@wxn0brp/db-storage-sqlite 0.101.0 → 0.110.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/find.js +4 -8
- package/dist/index.js +11 -5
- package/dist/update.js +3 -5
- package/package.json +3 -3
package/dist/find.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { findUtil } from "@wxn0brp/db-core/utils/action";
|
|
2
|
-
import {
|
|
2
|
+
import { findObj } from "@wxn0brp/db-core/utils/process";
|
|
3
3
|
export async function find(slv, config) {
|
|
4
|
-
const { collection, search
|
|
4
|
+
const { collection, search } = config;
|
|
5
5
|
let sqlResult = [];
|
|
6
6
|
if (typeof search === "function" || Object.keys(search).length === 0) {
|
|
7
7
|
const stmt = await slv._prepare(`SELECT * FROM ${collection}`);
|
|
@@ -17,10 +17,6 @@ export async function find(slv, config) {
|
|
|
17
17
|
const stmt = await slv._prepare(baseSql);
|
|
18
18
|
sqlResult = await Promise.resolve(stmt.all(...baseValues));
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
return findUtil(config,
|
|
22
|
-
find() {
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
}, [null]);
|
|
20
|
+
const result = sqlResult.filter(entry => findObj(entry, search));
|
|
21
|
+
return findUtil(config, result, []);
|
|
26
22
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { forgeTypedValthera,
|
|
1
|
+
import { forgeTypedValthera, ValtheraClass } from "@wxn0brp/db-core";
|
|
2
2
|
import { ActionsBase } from "@wxn0brp/db-core/base/actions";
|
|
3
|
+
import { addId } from "@wxn0brp/db-core/helpers/addId";
|
|
3
4
|
import { find } from "./find.js";
|
|
4
5
|
import { remove } from "./remove.js";
|
|
5
6
|
import { update } from "./update.js";
|
|
@@ -30,9 +31,8 @@ export class SQLiteValthera extends ActionsBase {
|
|
|
30
31
|
return tables.map((t) => t.name);
|
|
31
32
|
}
|
|
32
33
|
async add(config) {
|
|
33
|
-
const { data,
|
|
34
|
-
|
|
35
|
-
data._id = genId();
|
|
34
|
+
const { data, collection } = config;
|
|
35
|
+
await addId(config, this, true);
|
|
36
36
|
const keys = Object.keys(data);
|
|
37
37
|
const placeholders = keys.map(() => "?").join(", ");
|
|
38
38
|
const values = keys.map(k => data[k]);
|
|
@@ -94,16 +94,22 @@ export const DYNAMIC = {
|
|
|
94
94
|
return DYNAMIC.bun(file, keys, opts);
|
|
95
95
|
return DYNAMIC.node(file, keys, opts);
|
|
96
96
|
},
|
|
97
|
-
async bun(file, keys = {}, opts) {
|
|
97
|
+
async bun(file, keys = {}, opts = undefined) {
|
|
98
98
|
const { Database } = await import("bun:sqlite");
|
|
99
|
+
if (typeof opts === "object" && Object.keys(opts).length === 0)
|
|
100
|
+
opts = undefined;
|
|
99
101
|
return new SQLiteValthera(new Database(file, opts), keys);
|
|
100
102
|
},
|
|
101
103
|
async node(file, keys = {}, opts) {
|
|
102
104
|
const { DatabaseSync } = await import("node:sqlite");
|
|
105
|
+
if (!opts)
|
|
106
|
+
opts = {};
|
|
103
107
|
return new SQLiteValthera(new DatabaseSync(file, opts), keys);
|
|
104
108
|
},
|
|
105
109
|
async better(file, keys = {}, opts) {
|
|
106
110
|
const { default: def } = await import("better-sqlite3");
|
|
111
|
+
if (!opts)
|
|
112
|
+
opts = {};
|
|
107
113
|
return new SQLiteValthera(new def(file, opts), keys);
|
|
108
114
|
}
|
|
109
115
|
};
|
package/dist/update.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { updateObj } from "@wxn0brp/db-core/utils/process";
|
|
2
2
|
import { find } from "./find.js";
|
|
3
3
|
export async function update(slv, query, one) {
|
|
4
|
-
const { collection
|
|
4
|
+
const { collection } = query;
|
|
5
5
|
const matched = await find(slv, {
|
|
6
6
|
...query,
|
|
7
7
|
dbFindOpts: {
|
|
@@ -12,9 +12,7 @@ export async function update(slv, query, one) {
|
|
|
12
12
|
return [];
|
|
13
13
|
const key = slv.primaryKey[collection] || "_id";
|
|
14
14
|
const updateOne = async (target) => {
|
|
15
|
-
const newData =
|
|
16
|
-
? updater(target, context)
|
|
17
|
-
: updateObjectAdvanced(target, updater);
|
|
15
|
+
const newData = updateObj(query, target);
|
|
18
16
|
if (newData[key] !== target[key])
|
|
19
17
|
newData[key] = target[key];
|
|
20
18
|
const keys = Object.keys(newData).filter(k => k !== key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-storage-sqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.110.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "A pure SQLite storage adapter for the ValtheraDB database library",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"@types/better-sqlite3": "^7.6.13",
|
|
23
23
|
"@types/bun": "*",
|
|
24
24
|
"@types/node": "*",
|
|
25
|
-
"@wxn0brp/db-core": "^0.
|
|
25
|
+
"@wxn0brp/db-core": "^0.11.0-alpha.4",
|
|
26
26
|
"better-sqlite3": "^12.9.0",
|
|
27
27
|
"tsc-alias": "^1",
|
|
28
28
|
"typescript": "^6"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@wxn0brp/db-core": "^0.
|
|
31
|
+
"@wxn0brp/db-core": "^0.11.0-alpha.4",
|
|
32
32
|
"better-sqlite3": "^12.9.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|