@wxn0brp/db-storage-sqlite 0.110.0 → 0.110.1
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/README.md +2 -0
- package/dist/find.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -1
- package/dist/update.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,8 @@ await db.users.remove({ name: "John Doe" });
|
|
|
69
69
|
|
|
70
70
|
> This is necessary because SQLite cannot create a table without defining at least one column.
|
|
71
71
|
|
|
72
|
+
- **Boolean values** are automatically mapped to `0` (false) / `1` (true) when stored in or queried against SQLite, since SQLite has no native boolean type.
|
|
73
|
+
|
|
72
74
|
- All other methods (`add`, `find`, `update`, `remove`) are **fully compatible with ValtheraDB**, preserving all features like `_id` generation, complex filters (`hasFieldsAdvanced`), sorting, pagination, and function-based search.
|
|
73
75
|
|
|
74
76
|
## License
|
package/dist/find.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { findUtil } from "@wxn0brp/db-core/utils/action";
|
|
2
2
|
import { findObj } from "@wxn0brp/db-core/utils/process";
|
|
3
|
+
import { toSqlValue } from "./index.js";
|
|
3
4
|
export async function find(slv, config) {
|
|
4
5
|
const { collection, search } = config;
|
|
5
6
|
let sqlResult = [];
|
|
@@ -13,7 +14,7 @@ export async function find(slv, config) {
|
|
|
13
14
|
.filter(k => !k.startsWith("$"))
|
|
14
15
|
.filter(k => typeof search[k] !== "object");
|
|
15
16
|
const baseSql = `SELECT * FROM ${collection} WHERE ${baseKeys.map(k => `${k} = ?`).join(" AND ")}`;
|
|
16
|
-
const baseValues = baseKeys.map(k => search[k]);
|
|
17
|
+
const baseValues = baseKeys.map(k => toSqlValue(search[k]));
|
|
17
18
|
const stmt = await slv._prepare(baseSql);
|
|
18
19
|
sqlResult = await Promise.resolve(stmt.all(...baseValues));
|
|
19
20
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ActionsBase } from "@wxn0brp/db-core/base/actions";
|
|
|
3
3
|
import { Data } from "@wxn0brp/db-core/types/data";
|
|
4
4
|
import { VQueryT } from "@wxn0brp/db-core/types/query";
|
|
5
5
|
import { SupportedDB, VStatement } from "./types.js";
|
|
6
|
+
export declare function toSqlValue(v: any): any;
|
|
6
7
|
export declare class SQLiteValthera extends ActionsBase {
|
|
7
8
|
db: SupportedDB;
|
|
8
9
|
primaryKey: Record<string, string>;
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,11 @@ import { addId } from "@wxn0brp/db-core/helpers/addId";
|
|
|
4
4
|
import { find } from "./find.js";
|
|
5
5
|
import { remove } from "./remove.js";
|
|
6
6
|
import { update } from "./update.js";
|
|
7
|
+
export function toSqlValue(v) {
|
|
8
|
+
if (typeof v === "boolean")
|
|
9
|
+
return v ? 1 : 0;
|
|
10
|
+
return v;
|
|
11
|
+
}
|
|
7
12
|
export class SQLiteValthera extends ActionsBase {
|
|
8
13
|
db;
|
|
9
14
|
primaryKey;
|
|
@@ -35,7 +40,7 @@ export class SQLiteValthera extends ActionsBase {
|
|
|
35
40
|
await addId(config, this, true);
|
|
36
41
|
const keys = Object.keys(data);
|
|
37
42
|
const placeholders = keys.map(() => "?").join(", ");
|
|
38
|
-
const values = keys.map(k => data[k]);
|
|
43
|
+
const values = keys.map(k => toSqlValue(data[k]));
|
|
39
44
|
const sql = `INSERT INTO ${collection} (${keys.join(", ")}) VALUES (${placeholders})`;
|
|
40
45
|
const stmt = await this._prepare(sql);
|
|
41
46
|
await Promise.resolve(stmt.run(...values));
|
package/dist/update.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { updateObj } from "@wxn0brp/db-core/utils/process";
|
|
2
|
+
import { toSqlValue } from "./index.js";
|
|
2
3
|
import { find } from "./find.js";
|
|
3
4
|
export async function update(slv, query, one) {
|
|
4
5
|
const { collection } = query;
|
|
@@ -16,7 +17,7 @@ export async function update(slv, query, one) {
|
|
|
16
17
|
if (newData[key] !== target[key])
|
|
17
18
|
newData[key] = target[key];
|
|
18
19
|
const keys = Object.keys(newData).filter(k => k !== key);
|
|
19
|
-
const values = keys.map(k => newData[k]);
|
|
20
|
+
const values = keys.map(k => toSqlValue(newData[k]));
|
|
20
21
|
const sql = `UPDATE "${collection}" SET ${keys.map(k => `"${k}" = ?`).join(", ")} WHERE "${key}" = ?`;
|
|
21
22
|
const stmt = await slv._prepare(sql);
|
|
22
23
|
await Promise.resolve(stmt.run(...values, target[key]));
|