@type32/tauri-sqlite-orm 0.1.11 → 0.1.13

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 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._tableName || this._table.tableName;
597
- if (!baseTableName) throw new Error("Invalid table passed to select.from(): missing _tableName");
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._tableName || this._table.tableName;
728
- if (!tableName) throw new Error("Invalid table passed to insert(): missing _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(", ")}) VALUES (${placeholders})`;
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._tableName || this._table.tableName;
859
- if (!tableName) throw new Error("Invalid table passed to update(): missing _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._tableName || this._table.tableName;
976
- if (!tableName) throw new Error("Invalid table passed to delete(): missing _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) {
@@ -1047,7 +1066,9 @@ var TauriORM = class {
1047
1066
  return String(dv);
1048
1067
  }
1049
1068
  generateCreateTableSql(table) {
1050
- const tableName = table._tableName;
1069
+ const tableName = getTableName(table);
1070
+ if (!tableName)
1071
+ throw new Error("Invalid table passed to DDL: missing table name");
1051
1072
  const columns = Object.values(table._schema);
1052
1073
  const columnDefs = columns.map((col) => {
1053
1074
  let def = `${col.name} ${col.type}`;
@@ -1203,7 +1224,7 @@ var TauriORM = class {
1203
1224
  if (!this._tables) throw new Error("No tables configured.");
1204
1225
  const dbi = await this.getDb();
1205
1226
  const configuredNames = Object.values(this._tables).map(
1206
- (t) => t._tableName
1227
+ (t) => getTableName(t)
1207
1228
  );
1208
1229
  const existing = await dbi.select(
1209
1230
  `SELECT name FROM sqlite_master WHERE type='table'`
@@ -1217,7 +1238,7 @@ var TauriORM = class {
1217
1238
  );
1218
1239
  const tables = {};
1219
1240
  for (const tbl of Object.values(this._tables)) {
1220
- const tableName = tbl._tableName;
1241
+ const tableName = getTableName(tbl);
1221
1242
  if (!existingNames.includes(tableName)) {
1222
1243
  tables[tableName] = {
1223
1244
  missingColumns: Object.keys(tbl._schema),
@@ -1388,7 +1409,7 @@ var TauriORM = class {
1388
1409
  const dbi = await this.getDb();
1389
1410
  const preserve = options?.preserveData !== false;
1390
1411
  for (const tbl of tables) {
1391
- const tableName = tbl._tableName;
1412
+ const tableName = getTableName(tbl);
1392
1413
  const exists2 = await this.tableExists(tableName);
1393
1414
  if (!exists2) {
1394
1415
  await this.run(this.buildCreateTableSQL(tbl));
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._tableName || this._table.tableName;
519
- if (!baseTableName) throw new Error("Invalid table passed to select.from(): missing _tableName");
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._tableName || this._table.tableName;
650
- if (!tableName) throw new Error("Invalid table passed to insert(): missing _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(", ")}) VALUES (${placeholders})`;
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._tableName || this._table.tableName;
781
- if (!tableName) throw new Error("Invalid table passed to update(): missing _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._tableName || this._table.tableName;
898
- if (!tableName) throw new Error("Invalid table passed to delete(): missing _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) {
@@ -969,7 +988,9 @@ var TauriORM = class {
969
988
  return String(dv);
970
989
  }
971
990
  generateCreateTableSql(table) {
972
- const tableName = table._tableName;
991
+ const tableName = getTableName(table);
992
+ if (!tableName)
993
+ throw new Error("Invalid table passed to DDL: missing table name");
973
994
  const columns = Object.values(table._schema);
974
995
  const columnDefs = columns.map((col) => {
975
996
  let def = `${col.name} ${col.type}`;
@@ -1125,7 +1146,7 @@ var TauriORM = class {
1125
1146
  if (!this._tables) throw new Error("No tables configured.");
1126
1147
  const dbi = await this.getDb();
1127
1148
  const configuredNames = Object.values(this._tables).map(
1128
- (t) => t._tableName
1149
+ (t) => getTableName(t)
1129
1150
  );
1130
1151
  const existing = await dbi.select(
1131
1152
  `SELECT name FROM sqlite_master WHERE type='table'`
@@ -1139,7 +1160,7 @@ var TauriORM = class {
1139
1160
  );
1140
1161
  const tables = {};
1141
1162
  for (const tbl of Object.values(this._tables)) {
1142
- const tableName = tbl._tableName;
1163
+ const tableName = getTableName(tbl);
1143
1164
  if (!existingNames.includes(tableName)) {
1144
1165
  tables[tableName] = {
1145
1166
  missingColumns: Object.keys(tbl._schema),
@@ -1310,7 +1331,7 @@ var TauriORM = class {
1310
1331
  const dbi = await this.getDb();
1311
1332
  const preserve = options?.preserveData !== false;
1312
1333
  for (const tbl of tables) {
1313
- const tableName = tbl._tableName;
1334
+ const tableName = getTableName(tbl);
1314
1335
  const exists2 = await this.tableExists(tableName);
1315
1336
  if (!exists2) {
1316
1337
  await this.run(this.buildCreateTableSQL(tbl));
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@type32/tauri-sqlite-orm",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
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 src/cli.ts --format esm,cjs --dts",
22
- "dev": "tsup src/index.ts src/cli.ts --format esm,cjs --dts --watch",
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": [