@atscript/db-sqlite 0.1.31 → 0.1.32
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 +9 -11
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +8 -10
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -228,7 +228,7 @@ function buildCreateTable(table, fields) {
|
|
|
228
228
|
const primaryKeys = fields.filter((f) => f.isPrimaryKey);
|
|
229
229
|
for (const field of fields) {
|
|
230
230
|
if (field.ignored) continue;
|
|
231
|
-
const sqlType = sqliteTypeFromDesignType(field.designType);
|
|
231
|
+
const sqlType = field.isPrimaryKey && (field.designType === "number" || field.designType === "integer") ? "INTEGER" : sqliteTypeFromDesignType(field.designType);
|
|
232
232
|
let def = `"${esc$1(field.physicalName)}" ${sqlType}`;
|
|
233
233
|
if (field.isPrimaryKey && primaryKeys.length === 1) def += " PRIMARY KEY";
|
|
234
234
|
if (!field.optional && !field.isPrimaryKey) def += " NOT NULL";
|
|
@@ -250,16 +250,14 @@ function sqliteTypeFromDesignType(designType) {
|
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
function buildProjection(select) {
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (firstVal === 1) return entries.filter(([_, v]) => v === 1).map(([k]) => `"${esc$1(k)}"`).join(", ");
|
|
262
|
-
return "*";
|
|
253
|
+
const fields = select?.asArray;
|
|
254
|
+
if (!fields) return "*";
|
|
255
|
+
let sql = "";
|
|
256
|
+
for (let i = 0; i < fields.length; i++) {
|
|
257
|
+
if (i > 0) sql += ", ";
|
|
258
|
+
sql += `"${esc$1(fields[i])}"`;
|
|
259
|
+
}
|
|
260
|
+
return sql || "*";
|
|
263
261
|
}
|
|
264
262
|
function esc$1(name) {
|
|
265
263
|
return name.replace(/"/g, "\"\"");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TAtscriptAnnotatedType } from '@atscript/typescript/utils';
|
|
2
|
-
import { BaseDbAdapter, TDbInsertResult, TDbInsertManyResult, TDbUpdateResult, TDbDeleteResult } from '@atscript/utils-db';
|
|
3
|
-
import { Uniquery, FilterExpr } from '@uniqu/core';
|
|
2
|
+
import { BaseDbAdapter, TDbInsertResult, TDbInsertManyResult, DbQuery, FilterExpr, TDbUpdateResult, TDbDeleteResult } from '@atscript/utils-db';
|
|
4
3
|
import * as better_sqlite3 from 'better-sqlite3';
|
|
4
|
+
import { FilterExpr as FilterExpr$1 } from '@uniqu/core';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Result of a SQL statement that modifies data (INSERT, UPDATE, DELETE).
|
|
@@ -71,9 +71,9 @@ declare class SqliteAdapter extends BaseDbAdapter {
|
|
|
71
71
|
prepareId(id: unknown, _fieldType: TAtscriptAnnotatedType): unknown;
|
|
72
72
|
insertOne(data: Record<string, unknown>): Promise<TDbInsertResult>;
|
|
73
73
|
insertMany(data: Array<Record<string, unknown>>): Promise<TDbInsertManyResult>;
|
|
74
|
-
findOne(query:
|
|
75
|
-
findMany(query:
|
|
76
|
-
count(query:
|
|
74
|
+
findOne(query: DbQuery): Promise<Record<string, unknown> | null>;
|
|
75
|
+
findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
|
|
76
|
+
count(query: DbQuery): Promise<number>;
|
|
77
77
|
updateOne(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
78
78
|
updateMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
79
79
|
replaceOne(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
@@ -130,7 +130,7 @@ interface TSqlFragment {
|
|
|
130
130
|
* @returns `{ sql, params }` — the WHERE clause (without "WHERE") and bound params.
|
|
131
131
|
* Returns `{ sql: '1=1', params: [] }` for empty/null filters.
|
|
132
132
|
*/
|
|
133
|
-
declare function buildWhere(filter: FilterExpr): TSqlFragment;
|
|
133
|
+
declare function buildWhere(filter: FilterExpr$1): TSqlFragment;
|
|
134
134
|
|
|
135
135
|
export { BetterSqlite3Driver, SqliteAdapter, buildWhere };
|
|
136
136
|
export type { TSqlFragment, TSqliteDriver, TSqliteRunResult };
|
package/dist/index.mjs
CHANGED
|
@@ -211,7 +211,7 @@ function buildCreateTable(table, fields) {
|
|
|
211
211
|
const primaryKeys = fields.filter((f) => f.isPrimaryKey);
|
|
212
212
|
for (const field of fields) {
|
|
213
213
|
if (field.ignored) continue;
|
|
214
|
-
const sqlType = sqliteTypeFromDesignType(field.designType);
|
|
214
|
+
const sqlType = field.isPrimaryKey && (field.designType === "number" || field.designType === "integer") ? "INTEGER" : sqliteTypeFromDesignType(field.designType);
|
|
215
215
|
let def = `"${esc$1(field.physicalName)}" ${sqlType}`;
|
|
216
216
|
if (field.isPrimaryKey && primaryKeys.length === 1) def += " PRIMARY KEY";
|
|
217
217
|
if (!field.optional && !field.isPrimaryKey) def += " NOT NULL";
|
|
@@ -233,16 +233,14 @@ function sqliteTypeFromDesignType(designType) {
|
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
function buildProjection(select) {
|
|
236
|
-
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
const fields = select?.asArray;
|
|
237
|
+
if (!fields) return "*";
|
|
238
|
+
let sql = "";
|
|
239
|
+
for (let i = 0; i < fields.length; i++) {
|
|
240
|
+
if (i > 0) sql += ", ";
|
|
241
|
+
sql += `"${esc$1(fields[i])}"`;
|
|
240
242
|
}
|
|
241
|
-
|
|
242
|
-
if (entries.length === 0) return "*";
|
|
243
|
-
const firstVal = entries[0][1];
|
|
244
|
-
if (firstVal === 1) return entries.filter(([_, v]) => v === 1).map(([k]) => `"${esc$1(k)}"`).join(", ");
|
|
245
|
-
return "*";
|
|
243
|
+
return sql || "*";
|
|
246
244
|
}
|
|
247
245
|
function esc$1(name) {
|
|
248
246
|
return name.replace(/"/g, "\"\"");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-sqlite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.32",
|
|
4
4
|
"description": "SQLite adapter for @atscript/utils-db with swappable driver support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"vitest": "3.2.4"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@uniqu/core": "^0.0.
|
|
41
|
+
"@uniqu/core": "^0.0.2",
|
|
42
42
|
"better-sqlite3": ">=11.0.0",
|
|
43
|
-
"@atscript/core": "^0.1.
|
|
44
|
-
"@atscript/typescript": "^0.1.
|
|
45
|
-
"@atscript/utils-db": "^0.1.
|
|
43
|
+
"@atscript/core": "^0.1.32",
|
|
44
|
+
"@atscript/typescript": "^0.1.32",
|
|
45
|
+
"@atscript/utils-db": "^0.1.32"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"better-sqlite3": {
|