@type32/tauri-sqlite-orm 0.1.12 → 0.1.14
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 +27 -6
- package/dist/index.d.ts +27 -6
- package/dist/index.js +7 -5
- package/dist/index.mjs +7 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -194,6 +194,31 @@ type InferInsert<T> = T extends {
|
|
|
194
194
|
type InferSelect<T> = T extends {
|
|
195
195
|
$inferSelect: infer S;
|
|
196
196
|
} ? S : never;
|
|
197
|
+
type WithSpec = Record<string, boolean | {
|
|
198
|
+
with?: WithSpec;
|
|
199
|
+
columns?: string[];
|
|
200
|
+
}>;
|
|
201
|
+
type FindManyOptions<TTable extends Table<any>> = {
|
|
202
|
+
with?: WithSpec;
|
|
203
|
+
join?: boolean;
|
|
204
|
+
columns?: (keyof InferSelect<TTable>)[] | Record<keyof InferSelect<TTable>, boolean>;
|
|
205
|
+
where?: SQL | Partial<InferSelect<TTable>> | ((table: TTable, ops: {
|
|
206
|
+
eq: typeof eq;
|
|
207
|
+
ne: typeof ne;
|
|
208
|
+
gt: typeof gt;
|
|
209
|
+
gte: typeof gte;
|
|
210
|
+
lt: typeof lt;
|
|
211
|
+
lte: typeof lte;
|
|
212
|
+
like: typeof like;
|
|
213
|
+
}) => SQL);
|
|
214
|
+
orderBy?: (keyof InferSelect<TTable>)[] | ((table: TTable, ops: {
|
|
215
|
+
asc: typeof asc;
|
|
216
|
+
desc: typeof desc;
|
|
217
|
+
}) => (string | SQL)[]);
|
|
218
|
+
limit?: number;
|
|
219
|
+
offset?: number;
|
|
220
|
+
};
|
|
221
|
+
type FindFirstOptions<TTable extends Table<any>> = Omit<FindManyOptions<TTable>, "limit" | "offset">;
|
|
197
222
|
declare class SelectQueryBuilder<T> {
|
|
198
223
|
private _table;
|
|
199
224
|
private _selectedColumns;
|
|
@@ -323,8 +348,8 @@ declare class TauriORM {
|
|
|
323
348
|
configure<TTables extends Record<string, Table<any>>, TRelDefs extends Record<string, Record<string, RelationConfig>> = Record<string, Record<string, RelationConfig>>>(tables: TTables, relDefs?: TRelDefs): this & {
|
|
324
349
|
query: {
|
|
325
350
|
[K in keyof TTables]: {
|
|
326
|
-
findMany: (opts?:
|
|
327
|
-
findFirst: (opts?:
|
|
351
|
+
findMany: (opts?: FindManyOptions<TTables[K]>) => Promise<Array<InferSelect<TTables[K]>>>;
|
|
352
|
+
findFirst: (opts?: FindFirstOptions<TTables[K]>) => Promise<InferSelect<TTables[K]> | null>;
|
|
328
353
|
};
|
|
329
354
|
};
|
|
330
355
|
};
|
|
@@ -414,10 +439,6 @@ type ManyRelation = {
|
|
|
414
439
|
};
|
|
415
440
|
declare function relations(baseTable: Table<any>, builder: (ctx: RelationBuilderCtx) => Record<string, OneRelation | ManyRelation>): Record<string, OneRelation | ManyRelation>;
|
|
416
441
|
type RelationConfig = OneRelation | ManyRelation;
|
|
417
|
-
type WithSpec = Record<string, boolean | {
|
|
418
|
-
with?: WithSpec;
|
|
419
|
-
columns?: string[];
|
|
420
|
-
}>;
|
|
421
442
|
declare function makeQueryAPI(tables: Record<string, Table<any>>, relDefs: Record<string, Record<string, RelationConfig>>, dbProvider: () => Promise<Database>): { [K in keyof typeof tables]: {
|
|
422
443
|
findMany: (opts?: {
|
|
423
444
|
with?: WithSpec;
|
package/dist/index.d.ts
CHANGED
|
@@ -194,6 +194,31 @@ type InferInsert<T> = T extends {
|
|
|
194
194
|
type InferSelect<T> = T extends {
|
|
195
195
|
$inferSelect: infer S;
|
|
196
196
|
} ? S : never;
|
|
197
|
+
type WithSpec = Record<string, boolean | {
|
|
198
|
+
with?: WithSpec;
|
|
199
|
+
columns?: string[];
|
|
200
|
+
}>;
|
|
201
|
+
type FindManyOptions<TTable extends Table<any>> = {
|
|
202
|
+
with?: WithSpec;
|
|
203
|
+
join?: boolean;
|
|
204
|
+
columns?: (keyof InferSelect<TTable>)[] | Record<keyof InferSelect<TTable>, boolean>;
|
|
205
|
+
where?: SQL | Partial<InferSelect<TTable>> | ((table: TTable, ops: {
|
|
206
|
+
eq: typeof eq;
|
|
207
|
+
ne: typeof ne;
|
|
208
|
+
gt: typeof gt;
|
|
209
|
+
gte: typeof gte;
|
|
210
|
+
lt: typeof lt;
|
|
211
|
+
lte: typeof lte;
|
|
212
|
+
like: typeof like;
|
|
213
|
+
}) => SQL);
|
|
214
|
+
orderBy?: (keyof InferSelect<TTable>)[] | ((table: TTable, ops: {
|
|
215
|
+
asc: typeof asc;
|
|
216
|
+
desc: typeof desc;
|
|
217
|
+
}) => (string | SQL)[]);
|
|
218
|
+
limit?: number;
|
|
219
|
+
offset?: number;
|
|
220
|
+
};
|
|
221
|
+
type FindFirstOptions<TTable extends Table<any>> = Omit<FindManyOptions<TTable>, "limit" | "offset">;
|
|
197
222
|
declare class SelectQueryBuilder<T> {
|
|
198
223
|
private _table;
|
|
199
224
|
private _selectedColumns;
|
|
@@ -323,8 +348,8 @@ declare class TauriORM {
|
|
|
323
348
|
configure<TTables extends Record<string, Table<any>>, TRelDefs extends Record<string, Record<string, RelationConfig>> = Record<string, Record<string, RelationConfig>>>(tables: TTables, relDefs?: TRelDefs): this & {
|
|
324
349
|
query: {
|
|
325
350
|
[K in keyof TTables]: {
|
|
326
|
-
findMany: (opts?:
|
|
327
|
-
findFirst: (opts?:
|
|
351
|
+
findMany: (opts?: FindManyOptions<TTables[K]>) => Promise<Array<InferSelect<TTables[K]>>>;
|
|
352
|
+
findFirst: (opts?: FindFirstOptions<TTables[K]>) => Promise<InferSelect<TTables[K]> | null>;
|
|
328
353
|
};
|
|
329
354
|
};
|
|
330
355
|
};
|
|
@@ -414,10 +439,6 @@ type ManyRelation = {
|
|
|
414
439
|
};
|
|
415
440
|
declare function relations(baseTable: Table<any>, builder: (ctx: RelationBuilderCtx) => Record<string, OneRelation | ManyRelation>): Record<string, OneRelation | ManyRelation>;
|
|
416
441
|
type RelationConfig = OneRelation | ManyRelation;
|
|
417
|
-
type WithSpec = Record<string, boolean | {
|
|
418
|
-
with?: WithSpec;
|
|
419
|
-
columns?: string[];
|
|
420
|
-
}>;
|
|
421
442
|
declare function makeQueryAPI(tables: Record<string, Table<any>>, relDefs: Record<string, Record<string, RelationConfig>>, dbProvider: () => Promise<Database>): { [K in keyof typeof tables]: {
|
|
422
443
|
findMany: (opts?: {
|
|
423
444
|
with?: WithSpec;
|
package/dist/index.js
CHANGED
|
@@ -273,7 +273,7 @@ function defineTable(tableName, schema, extras) {
|
|
|
273
273
|
col.tableName = tableName;
|
|
274
274
|
}
|
|
275
275
|
const table = {
|
|
276
|
-
|
|
276
|
+
tableName,
|
|
277
277
|
_schema: finalizedSchema,
|
|
278
278
|
_constraints: [],
|
|
279
279
|
_indexes: [],
|
|
@@ -1066,7 +1066,9 @@ var TauriORM = class {
|
|
|
1066
1066
|
return String(dv);
|
|
1067
1067
|
}
|
|
1068
1068
|
generateCreateTableSql(table) {
|
|
1069
|
-
const tableName = table
|
|
1069
|
+
const tableName = getTableName(table);
|
|
1070
|
+
if (!tableName)
|
|
1071
|
+
throw new Error("Invalid table passed to DDL: missing table name");
|
|
1070
1072
|
const columns = Object.values(table._schema);
|
|
1071
1073
|
const columnDefs = columns.map((col) => {
|
|
1072
1074
|
let def = `${col.name} ${col.type}`;
|
|
@@ -1222,7 +1224,7 @@ var TauriORM = class {
|
|
|
1222
1224
|
if (!this._tables) throw new Error("No tables configured.");
|
|
1223
1225
|
const dbi = await this.getDb();
|
|
1224
1226
|
const configuredNames = Object.values(this._tables).map(
|
|
1225
|
-
(t) => t
|
|
1227
|
+
(t) => getTableName(t)
|
|
1226
1228
|
);
|
|
1227
1229
|
const existing = await dbi.select(
|
|
1228
1230
|
`SELECT name FROM sqlite_master WHERE type='table'`
|
|
@@ -1236,7 +1238,7 @@ var TauriORM = class {
|
|
|
1236
1238
|
);
|
|
1237
1239
|
const tables = {};
|
|
1238
1240
|
for (const tbl of Object.values(this._tables)) {
|
|
1239
|
-
const tableName = tbl
|
|
1241
|
+
const tableName = getTableName(tbl);
|
|
1240
1242
|
if (!existingNames.includes(tableName)) {
|
|
1241
1243
|
tables[tableName] = {
|
|
1242
1244
|
missingColumns: Object.keys(tbl._schema),
|
|
@@ -1407,7 +1409,7 @@ var TauriORM = class {
|
|
|
1407
1409
|
const dbi = await this.getDb();
|
|
1408
1410
|
const preserve = options?.preserveData !== false;
|
|
1409
1411
|
for (const tbl of tables) {
|
|
1410
|
-
const tableName = tbl
|
|
1412
|
+
const tableName = getTableName(tbl);
|
|
1411
1413
|
const exists2 = await this.tableExists(tableName);
|
|
1412
1414
|
if (!exists2) {
|
|
1413
1415
|
await this.run(this.buildCreateTableSQL(tbl));
|
package/dist/index.mjs
CHANGED
|
@@ -195,7 +195,7 @@ function defineTable(tableName, schema, extras) {
|
|
|
195
195
|
col.tableName = tableName;
|
|
196
196
|
}
|
|
197
197
|
const table = {
|
|
198
|
-
|
|
198
|
+
tableName,
|
|
199
199
|
_schema: finalizedSchema,
|
|
200
200
|
_constraints: [],
|
|
201
201
|
_indexes: [],
|
|
@@ -988,7 +988,9 @@ var TauriORM = class {
|
|
|
988
988
|
return String(dv);
|
|
989
989
|
}
|
|
990
990
|
generateCreateTableSql(table) {
|
|
991
|
-
const tableName = table
|
|
991
|
+
const tableName = getTableName(table);
|
|
992
|
+
if (!tableName)
|
|
993
|
+
throw new Error("Invalid table passed to DDL: missing table name");
|
|
992
994
|
const columns = Object.values(table._schema);
|
|
993
995
|
const columnDefs = columns.map((col) => {
|
|
994
996
|
let def = `${col.name} ${col.type}`;
|
|
@@ -1144,7 +1146,7 @@ var TauriORM = class {
|
|
|
1144
1146
|
if (!this._tables) throw new Error("No tables configured.");
|
|
1145
1147
|
const dbi = await this.getDb();
|
|
1146
1148
|
const configuredNames = Object.values(this._tables).map(
|
|
1147
|
-
(t) => t
|
|
1149
|
+
(t) => getTableName(t)
|
|
1148
1150
|
);
|
|
1149
1151
|
const existing = await dbi.select(
|
|
1150
1152
|
`SELECT name FROM sqlite_master WHERE type='table'`
|
|
@@ -1158,7 +1160,7 @@ var TauriORM = class {
|
|
|
1158
1160
|
);
|
|
1159
1161
|
const tables = {};
|
|
1160
1162
|
for (const tbl of Object.values(this._tables)) {
|
|
1161
|
-
const tableName = tbl
|
|
1163
|
+
const tableName = getTableName(tbl);
|
|
1162
1164
|
if (!existingNames.includes(tableName)) {
|
|
1163
1165
|
tables[tableName] = {
|
|
1164
1166
|
missingColumns: Object.keys(tbl._schema),
|
|
@@ -1329,7 +1331,7 @@ var TauriORM = class {
|
|
|
1329
1331
|
const dbi = await this.getDb();
|
|
1330
1332
|
const preserve = options?.preserveData !== false;
|
|
1331
1333
|
for (const tbl of tables) {
|
|
1332
|
-
const tableName = tbl
|
|
1334
|
+
const tableName = getTableName(tbl);
|
|
1333
1335
|
const exists2 = await this.tableExists(tableName);
|
|
1334
1336
|
if (!exists2) {
|
|
1335
1337
|
await this.run(this.buildCreateTableSQL(tbl));
|