@pineliner/odb-client 1.0.7 → 1.0.9
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/database/adapters/bun-sqlite.d.ts.map +1 -1
- package/dist/database/adapters/libsql.d.ts.map +1 -1
- package/dist/database/adapters/odblite.d.ts.map +1 -1
- package/dist/database/types.d.ts +26 -2
- package/dist/database/types.d.ts.map +1 -1
- package/dist/index.cjs +195 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +194 -30
- package/dist/orm/index.d.ts +79 -1
- package/dist/orm/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/database/adapters/bun-sqlite.ts +59 -5
- package/src/database/adapters/libsql.ts +66 -6
- package/src/database/adapters/odblite.ts +79 -16
- package/src/database/types.ts +28 -2
- package/src/index.ts +1 -0
- package/src/orm/index.ts +216 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-sqlite.d.ts","sourceRoot":"","sources":["../../../src/database/adapters/bun-sqlite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EAGV,eAAe,
|
|
1
|
+
{"version":3,"file":"bun-sqlite.d.ts","sourceRoot":"","sources":["../../../src/database/adapters/bun-sqlite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EAGV,eAAe,EAEhB,MAAM,UAAU,CAAA;AAsDjB;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,eAAe;IACtD,QAAQ,CAAC,IAAI,EAAG,YAAY,CAAS;IACrC,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,eAAe;IAI7B,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IASrD,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5C,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;CAapC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libsql.d.ts","sourceRoot":"","sources":["../../../src/database/adapters/libsql.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EAGV,YAAY,
|
|
1
|
+
{"version":3,"file":"libsql.d.ts","sourceRoot":"","sources":["../../../src/database/adapters/libsql.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EAGV,YAAY,EAEb,MAAM,UAAU,CAAA;AAsDjB;;;GAGG;AACH,qBAAa,aAAc,YAAW,eAAe;IACnD,QAAQ,CAAC,IAAI,EAAG,QAAQ,CAAS;IACjC,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,EAAE,YAAY;IAI1B,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAUlD,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5C,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;CAYpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odblite.d.ts","sourceRoot":"","sources":["../../../src/database/adapters/odblite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAE5D,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EAGV,aAAa,
|
|
1
|
+
{"version":3,"file":"odblite.d.ts","sourceRoot":"","sources":["../../../src/database/adapters/odblite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAE5D,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EAGV,aAAa,EAEd,MAAM,UAAU,CAAA;AAsDjB;;;GAGG;AACH,qBAAa,cAAe,YAAW,eAAe;IACpD,QAAQ,CAAC,IAAI,EAAG,SAAS,CAAS;IAClC,OAAO,CAAC,MAAM,CAAe;IACtB,aAAa,EAAE,aAAa,CAAA;gBAEvB,MAAM,EAAE,aAAa;IAQ3B,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;IAgCzC,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5C,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;CAQpC"}
|
package/dist/database/types.d.ts
CHANGED
|
@@ -14,6 +14,30 @@ export interface QueryResult<T = any> {
|
|
|
14
14
|
rowsAffected?: number;
|
|
15
15
|
lastInsertRowid?: number | bigint;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Query options for fine-grained control
|
|
19
|
+
*/
|
|
20
|
+
export interface QueryOptions {
|
|
21
|
+
/**
|
|
22
|
+
* List of column names that should be auto-parsed as JSON when reading
|
|
23
|
+
* Only applies to columns that contain stringified JSON in SELECT queries
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* await conn.query('SELECT * FROM suppliers', [], { jsonColumns: ['connections', 'config'] })
|
|
27
|
+
*/
|
|
28
|
+
jsonColumns?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Automatically stringify parameters for JSON columns in UPDATE/INSERT queries
|
|
31
|
+
* Maps column names to parameter indices (0-based)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // UPDATE suppliers SET connections = ?, updated_at = ? WHERE id = ?
|
|
35
|
+
* await conn.execute(query, [connections, now, id], {
|
|
36
|
+
* stringifyParams: { connections: 0 } // Auto-stringify first parameter
|
|
37
|
+
* })
|
|
38
|
+
*/
|
|
39
|
+
stringifyParams?: Record<string, number>;
|
|
40
|
+
}
|
|
17
41
|
/**
|
|
18
42
|
* Unified database connection interface
|
|
19
43
|
* All backends implement this through adapters
|
|
@@ -26,11 +50,11 @@ export interface QueryResult<T = any> {
|
|
|
26
50
|
export interface Connection {
|
|
27
51
|
sql<T = any>(strings: TemplateStringsArray, ...values: any[]): Promise<T[]>;
|
|
28
52
|
sql(value: any, ...keys: string[]): any;
|
|
29
|
-
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
53
|
+
query<T = any>(sql: string, params?: any[], options?: QueryOptions): Promise<QueryResult<T>>;
|
|
30
54
|
execute(sql: string | {
|
|
31
55
|
sql: string;
|
|
32
56
|
args?: any[];
|
|
33
|
-
}, params?: any[]): Promise<QueryResult>;
|
|
57
|
+
}, params?: any[], options?: QueryOptions): Promise<QueryResult>;
|
|
34
58
|
prepare(sql: string): PreparedStatement;
|
|
35
59
|
transaction<T>(fn: (tx: Connection) => Promise<T>): Promise<T>;
|
|
36
60
|
begin<T>(fn: (tx: Connection) => Promise<T>): Promise<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,cAAc,GACd,WAAW,GACX,WAAW,CAAA;AAEf;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAClC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IAGzB,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAA;IAG3E,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;IAGvC,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE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require__.r(__webpack_exports__);
|
|
5
5
|
__webpack_require__.d(__webpack_exports__, {
|
|
6
6
|
ORM: ()=>ORM,
|
|
7
|
+
Transaction: ()=>Transaction,
|
|
7
8
|
and: ()=>and,
|
|
8
9
|
createORM: ()=>createORM,
|
|
9
10
|
eq: ()=>eq,
|
|
@@ -294,10 +295,67 @@ var __webpack_modules__ = {
|
|
|
294
295
|
return new DeleteBuilder(this.db, this.tableName);
|
|
295
296
|
}
|
|
296
297
|
}
|
|
298
|
+
class Transaction {
|
|
299
|
+
orm;
|
|
300
|
+
isCommitted = false;
|
|
301
|
+
isRolledBack = false;
|
|
302
|
+
db;
|
|
303
|
+
savepointName;
|
|
304
|
+
constructor(db, transactionDepth = 0, savepointName){
|
|
305
|
+
this.db = db;
|
|
306
|
+
this.orm = new ORM(db, transactionDepth);
|
|
307
|
+
this.savepointName = savepointName;
|
|
308
|
+
}
|
|
309
|
+
select(fields) {
|
|
310
|
+
this.checkNotFinalized();
|
|
311
|
+
return this.orm.select(fields);
|
|
312
|
+
}
|
|
313
|
+
insert(tableName) {
|
|
314
|
+
this.checkNotFinalized();
|
|
315
|
+
return this.orm.insert(tableName);
|
|
316
|
+
}
|
|
317
|
+
update(tableName) {
|
|
318
|
+
this.checkNotFinalized();
|
|
319
|
+
return this.orm.update(tableName);
|
|
320
|
+
}
|
|
321
|
+
delete(tableName) {
|
|
322
|
+
this.checkNotFinalized();
|
|
323
|
+
return this.orm.delete(tableName);
|
|
324
|
+
}
|
|
325
|
+
execute(sql, params) {
|
|
326
|
+
this.checkNotFinalized();
|
|
327
|
+
return this.orm.execute(sql, params);
|
|
328
|
+
}
|
|
329
|
+
async transaction(fn) {
|
|
330
|
+
this.checkNotFinalized();
|
|
331
|
+
if (fn) return await this.orm.transaction(fn);
|
|
332
|
+
return await this.orm.transaction();
|
|
333
|
+
}
|
|
334
|
+
async commit() {
|
|
335
|
+
if (this.isCommitted) throw new Error('Transaction already committed');
|
|
336
|
+
if (this.isRolledBack) throw new Error('Transaction already rolled back');
|
|
337
|
+
if (this.savepointName) await this.db.execute(`RELEASE SAVEPOINT ${this.savepointName}`, []);
|
|
338
|
+
else await this.db.execute('COMMIT', []);
|
|
339
|
+
this.isCommitted = true;
|
|
340
|
+
}
|
|
341
|
+
async rollback() {
|
|
342
|
+
if (this.isCommitted) throw new Error('Transaction already committed');
|
|
343
|
+
if (this.isRolledBack) throw new Error('Transaction already rolled back');
|
|
344
|
+
if (this.savepointName) await this.db.execute(`ROLLBACK TO SAVEPOINT ${this.savepointName}`, []);
|
|
345
|
+
else await this.db.execute('ROLLBACK', []);
|
|
346
|
+
this.isRolledBack = true;
|
|
347
|
+
}
|
|
348
|
+
checkNotFinalized() {
|
|
349
|
+
if (this.isCommitted) throw new Error('Cannot perform operations on committed transaction');
|
|
350
|
+
if (this.isRolledBack) throw new Error('Cannot perform operations on rolled back transaction');
|
|
351
|
+
}
|
|
352
|
+
}
|
|
297
353
|
class ORM {
|
|
298
354
|
db;
|
|
299
|
-
|
|
355
|
+
transactionDepth = 0;
|
|
356
|
+
constructor(db, transactionDepth = 0){
|
|
300
357
|
this.db = db;
|
|
358
|
+
this.transactionDepth = transactionDepth;
|
|
301
359
|
}
|
|
302
360
|
table(tableName) {
|
|
303
361
|
return new TableQueryBuilder(this.db, tableName);
|
|
@@ -323,6 +381,33 @@ var __webpack_modules__ = {
|
|
|
323
381
|
execute(sql, params) {
|
|
324
382
|
return this.db.execute(sql, params);
|
|
325
383
|
}
|
|
384
|
+
async transaction(fn) {
|
|
385
|
+
if (!fn) if (this.transactionDepth > 0) {
|
|
386
|
+
const savepointName = `sp_${this.transactionDepth}_${Date.now()}`;
|
|
387
|
+
await this.db.execute(`SAVEPOINT ${savepointName}`, []);
|
|
388
|
+
return new Transaction(this.db, this.transactionDepth + 1, savepointName);
|
|
389
|
+
} else {
|
|
390
|
+
await this.db.execute('BEGIN TRANSACTION', []);
|
|
391
|
+
return new Transaction(this.db, 1);
|
|
392
|
+
}
|
|
393
|
+
if (!(this.transactionDepth > 0)) return await this.db.transaction(async (txConnection)=>{
|
|
394
|
+
const txOrm = new ORM(txConnection, 1);
|
|
395
|
+
return await fn(txOrm);
|
|
396
|
+
});
|
|
397
|
+
{
|
|
398
|
+
const savepointName = `sp_${this.transactionDepth}_${Date.now()}`;
|
|
399
|
+
try {
|
|
400
|
+
await this.db.execute(`SAVEPOINT ${savepointName}`, []);
|
|
401
|
+
const nestedOrm = new ORM(this.db, this.transactionDepth + 1);
|
|
402
|
+
const result = await fn(nestedOrm);
|
|
403
|
+
await this.db.execute(`RELEASE SAVEPOINT ${savepointName}`, []);
|
|
404
|
+
return result;
|
|
405
|
+
} catch (error) {
|
|
406
|
+
await this.db.execute(`ROLLBACK TO SAVEPOINT ${savepointName}`, []);
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
326
411
|
}
|
|
327
412
|
function createORM(db) {
|
|
328
413
|
return new ORM(db);
|
|
@@ -398,6 +483,7 @@ var __webpack_exports__ = {};
|
|
|
398
483
|
splitSQLStatements: ()=>splitSQLStatements,
|
|
399
484
|
where: ()=>src_where,
|
|
400
485
|
LibSQLAdapter: ()=>LibSQLAdapter,
|
|
486
|
+
ORMTransaction: ()=>orm.Transaction,
|
|
401
487
|
lt: ()=>orm.lt,
|
|
402
488
|
fragment: ()=>fragment,
|
|
403
489
|
isNull: ()=>orm.isNull,
|
|
@@ -1264,6 +1350,26 @@ var __webpack_exports__ = {};
|
|
|
1264
1350
|
args: values
|
|
1265
1351
|
};
|
|
1266
1352
|
}
|
|
1353
|
+
function parseJsonColumns(rows, jsonColumns) {
|
|
1354
|
+
if (!jsonColumns || 0 === jsonColumns.length) return rows;
|
|
1355
|
+
return rows.map((row)=>{
|
|
1356
|
+
const parsed = {
|
|
1357
|
+
...row
|
|
1358
|
+
};
|
|
1359
|
+
for (const col of jsonColumns)if (col in parsed && 'string' == typeof parsed[col]) try {
|
|
1360
|
+
parsed[col] = JSON.parse(parsed[col]);
|
|
1361
|
+
} catch {}
|
|
1362
|
+
return parsed;
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
function stringifyJsonParams(params, stringifyParams) {
|
|
1366
|
+
if (!stringifyParams || 0 === Object.keys(stringifyParams).length) return params;
|
|
1367
|
+
const result = [
|
|
1368
|
+
...params
|
|
1369
|
+
];
|
|
1370
|
+
for (const [_columnName, index] of Object.entries(stringifyParams))if (index < result.length && null != result[index] && 'object' == typeof result[index]) result[index] = JSON.stringify(result[index]);
|
|
1371
|
+
return result;
|
|
1372
|
+
}
|
|
1267
1373
|
class BunSQLiteAdapter {
|
|
1268
1374
|
type = 'bun-sqlite';
|
|
1269
1375
|
config;
|
|
@@ -1321,10 +1427,10 @@ var __webpack_exports__ = {};
|
|
|
1321
1427
|
this.sql.set = set;
|
|
1322
1428
|
this.sql.where = sql_template_where;
|
|
1323
1429
|
}
|
|
1324
|
-
async query(sql, params = []) {
|
|
1325
|
-
return this.execute(sql, params);
|
|
1430
|
+
async query(sql, params = [], options) {
|
|
1431
|
+
return this.execute(sql, params, options);
|
|
1326
1432
|
}
|
|
1327
|
-
async execute(sql, params = []) {
|
|
1433
|
+
async execute(sql, params = [], options) {
|
|
1328
1434
|
try {
|
|
1329
1435
|
let sqlStr;
|
|
1330
1436
|
let sqlParams;
|
|
@@ -1343,12 +1449,14 @@ var __webpack_exports__ = {};
|
|
|
1343
1449
|
sqlStr = sql;
|
|
1344
1450
|
sqlParams = params;
|
|
1345
1451
|
}
|
|
1452
|
+
if (options?.stringifyParams) sqlParams = stringifyJsonParams(sqlParams, options.stringifyParams);
|
|
1346
1453
|
const stmt = this.db.query(sqlStr);
|
|
1347
1454
|
const isSelect = sqlStr.trim().toUpperCase().startsWith('SELECT') || sqlStr.trim().toUpperCase().includes('RETURNING');
|
|
1348
1455
|
if (isSelect) {
|
|
1349
|
-
|
|
1456
|
+
let rows = stmt.all(...sqlParams);
|
|
1457
|
+
if (options?.jsonColumns) rows = parseJsonColumns(rows, options.jsonColumns);
|
|
1350
1458
|
return {
|
|
1351
|
-
rows
|
|
1459
|
+
rows,
|
|
1352
1460
|
rowsAffected: 0
|
|
1353
1461
|
};
|
|
1354
1462
|
}
|
|
@@ -1416,6 +1524,26 @@ var __webpack_exports__ = {};
|
|
|
1416
1524
|
}
|
|
1417
1525
|
}
|
|
1418
1526
|
const external_libsql_client_namespaceObject = require("@libsql/client");
|
|
1527
|
+
function libsql_parseJsonColumns(rows, jsonColumns) {
|
|
1528
|
+
if (!jsonColumns || 0 === jsonColumns.length) return rows;
|
|
1529
|
+
return rows.map((row)=>{
|
|
1530
|
+
const parsed = {
|
|
1531
|
+
...row
|
|
1532
|
+
};
|
|
1533
|
+
for (const col of jsonColumns)if (col in parsed && 'string' == typeof parsed[col]) try {
|
|
1534
|
+
parsed[col] = JSON.parse(parsed[col]);
|
|
1535
|
+
} catch {}
|
|
1536
|
+
return parsed;
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
function libsql_stringifyJsonParams(params, stringifyParams) {
|
|
1540
|
+
if (!stringifyParams || 0 === Object.keys(stringifyParams).length) return params;
|
|
1541
|
+
const result = [
|
|
1542
|
+
...params
|
|
1543
|
+
];
|
|
1544
|
+
for (const [_columnName, index] of Object.entries(stringifyParams))if (index < result.length && null != result[index] && 'object' == typeof result[index]) result[index] = JSON.stringify(result[index]);
|
|
1545
|
+
return result;
|
|
1546
|
+
}
|
|
1419
1547
|
class LibSQLAdapter {
|
|
1420
1548
|
type = 'libsql';
|
|
1421
1549
|
config;
|
|
@@ -1473,10 +1601,10 @@ var __webpack_exports__ = {};
|
|
|
1473
1601
|
this.sql.set = set;
|
|
1474
1602
|
this.sql.where = sql_template_where;
|
|
1475
1603
|
}
|
|
1476
|
-
async query(sql, params = []) {
|
|
1477
|
-
return this.execute(sql, params);
|
|
1604
|
+
async query(sql, params = [], options) {
|
|
1605
|
+
return this.execute(sql, params, options);
|
|
1478
1606
|
}
|
|
1479
|
-
async execute(sql, params = []) {
|
|
1607
|
+
async execute(sql, params = [], options) {
|
|
1480
1608
|
try {
|
|
1481
1609
|
const target = this.txClient || this.client;
|
|
1482
1610
|
let query;
|
|
@@ -1485,23 +1613,29 @@ var __webpack_exports__ = {};
|
|
|
1485
1613
|
console.log('[LibSQL] Executing SQL:', sql);
|
|
1486
1614
|
console.log('[LibSQL] With params:', params);
|
|
1487
1615
|
}
|
|
1616
|
+
let args = params;
|
|
1617
|
+
if (options?.stringifyParams) args = libsql_stringifyJsonParams(args, options.stringifyParams);
|
|
1488
1618
|
query = {
|
|
1489
1619
|
sql,
|
|
1490
|
-
args
|
|
1620
|
+
args
|
|
1491
1621
|
};
|
|
1492
1622
|
} else {
|
|
1493
1623
|
if (process.env.DEBUG_SQL) {
|
|
1494
1624
|
console.log('[LibSQL] Executing SQL:', sql.sql);
|
|
1495
1625
|
console.log('[LibSQL] With args:', sql.args);
|
|
1496
1626
|
}
|
|
1627
|
+
let args = sql.args || [];
|
|
1628
|
+
if (options?.stringifyParams) args = libsql_stringifyJsonParams(args, options.stringifyParams);
|
|
1497
1629
|
query = {
|
|
1498
1630
|
sql: sql.sql,
|
|
1499
|
-
args
|
|
1631
|
+
args
|
|
1500
1632
|
};
|
|
1501
1633
|
}
|
|
1502
1634
|
const result = await target.execute(query);
|
|
1635
|
+
let rows = result.rows;
|
|
1636
|
+
if (options?.jsonColumns) rows = libsql_parseJsonColumns(rows, options.jsonColumns);
|
|
1503
1637
|
return {
|
|
1504
|
-
rows
|
|
1638
|
+
rows,
|
|
1505
1639
|
rowsAffected: Number(result.rowsAffected),
|
|
1506
1640
|
lastInsertRowid: result.lastInsertRowid ? BigInt(result.lastInsertRowid.toString()) : void 0
|
|
1507
1641
|
};
|
|
@@ -1543,6 +1677,26 @@ var __webpack_exports__ = {};
|
|
|
1543
1677
|
return createORM(this);
|
|
1544
1678
|
}
|
|
1545
1679
|
}
|
|
1680
|
+
function odblite_parseJsonColumns(rows, jsonColumns) {
|
|
1681
|
+
if (!jsonColumns || 0 === jsonColumns.length) return rows;
|
|
1682
|
+
return rows.map((row)=>{
|
|
1683
|
+
const parsed = {
|
|
1684
|
+
...row
|
|
1685
|
+
};
|
|
1686
|
+
for (const col of jsonColumns)if (col in parsed && 'string' == typeof parsed[col]) try {
|
|
1687
|
+
parsed[col] = JSON.parse(parsed[col]);
|
|
1688
|
+
} catch {}
|
|
1689
|
+
return parsed;
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
function odblite_stringifyJsonParams(params, stringifyParams) {
|
|
1693
|
+
if (!stringifyParams || 0 === Object.keys(stringifyParams).length) return params;
|
|
1694
|
+
const result = [
|
|
1695
|
+
...params
|
|
1696
|
+
];
|
|
1697
|
+
for (const [_columnName, index] of Object.entries(stringifyParams))if (index < result.length && null != result[index] && 'object' == typeof result[index]) result[index] = JSON.stringify(result[index]);
|
|
1698
|
+
return result;
|
|
1699
|
+
}
|
|
1546
1700
|
class ODBLiteAdapter {
|
|
1547
1701
|
type = 'odblite';
|
|
1548
1702
|
config;
|
|
@@ -1629,32 +1783,42 @@ var __webpack_exports__ = {};
|
|
|
1629
1783
|
this.sql.set = set;
|
|
1630
1784
|
this.sql.where = sql_template_where;
|
|
1631
1785
|
}
|
|
1632
|
-
async query(sql, params = []) {
|
|
1633
|
-
return this.execute(sql, params);
|
|
1786
|
+
async query(sql, params = [], options) {
|
|
1787
|
+
return this.execute(sql, params, options);
|
|
1634
1788
|
}
|
|
1635
|
-
async execute(sql, params = []) {
|
|
1789
|
+
async execute(sql, params = [], options) {
|
|
1636
1790
|
try {
|
|
1791
|
+
let rows;
|
|
1792
|
+
let rowsAffected;
|
|
1793
|
+
let lastInsertRowid;
|
|
1637
1794
|
if ('object' == typeof sql) {
|
|
1638
1795
|
if (process.env.DEBUG_SQL) {
|
|
1639
1796
|
console.log('[ODBLite] Executing SQL:', sql.sql);
|
|
1640
1797
|
console.log('[ODBLite] With args:', sql.args);
|
|
1641
1798
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1799
|
+
let args = sql.args || [];
|
|
1800
|
+
if (options?.stringifyParams) args = odblite_stringifyJsonParams(args, options.stringifyParams);
|
|
1801
|
+
const result = await this.client.sql.execute(sql.sql, args);
|
|
1802
|
+
rows = result.rows;
|
|
1803
|
+
rowsAffected = result.rowsAffected || 0;
|
|
1804
|
+
lastInsertRowid = result.lastInsertRowid;
|
|
1805
|
+
} else {
|
|
1806
|
+
if (process.env.DEBUG_SQL) {
|
|
1807
|
+
console.log('[ODBLite] Executing SQL:', sql);
|
|
1808
|
+
console.log('[ODBLite] With params:', params);
|
|
1809
|
+
}
|
|
1810
|
+
let args = params;
|
|
1811
|
+
if (options?.stringifyParams) args = odblite_stringifyJsonParams(args, options.stringifyParams);
|
|
1812
|
+
const result = await this.client.sql.execute(sql, args);
|
|
1813
|
+
rows = result.rows;
|
|
1814
|
+
rowsAffected = result.rowsAffected || 0;
|
|
1815
|
+
lastInsertRowid = result.lastInsertRowid;
|
|
1652
1816
|
}
|
|
1653
|
-
|
|
1817
|
+
if (options?.jsonColumns) rows = odblite_parseJsonColumns(rows, options.jsonColumns);
|
|
1654
1818
|
return {
|
|
1655
|
-
rows
|
|
1656
|
-
rowsAffected
|
|
1657
|
-
lastInsertRowid
|
|
1819
|
+
rows,
|
|
1820
|
+
rowsAffected,
|
|
1821
|
+
lastInsertRowid
|
|
1658
1822
|
};
|
|
1659
1823
|
} catch (error) {
|
|
1660
1824
|
throw error;
|
|
@@ -1948,6 +2112,7 @@ exports.ODBLiteClient = __webpack_exports__.ODBLiteClient;
|
|
|
1948
2112
|
exports.ODBLiteError = __webpack_exports__.ODBLiteError;
|
|
1949
2113
|
exports.ODBLiteTransaction = __webpack_exports__.ODBLiteTransaction;
|
|
1950
2114
|
exports.ORM = __webpack_exports__.ORM;
|
|
2115
|
+
exports.ORMTransaction = __webpack_exports__.ORMTransaction;
|
|
1951
2116
|
exports.QueryError = __webpack_exports__.QueryError;
|
|
1952
2117
|
exports.SQLParser = __webpack_exports__.SQLParser;
|
|
1953
2118
|
exports.ServiceClient = __webpack_exports__.ServiceClient;
|
|
@@ -1996,6 +2161,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
1996
2161
|
"ODBLiteError",
|
|
1997
2162
|
"ODBLiteTransaction",
|
|
1998
2163
|
"ORM",
|
|
2164
|
+
"ORMTransaction",
|
|
1999
2165
|
"QueryError",
|
|
2000
2166
|
"SQLParser",
|
|
2001
2167
|
"ServiceClient",
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { HTTPClient } from './core/http-client.ts';
|
|
|
5
5
|
export { SQLParser, sql, fragment } from './core/sql-parser.ts';
|
|
6
6
|
export { ServiceClient } from './service/service-client.ts';
|
|
7
7
|
export { DatabaseManager, parseSQL, splitSQLStatements, BunSQLiteAdapter, LibSQLAdapter, ODBLiteAdapter, sql as sqlTemplate, raw as rawSQL, empty, fragment as sqlFragment, join as sqlJoin, set, where as sqlWhere, convertTemplateToQuery, } from './database/index.ts';
|
|
8
|
-
export { ORM, createORM, eq, ne, gt, gte, lt, lte, like, inArray, isNull, isNotNull, and, or, type WhereCondition, type OrderByDirection, } from './orm/index.ts';
|
|
8
|
+
export { ORM, Transaction as ORMTransaction, createORM, eq, ne, gt, gte, lt, lte, like, inArray, isNull, isNotNull, and, or, type WhereCondition, type OrderByDirection, } from './orm/index.ts';
|
|
9
9
|
export type { ODBLiteConfig, ODBLiteConnection, QueryResult, Transaction, SQLFragment, PreparedQuery, QueryParameter, PrimitiveType, Row } from './types.ts';
|
|
10
10
|
export type { ServiceClientConfig, ODBLiteDatabase, ODBLiteNode } from './service/service-client.ts';
|
|
11
11
|
export type { TenancyMode, BackendType, QueryResult as DatabaseQueryResult, Connection, DatabaseAdapter, PreparedStatement as DatabasePreparedStatement, DatabaseManagerConfig, MigrationConfig, BunSQLiteConfig, LibSQLConfig, ODBLiteConfig as DatabaseODBLiteConfig, TenantInfo, ParsedStatements, SQLParserOptions, SqlQuery, SqlFragment, } from './database/index.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EACL,eAAe,EACf,QAAQ,EACR,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,cAAc,EAEd,GAAG,IAAI,WAAW,EAClB,GAAG,IAAI,MAAM,EACb,KAAK,EACL,QAAQ,IAAI,WAAW,EACvB,IAAI,IAAI,OAAO,EACf,GAAG,EACH,KAAK,IAAI,QAAQ,EACjB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,GAAG,EACH,SAAS,EACT,EAAE,EACF,EAAE,EACF,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,IAAI,EACJ,OAAO,EACP,MAAM,EACN,SAAS,EACT,GAAG,EACH,EAAE,EACF,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,cAAc,EACd,aAAa,EACb,GAAG,EACJ,MAAM,YAAY,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