@type32/tauri-sqlite-orm 0.1.11 → 0.1.12
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.js +28 -9
- package/dist/index.mjs +28 -9
- package/package.json +3 -6
package/dist/index.js
CHANGED
|
@@ -504,6 +504,10 @@ var asc = (column) => `${getQualifiedName(column)} ASC`;
|
|
|
504
504
|
var desc = (column) => `${getQualifiedName(column)} DESC`;
|
|
505
505
|
|
|
506
506
|
// src/orm.ts
|
|
507
|
+
function getTableName(table) {
|
|
508
|
+
const anyTable = table;
|
|
509
|
+
return anyTable._tableName || anyTable.tableName || anyTable.name || "";
|
|
510
|
+
}
|
|
507
511
|
var SelectQueryBuilder = class {
|
|
508
512
|
_table = null;
|
|
509
513
|
_selectedColumns = [];
|
|
@@ -593,8 +597,12 @@ var SelectQueryBuilder = class {
|
|
|
593
597
|
throw new Error("Cannot execute select query without a 'from' table.");
|
|
594
598
|
}
|
|
595
599
|
const db = await this._dbProvider();
|
|
596
|
-
const baseTableName = this._table
|
|
597
|
-
if (!baseTableName)
|
|
600
|
+
const baseTableName = getTableName(this._table);
|
|
601
|
+
if (!baseTableName) {
|
|
602
|
+
throw new Error(
|
|
603
|
+
"Invalid table passed to select.from(): missing table name"
|
|
604
|
+
);
|
|
605
|
+
}
|
|
598
606
|
const bindings = [];
|
|
599
607
|
const selectList = this._selectedColumns.length > 0 ? this._selectedColumns.map((c) => c.alias ? `${c.sql} AS ${c.alias}` : c.sql).join(", ") : Object.values(this._table._schema).map((c) => `${baseTableName}.${c.name}`).join(", ");
|
|
600
608
|
let query = `SELECT ${this._distinct ? "DISTINCT " : ""}${selectList} FROM ${baseTableName}`;
|
|
@@ -724,8 +732,11 @@ var TauriORM = class {
|
|
|
724
732
|
}
|
|
725
733
|
async execute() {
|
|
726
734
|
const db = await self.getDb();
|
|
727
|
-
const tableName = this._table
|
|
728
|
-
if (!tableName)
|
|
735
|
+
const tableName = getTableName(this._table);
|
|
736
|
+
if (!tableName)
|
|
737
|
+
throw new Error(
|
|
738
|
+
"Invalid table passed to insert(): missing table name"
|
|
739
|
+
);
|
|
729
740
|
if (this._selectSql) {
|
|
730
741
|
const cols = Object.keys(this._table._schema);
|
|
731
742
|
let query = `INSERT INTO ${tableName} (${cols.join(", ")}) ${this._selectSql.clause}`;
|
|
@@ -763,7 +774,9 @@ var TauriORM = class {
|
|
|
763
774
|
const keys = entries.map(([k]) => schema[k]?.name ?? k);
|
|
764
775
|
const values = entries.map(([k, v]) => coerceValue2(schema[k], v));
|
|
765
776
|
const placeholders = values.map(() => "?").join(", ");
|
|
766
|
-
let query = `INSERT INTO ${tableName} (${keys.join(
|
|
777
|
+
let query = `INSERT INTO ${tableName} (${keys.join(
|
|
778
|
+
", "
|
|
779
|
+
)}) VALUES (${placeholders})`;
|
|
767
780
|
const bindings = [...values];
|
|
768
781
|
query += this._buildConflictClause();
|
|
769
782
|
const ret = await this._executeWithReturning(db, query, bindings);
|
|
@@ -855,8 +868,11 @@ var TauriORM = class {
|
|
|
855
868
|
if (!this._data)
|
|
856
869
|
throw new Error("Update requires set() before execute()");
|
|
857
870
|
const db = await self.getDb();
|
|
858
|
-
const tableName = this._table
|
|
859
|
-
if (!tableName)
|
|
871
|
+
const tableName = getTableName(this._table);
|
|
872
|
+
if (!tableName)
|
|
873
|
+
throw new Error(
|
|
874
|
+
"Invalid table passed to update(): missing table name"
|
|
875
|
+
);
|
|
860
876
|
const schema = this._table._schema;
|
|
861
877
|
const dataToSet = { ...this._data };
|
|
862
878
|
for (const [key, col] of Object.entries(schema)) {
|
|
@@ -972,8 +988,11 @@ var TauriORM = class {
|
|
|
972
988
|
}
|
|
973
989
|
async execute() {
|
|
974
990
|
const db = await self.getDb();
|
|
975
|
-
const tableName = this._table
|
|
976
|
-
if (!tableName)
|
|
991
|
+
const tableName = getTableName(this._table);
|
|
992
|
+
if (!tableName)
|
|
993
|
+
throw new Error(
|
|
994
|
+
"Invalid table passed to delete(): missing table name"
|
|
995
|
+
);
|
|
977
996
|
let query = `DELETE FROM ${tableName}`;
|
|
978
997
|
const bindings = [];
|
|
979
998
|
if (this._where) {
|
package/dist/index.mjs
CHANGED
|
@@ -426,6 +426,10 @@ var asc = (column) => `${getQualifiedName(column)} ASC`;
|
|
|
426
426
|
var desc = (column) => `${getQualifiedName(column)} DESC`;
|
|
427
427
|
|
|
428
428
|
// src/orm.ts
|
|
429
|
+
function getTableName(table) {
|
|
430
|
+
const anyTable = table;
|
|
431
|
+
return anyTable._tableName || anyTable.tableName || anyTable.name || "";
|
|
432
|
+
}
|
|
429
433
|
var SelectQueryBuilder = class {
|
|
430
434
|
_table = null;
|
|
431
435
|
_selectedColumns = [];
|
|
@@ -515,8 +519,12 @@ var SelectQueryBuilder = class {
|
|
|
515
519
|
throw new Error("Cannot execute select query without a 'from' table.");
|
|
516
520
|
}
|
|
517
521
|
const db = await this._dbProvider();
|
|
518
|
-
const baseTableName = this._table
|
|
519
|
-
if (!baseTableName)
|
|
522
|
+
const baseTableName = getTableName(this._table);
|
|
523
|
+
if (!baseTableName) {
|
|
524
|
+
throw new Error(
|
|
525
|
+
"Invalid table passed to select.from(): missing table name"
|
|
526
|
+
);
|
|
527
|
+
}
|
|
520
528
|
const bindings = [];
|
|
521
529
|
const selectList = this._selectedColumns.length > 0 ? this._selectedColumns.map((c) => c.alias ? `${c.sql} AS ${c.alias}` : c.sql).join(", ") : Object.values(this._table._schema).map((c) => `${baseTableName}.${c.name}`).join(", ");
|
|
522
530
|
let query = `SELECT ${this._distinct ? "DISTINCT " : ""}${selectList} FROM ${baseTableName}`;
|
|
@@ -646,8 +654,11 @@ var TauriORM = class {
|
|
|
646
654
|
}
|
|
647
655
|
async execute() {
|
|
648
656
|
const db = await self.getDb();
|
|
649
|
-
const tableName = this._table
|
|
650
|
-
if (!tableName)
|
|
657
|
+
const tableName = getTableName(this._table);
|
|
658
|
+
if (!tableName)
|
|
659
|
+
throw new Error(
|
|
660
|
+
"Invalid table passed to insert(): missing table name"
|
|
661
|
+
);
|
|
651
662
|
if (this._selectSql) {
|
|
652
663
|
const cols = Object.keys(this._table._schema);
|
|
653
664
|
let query = `INSERT INTO ${tableName} (${cols.join(", ")}) ${this._selectSql.clause}`;
|
|
@@ -685,7 +696,9 @@ var TauriORM = class {
|
|
|
685
696
|
const keys = entries.map(([k]) => schema[k]?.name ?? k);
|
|
686
697
|
const values = entries.map(([k, v]) => coerceValue2(schema[k], v));
|
|
687
698
|
const placeholders = values.map(() => "?").join(", ");
|
|
688
|
-
let query = `INSERT INTO ${tableName} (${keys.join(
|
|
699
|
+
let query = `INSERT INTO ${tableName} (${keys.join(
|
|
700
|
+
", "
|
|
701
|
+
)}) VALUES (${placeholders})`;
|
|
689
702
|
const bindings = [...values];
|
|
690
703
|
query += this._buildConflictClause();
|
|
691
704
|
const ret = await this._executeWithReturning(db, query, bindings);
|
|
@@ -777,8 +790,11 @@ var TauriORM = class {
|
|
|
777
790
|
if (!this._data)
|
|
778
791
|
throw new Error("Update requires set() before execute()");
|
|
779
792
|
const db = await self.getDb();
|
|
780
|
-
const tableName = this._table
|
|
781
|
-
if (!tableName)
|
|
793
|
+
const tableName = getTableName(this._table);
|
|
794
|
+
if (!tableName)
|
|
795
|
+
throw new Error(
|
|
796
|
+
"Invalid table passed to update(): missing table name"
|
|
797
|
+
);
|
|
782
798
|
const schema = this._table._schema;
|
|
783
799
|
const dataToSet = { ...this._data };
|
|
784
800
|
for (const [key, col] of Object.entries(schema)) {
|
|
@@ -894,8 +910,11 @@ var TauriORM = class {
|
|
|
894
910
|
}
|
|
895
911
|
async execute() {
|
|
896
912
|
const db = await self.getDb();
|
|
897
|
-
const tableName = this._table
|
|
898
|
-
if (!tableName)
|
|
913
|
+
const tableName = getTableName(this._table);
|
|
914
|
+
if (!tableName)
|
|
915
|
+
throw new Error(
|
|
916
|
+
"Invalid table passed to delete(): missing table name"
|
|
917
|
+
);
|
|
899
918
|
let query = `DELETE FROM ${tableName}`;
|
|
900
919
|
const bindings = [];
|
|
901
920
|
if (this._where) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@type32/tauri-sqlite-orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "A Drizzle-like ORM for Tauri v2's SQL JS API plugin.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"bin": {
|
|
9
|
-
"tauriorm-kit": "./dist/cli.mjs"
|
|
10
|
-
},
|
|
11
8
|
"exports": {
|
|
12
9
|
".": {
|
|
13
10
|
"import": "./dist/index.mjs",
|
|
@@ -18,8 +15,8 @@
|
|
|
18
15
|
"dist"
|
|
19
16
|
],
|
|
20
17
|
"scripts": {
|
|
21
|
-
"build": "tsup src/index.ts
|
|
22
|
-
"dev": "tsup src/index.ts
|
|
18
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
19
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
23
20
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
21
|
},
|
|
25
22
|
"keywords": [
|