@type32/tauri-sqlite-orm 0.1.18-1 → 0.1.18-2
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 +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +21 -4
- package/dist/index.mjs +21 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -117,6 +117,10 @@ declare class UpdateQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
|
|
117
117
|
private updateData;
|
|
118
118
|
constructor(db: Database, table: T);
|
|
119
119
|
set(data: Partial<InferInsertModel<T>>): this;
|
|
120
|
+
build(): {
|
|
121
|
+
sql: string;
|
|
122
|
+
params: any[];
|
|
123
|
+
};
|
|
120
124
|
execute(): Promise<number>;
|
|
121
125
|
}
|
|
122
126
|
declare class DeleteQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
package/dist/index.d.ts
CHANGED
|
@@ -117,6 +117,10 @@ declare class UpdateQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
|
|
117
117
|
private updateData;
|
|
118
118
|
constructor(db: Database, table: T);
|
|
119
119
|
set(data: Partial<InferInsertModel<T>>): this;
|
|
120
|
+
build(): {
|
|
121
|
+
sql: string;
|
|
122
|
+
params: any[];
|
|
123
|
+
};
|
|
120
124
|
execute(): Promise<number>;
|
|
121
125
|
}
|
|
122
126
|
declare class DeleteQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
package/dist/index.js
CHANGED
|
@@ -281,18 +281,35 @@ var UpdateQueryBuilder = class extends BaseQueryBuilder {
|
|
|
281
281
|
this.updateData = { ...this.updateData, ...data };
|
|
282
282
|
return this;
|
|
283
283
|
}
|
|
284
|
-
|
|
284
|
+
build() {
|
|
285
|
+
const baseQuery = this.query;
|
|
286
|
+
const whereParams = this.params;
|
|
287
|
+
let tablePart = baseQuery;
|
|
288
|
+
let whereClause = "";
|
|
289
|
+
const whereIndex = baseQuery.indexOf(" WHERE ");
|
|
290
|
+
if (whereIndex !== -1) {
|
|
291
|
+
tablePart = baseQuery.substring(0, whereIndex);
|
|
292
|
+
whereClause = baseQuery.substring(whereIndex);
|
|
293
|
+
}
|
|
285
294
|
const entries = Object.entries(this.updateData);
|
|
295
|
+
if (entries.length === 0) {
|
|
296
|
+
throw new Error("Cannot execute an update query without a .set() call.");
|
|
297
|
+
}
|
|
286
298
|
const setClause = entries.map(([key]) => {
|
|
287
299
|
const column = this.table._.columns[key];
|
|
288
|
-
if (!column)
|
|
300
|
+
if (!column) {
|
|
289
301
|
throw new Error(
|
|
290
302
|
`Column ${key} does not exist on table ${this.table._.name}`
|
|
291
303
|
);
|
|
304
|
+
}
|
|
292
305
|
return `${column._.name} = ?`;
|
|
293
306
|
}).join(", ");
|
|
294
|
-
|
|
295
|
-
|
|
307
|
+
const setParams = entries.map(([, value]) => value);
|
|
308
|
+
const sql = `${tablePart} SET ${setClause}${whereClause}`;
|
|
309
|
+
const params = [...setParams, ...whereParams];
|
|
310
|
+
return { sql, params };
|
|
311
|
+
}
|
|
312
|
+
async execute() {
|
|
296
313
|
const { sql, params } = this.build();
|
|
297
314
|
const result = await this.db.execute(sql, params);
|
|
298
315
|
return result.rowsAffected;
|
package/dist/index.mjs
CHANGED
|
@@ -231,18 +231,35 @@ var UpdateQueryBuilder = class extends BaseQueryBuilder {
|
|
|
231
231
|
this.updateData = { ...this.updateData, ...data };
|
|
232
232
|
return this;
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
build() {
|
|
235
|
+
const baseQuery = this.query;
|
|
236
|
+
const whereParams = this.params;
|
|
237
|
+
let tablePart = baseQuery;
|
|
238
|
+
let whereClause = "";
|
|
239
|
+
const whereIndex = baseQuery.indexOf(" WHERE ");
|
|
240
|
+
if (whereIndex !== -1) {
|
|
241
|
+
tablePart = baseQuery.substring(0, whereIndex);
|
|
242
|
+
whereClause = baseQuery.substring(whereIndex);
|
|
243
|
+
}
|
|
235
244
|
const entries = Object.entries(this.updateData);
|
|
245
|
+
if (entries.length === 0) {
|
|
246
|
+
throw new Error("Cannot execute an update query without a .set() call.");
|
|
247
|
+
}
|
|
236
248
|
const setClause = entries.map(([key]) => {
|
|
237
249
|
const column = this.table._.columns[key];
|
|
238
|
-
if (!column)
|
|
250
|
+
if (!column) {
|
|
239
251
|
throw new Error(
|
|
240
252
|
`Column ${key} does not exist on table ${this.table._.name}`
|
|
241
253
|
);
|
|
254
|
+
}
|
|
242
255
|
return `${column._.name} = ?`;
|
|
243
256
|
}).join(", ");
|
|
244
|
-
|
|
245
|
-
|
|
257
|
+
const setParams = entries.map(([, value]) => value);
|
|
258
|
+
const sql = `${tablePart} SET ${setClause}${whereClause}`;
|
|
259
|
+
const params = [...setParams, ...whereParams];
|
|
260
|
+
return { sql, params };
|
|
261
|
+
}
|
|
262
|
+
async execute() {
|
|
246
263
|
const { sql, params } = this.build();
|
|
247
264
|
const result = await this.db.execute(sql, params);
|
|
248
265
|
return result.rowsAffected;
|