@atscript/db-sqlite 0.1.29 → 0.1.31

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/index.cjs CHANGED
@@ -40,45 +40,46 @@ const EMPTY_OR = {
40
40
  */ const sqlVisitor = {
41
41
  comparison(field, op, value) {
42
42
  const col = `"${escapeIdent(field)}"`;
43
+ const v = toSqliteParam(value);
43
44
  switch (op) {
44
45
  case "$eq": {
45
- if (value === null) return {
46
+ if (v === null) return {
46
47
  sql: `${col} IS NULL`,
47
48
  params: []
48
49
  };
49
50
  return {
50
51
  sql: `${col} = ?`,
51
- params: [value]
52
+ params: [v]
52
53
  };
53
54
  }
54
55
  case "$ne": {
55
- if (value === null) return {
56
+ if (v === null) return {
56
57
  sql: `${col} IS NOT NULL`,
57
58
  params: []
58
59
  };
59
60
  return {
60
61
  sql: `${col} != ?`,
61
- params: [value]
62
+ params: [v]
62
63
  };
63
64
  }
64
65
  case "$gt": return {
65
66
  sql: `${col} > ?`,
66
- params: [value]
67
+ params: [v]
67
68
  };
68
69
  case "$gte": return {
69
70
  sql: `${col} >= ?`,
70
- params: [value]
71
+ params: [v]
71
72
  };
72
73
  case "$lt": return {
73
74
  sql: `${col} < ?`,
74
- params: [value]
75
+ params: [v]
75
76
  };
76
77
  case "$lte": return {
77
78
  sql: `${col} <= ?`,
78
- params: [value]
79
+ params: [v]
79
80
  };
80
81
  case "$in": {
81
- const arr = value;
82
+ const arr = value.map(toSqliteParam);
82
83
  if (arr.length === 0) return EMPTY_OR;
83
84
  const placeholders = arr.map(() => "?").join(", ");
84
85
  return {
@@ -87,7 +88,7 @@ const EMPTY_OR = {
87
88
  };
88
89
  }
89
90
  case "$nin": {
90
- const arr = value;
91
+ const arr = value.map(toSqliteParam);
91
92
  if (arr.length === 0) return EMPTY_AND;
92
93
  const placeholders = arr.map(() => "?").join(", ");
93
94
  return {
@@ -162,6 +163,13 @@ function buildWhere(filter) {
162
163
  */ function escapeIdent(name) {
163
164
  return name.replace(/"/g, "\"\"");
164
165
  }
166
+ /**
167
+ * Converts a JS value to a SQLite-bindable parameter.
168
+ * SQLite cannot bind booleans — they must be 0/1.
169
+ */ function toSqliteParam(value) {
170
+ if (typeof value === "boolean") return value ? 1 : 0;
171
+ return value;
172
+ }
165
173
 
166
174
  //#endregion
167
175
  //#region packages/db-sqlite/src/sql-builder.ts
@@ -405,15 +413,11 @@ var SqliteAdapter = class extends __atscript_utils_db.BaseDbAdapter {
405
413
  }
406
414
  async syncIndexes() {
407
415
  const tableName = this.resolveTableName();
408
- const columnMap = this._table.columnMap;
409
416
  await this.syncIndexesWithDiff({
410
417
  listExisting: async () => this.driver.all(`PRAGMA index_list("${esc(tableName)}")`).filter((i) => !i.name.startsWith("sqlite_")),
411
418
  createIndex: async (index) => {
412
419
  const unique = index.type === "unique" ? "UNIQUE " : "";
413
- const cols = index.fields.map((f) => {
414
- const physical = columnMap.get(f.name) ?? f.name;
415
- return `"${esc(physical)}" ${f.sort === "desc" ? "DESC" : "ASC"}`;
416
- }).join(", ");
420
+ const cols = index.fields.map((f) => `"${esc(f.name)}" ${f.sort === "desc" ? "DESC" : "ASC"}`).join(", ");
417
421
  this.driver.exec(`CREATE ${unique}INDEX IF NOT EXISTS "${esc(index.key)}" ON "${esc(tableName)}" (${cols})`);
418
422
  },
419
423
  dropIndex: async (name) => {
package/dist/index.mjs CHANGED
@@ -23,45 +23,46 @@ const EMPTY_OR = {
23
23
  */ const sqlVisitor = {
24
24
  comparison(field, op, value) {
25
25
  const col = `"${escapeIdent(field)}"`;
26
+ const v = toSqliteParam(value);
26
27
  switch (op) {
27
28
  case "$eq": {
28
- if (value === null) return {
29
+ if (v === null) return {
29
30
  sql: `${col} IS NULL`,
30
31
  params: []
31
32
  };
32
33
  return {
33
34
  sql: `${col} = ?`,
34
- params: [value]
35
+ params: [v]
35
36
  };
36
37
  }
37
38
  case "$ne": {
38
- if (value === null) return {
39
+ if (v === null) return {
39
40
  sql: `${col} IS NOT NULL`,
40
41
  params: []
41
42
  };
42
43
  return {
43
44
  sql: `${col} != ?`,
44
- params: [value]
45
+ params: [v]
45
46
  };
46
47
  }
47
48
  case "$gt": return {
48
49
  sql: `${col} > ?`,
49
- params: [value]
50
+ params: [v]
50
51
  };
51
52
  case "$gte": return {
52
53
  sql: `${col} >= ?`,
53
- params: [value]
54
+ params: [v]
54
55
  };
55
56
  case "$lt": return {
56
57
  sql: `${col} < ?`,
57
- params: [value]
58
+ params: [v]
58
59
  };
59
60
  case "$lte": return {
60
61
  sql: `${col} <= ?`,
61
- params: [value]
62
+ params: [v]
62
63
  };
63
64
  case "$in": {
64
- const arr = value;
65
+ const arr = value.map(toSqliteParam);
65
66
  if (arr.length === 0) return EMPTY_OR;
66
67
  const placeholders = arr.map(() => "?").join(", ");
67
68
  return {
@@ -70,7 +71,7 @@ const EMPTY_OR = {
70
71
  };
71
72
  }
72
73
  case "$nin": {
73
- const arr = value;
74
+ const arr = value.map(toSqliteParam);
74
75
  if (arr.length === 0) return EMPTY_AND;
75
76
  const placeholders = arr.map(() => "?").join(", ");
76
77
  return {
@@ -145,6 +146,13 @@ function buildWhere(filter) {
145
146
  */ function escapeIdent(name) {
146
147
  return name.replace(/"/g, "\"\"");
147
148
  }
149
+ /**
150
+ * Converts a JS value to a SQLite-bindable parameter.
151
+ * SQLite cannot bind booleans — they must be 0/1.
152
+ */ function toSqliteParam(value) {
153
+ if (typeof value === "boolean") return value ? 1 : 0;
154
+ return value;
155
+ }
148
156
 
149
157
  //#endregion
150
158
  //#region packages/db-sqlite/src/sql-builder.ts
@@ -388,15 +396,11 @@ var SqliteAdapter = class extends BaseDbAdapter {
388
396
  }
389
397
  async syncIndexes() {
390
398
  const tableName = this.resolveTableName();
391
- const columnMap = this._table.columnMap;
392
399
  await this.syncIndexesWithDiff({
393
400
  listExisting: async () => this.driver.all(`PRAGMA index_list("${esc(tableName)}")`).filter((i) => !i.name.startsWith("sqlite_")),
394
401
  createIndex: async (index) => {
395
402
  const unique = index.type === "unique" ? "UNIQUE " : "";
396
- const cols = index.fields.map((f) => {
397
- const physical = columnMap.get(f.name) ?? f.name;
398
- return `"${esc(physical)}" ${f.sort === "desc" ? "DESC" : "ASC"}`;
399
- }).join(", ");
403
+ const cols = index.fields.map((f) => `"${esc(f.name)}" ${f.sort === "desc" ? "DESC" : "ASC"}`).join(", ");
400
404
  this.driver.exec(`CREATE ${unique}INDEX IF NOT EXISTS "${esc(index.key)}" ON "${esc(tableName)}" (${cols})`);
401
405
  },
402
406
  dropIndex: async (name) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-sqlite",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "SQLite adapter for @atscript/utils-db with swappable driver support.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -40,9 +40,9 @@
40
40
  "peerDependencies": {
41
41
  "@uniqu/core": "^0.0.1",
42
42
  "better-sqlite3": ">=11.0.0",
43
- "@atscript/core": "^0.1.29",
44
- "@atscript/utils-db": "^0.1.29",
45
- "@atscript/typescript": "^0.1.29"
43
+ "@atscript/core": "^0.1.31",
44
+ "@atscript/typescript": "^0.1.31",
45
+ "@atscript/utils-db": "^0.1.31"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "better-sqlite3": {