@type32/tauri-sqlite-orm 0.1.6 → 0.1.8

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.d.mts CHANGED
@@ -295,6 +295,7 @@ declare class TauriORM {
295
295
  execute(): Promise<unknown>;
296
296
  };
297
297
  run(query: string, bindings?: any[]): Promise<void>;
298
+ private formatDefaultValue;
298
299
  private generateCreateTableSql;
299
300
  createTableIfNotExists(table: Table<any>): Promise<void>;
300
301
  createTablesIfNotExist(tables: Table<any>[]): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -295,6 +295,7 @@ declare class TauriORM {
295
295
  execute(): Promise<unknown>;
296
296
  };
297
297
  run(query: string, bindings?: any[]): Promise<void>;
298
+ private formatDefaultValue;
298
299
  private generateCreateTableSql;
299
300
  createTableIfNotExists(table: Table<any>): Promise<void>;
300
301
  createTablesIfNotExist(tables: Table<any>[]): Promise<void>;
package/dist/index.js CHANGED
@@ -211,7 +211,10 @@ function increments(name) {
211
211
  }
212
212
  function unique(name) {
213
213
  return {
214
- on: (...cols) => ({ name, columns: cols.map((c) => c.name) })
214
+ on: (...cols) => ({
215
+ name,
216
+ columns: cols.map((c) => c.name)
217
+ })
215
218
  };
216
219
  }
217
220
  function primaryKey(opts) {
@@ -233,14 +236,26 @@ function foreignKey(opts) {
233
236
  }
234
237
  function index(name) {
235
238
  return {
236
- on: (...cols) => ({ name, columns: cols.map((c) => c.name) }),
239
+ on: (...cols) => ({
240
+ name,
241
+ columns: cols.map((c) => c.name)
242
+ }),
237
243
  where: (expr) => ({ name, columns: [], where: expr })
238
244
  };
239
245
  }
240
246
  function uniqueIndex(name) {
241
247
  return {
242
- on: (...cols) => ({ name, columns: cols.map((c) => c.name), unique: true }),
243
- where: (expr) => ({ name, columns: [], unique: true, where: expr })
248
+ on: (...cols) => ({
249
+ name,
250
+ columns: cols.map((c) => c.name),
251
+ unique: true
252
+ }),
253
+ where: (expr) => ({
254
+ name,
255
+ columns: [],
256
+ unique: true,
257
+ where: expr
258
+ })
244
259
  };
245
260
  }
246
261
  function defineTable(tableName, schema, extras) {
@@ -960,6 +975,25 @@ var TauriORM = class {
960
975
  await db.execute(query, bindings);
961
976
  }
962
977
  // --- Migrations API ---
978
+ formatDefaultValue(col) {
979
+ const dv = col.defaultValue;
980
+ if (dv === void 0) return null;
981
+ if (dv && typeof dv === "object" && "raw" in dv) {
982
+ return dv.raw;
983
+ }
984
+ if (dv instanceof Date) {
985
+ const isMs = col.mode === "timestamp_ms";
986
+ const num = isMs ? dv.getTime() : Math.floor(dv.getTime() / 1e3);
987
+ return String(num);
988
+ }
989
+ if (col.mode === "boolean") {
990
+ return String(dv ? 1 : 0);
991
+ }
992
+ if (typeof dv === "string") {
993
+ return `'${dv.replace(/'/g, "''")}'`;
994
+ }
995
+ return String(dv);
996
+ }
963
997
  generateCreateTableSql(table) {
964
998
  const tableName = table._tableName;
965
999
  const columns = Object.values(table._schema);
@@ -970,14 +1004,8 @@ var TauriORM = class {
970
1004
  }
971
1005
  if (col.isNotNull) def += " NOT NULL";
972
1006
  if (col.defaultValue !== void 0) {
973
- const dv = col.defaultValue;
974
- if (dv && typeof dv === "object" && "raw" in dv) {
975
- def += ` DEFAULT ${dv.raw}`;
976
- } else if (typeof dv === "string") {
977
- def += ` DEFAULT '${dv.replace(/'/g, "''")}'`;
978
- } else {
979
- def += ` DEFAULT ${dv}`;
980
- }
1007
+ const formatted = this.formatDefaultValue(col);
1008
+ if (formatted !== null) def += ` DEFAULT ${formatted}`;
981
1009
  }
982
1010
  if (col.references && !col.isPrimaryKey) {
983
1011
  def += ` REFERENCES ${col.references.table} (${col.references.column})`;
@@ -1278,12 +1306,8 @@ var TauriORM = class {
1278
1306
  let clause = `${m.name} ${m.type}`;
1279
1307
  if (m.isNotNull) clause += " NOT NULL";
1280
1308
  if (m.defaultValue !== void 0) {
1281
- const dv = m.defaultValue;
1282
- if (dv && typeof dv === "object" && "raw" in dv)
1283
- clause += ` DEFAULT ${dv.raw}`;
1284
- else if (typeof dv === "string")
1285
- clause += ` DEFAULT '${dv.replace(/'/g, "''")}'`;
1286
- else clause += ` DEFAULT ${dv}`;
1309
+ const formatted = this.formatDefaultValue(m);
1310
+ if (formatted !== null) clause += ` DEFAULT ${formatted}`;
1287
1311
  }
1288
1312
  await this.run(`ALTER TABLE ${tableName} ADD COLUMN ${clause}`);
1289
1313
  }
package/dist/index.mjs CHANGED
@@ -133,7 +133,10 @@ function increments(name) {
133
133
  }
134
134
  function unique(name) {
135
135
  return {
136
- on: (...cols) => ({ name, columns: cols.map((c) => c.name) })
136
+ on: (...cols) => ({
137
+ name,
138
+ columns: cols.map((c) => c.name)
139
+ })
137
140
  };
138
141
  }
139
142
  function primaryKey(opts) {
@@ -155,14 +158,26 @@ function foreignKey(opts) {
155
158
  }
156
159
  function index(name) {
157
160
  return {
158
- on: (...cols) => ({ name, columns: cols.map((c) => c.name) }),
161
+ on: (...cols) => ({
162
+ name,
163
+ columns: cols.map((c) => c.name)
164
+ }),
159
165
  where: (expr) => ({ name, columns: [], where: expr })
160
166
  };
161
167
  }
162
168
  function uniqueIndex(name) {
163
169
  return {
164
- on: (...cols) => ({ name, columns: cols.map((c) => c.name), unique: true }),
165
- where: (expr) => ({ name, columns: [], unique: true, where: expr })
170
+ on: (...cols) => ({
171
+ name,
172
+ columns: cols.map((c) => c.name),
173
+ unique: true
174
+ }),
175
+ where: (expr) => ({
176
+ name,
177
+ columns: [],
178
+ unique: true,
179
+ where: expr
180
+ })
166
181
  };
167
182
  }
168
183
  function defineTable(tableName, schema, extras) {
@@ -882,6 +897,25 @@ var TauriORM = class {
882
897
  await db.execute(query, bindings);
883
898
  }
884
899
  // --- Migrations API ---
900
+ formatDefaultValue(col) {
901
+ const dv = col.defaultValue;
902
+ if (dv === void 0) return null;
903
+ if (dv && typeof dv === "object" && "raw" in dv) {
904
+ return dv.raw;
905
+ }
906
+ if (dv instanceof Date) {
907
+ const isMs = col.mode === "timestamp_ms";
908
+ const num = isMs ? dv.getTime() : Math.floor(dv.getTime() / 1e3);
909
+ return String(num);
910
+ }
911
+ if (col.mode === "boolean") {
912
+ return String(dv ? 1 : 0);
913
+ }
914
+ if (typeof dv === "string") {
915
+ return `'${dv.replace(/'/g, "''")}'`;
916
+ }
917
+ return String(dv);
918
+ }
885
919
  generateCreateTableSql(table) {
886
920
  const tableName = table._tableName;
887
921
  const columns = Object.values(table._schema);
@@ -892,14 +926,8 @@ var TauriORM = class {
892
926
  }
893
927
  if (col.isNotNull) def += " NOT NULL";
894
928
  if (col.defaultValue !== void 0) {
895
- const dv = col.defaultValue;
896
- if (dv && typeof dv === "object" && "raw" in dv) {
897
- def += ` DEFAULT ${dv.raw}`;
898
- } else if (typeof dv === "string") {
899
- def += ` DEFAULT '${dv.replace(/'/g, "''")}'`;
900
- } else {
901
- def += ` DEFAULT ${dv}`;
902
- }
929
+ const formatted = this.formatDefaultValue(col);
930
+ if (formatted !== null) def += ` DEFAULT ${formatted}`;
903
931
  }
904
932
  if (col.references && !col.isPrimaryKey) {
905
933
  def += ` REFERENCES ${col.references.table} (${col.references.column})`;
@@ -1200,12 +1228,8 @@ var TauriORM = class {
1200
1228
  let clause = `${m.name} ${m.type}`;
1201
1229
  if (m.isNotNull) clause += " NOT NULL";
1202
1230
  if (m.defaultValue !== void 0) {
1203
- const dv = m.defaultValue;
1204
- if (dv && typeof dv === "object" && "raw" in dv)
1205
- clause += ` DEFAULT ${dv.raw}`;
1206
- else if (typeof dv === "string")
1207
- clause += ` DEFAULT '${dv.replace(/'/g, "''")}'`;
1208
- else clause += ` DEFAULT ${dv}`;
1231
+ const formatted = this.formatDefaultValue(m);
1232
+ if (formatted !== null) clause += ` DEFAULT ${formatted}`;
1209
1233
  }
1210
1234
  await this.run(`ALTER TABLE ${tableName} ADD COLUMN ${clause}`);
1211
1235
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@type32/tauri-sqlite-orm",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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",