evikit 2.6.0 → 2.7.0

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.
Files changed (3) hide show
  1. package/db.d.ts +1 -2
  2. package/package.json +1 -1
  3. package/sqlite.js +16 -14
package/db.d.ts CHANGED
@@ -27,8 +27,7 @@ export type Db<
27
27
  | InferOutput<Schema[Table]["entries"][K]>
28
28
  | InferOutput<Schema[Table]["entries"][K]>[];
29
29
  };
30
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
31
- } = { with: {} },
30
+ },
32
31
  >(
33
32
  props?: W,
34
33
  ): Select<Schema, R, F, Table, W>[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "evikit",
3
3
  "description": "Preact/SQLite SSR framework for small web apps",
4
- "version": "2.6.0",
4
+ "version": "2.7.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./index.js",
package/sqlite.js CHANGED
@@ -26,6 +26,7 @@ export function sqlite({ pkg, schema }) {
26
26
  const database = new DatabaseSync(data ? `${data}/db.sqlite3` : ":memory:", {
27
27
  timeout: 1000,
28
28
  });
29
+ database.prepare("pragma journal_mode=wal").run();
29
30
  const flat = flatten(relations(schema));
30
31
 
31
32
  const haveTables = /** @type {{ name: string }[]} */ (
@@ -290,6 +291,20 @@ export function sqlite({ pkg, schema }) {
290
291
  }
291
292
  }
292
293
 
294
+ ok(schema[table]);
295
+ const columns = Object.entries(schema[table].entries);
296
+ const primaryKey = columns.find(
297
+ ([, column]) =>
298
+ /** @type {{ primary?: true }} */ (getMetadata(column)).primary,
299
+ );
300
+ ok(primaryKey);
301
+ const upsert = database.prepare(
302
+ `insert into ${table} (${columns.map(([name]) => name).join(", ")}) values\n` +
303
+ `(${columns.map(() => "?").join(", ")})\n` +
304
+ `on conflict (${primaryKey[0]}) do update set\n` +
305
+ columns.map(([name]) => `${name} = ?`).join(",\n"),
306
+ );
307
+
293
308
  return [
294
309
  table,
295
310
  {
@@ -351,24 +366,11 @@ export function sqlite({ pkg, schema }) {
351
366
  /** @param {any[]} values */
352
367
  upsert(...values) {
353
368
  ok(schema[table]);
354
- const columns = Object.entries(schema[table].entries);
355
- const primaryKey = columns.find(
356
- ([, column]) =>
357
- /** @type {{ primary?: true }} */ (getMetadata(column))
358
- .primary,
359
- );
360
- ok(primaryKey);
361
- const query = database.prepare(
362
- `insert into ${table} (${columns.map(([name]) => name).join(", ")}) values\n` +
363
- `(${columns.map(() => "?").join(", ")})\n` +
364
- `on conflict (${primaryKey[0]}) do update set\n` +
365
- columns.map(([name]) => `${name} = ?`).join(",\n"),
366
- );
367
369
  const outputs = [];
368
370
  for (const row of values) {
369
371
  const output = parse(schema[table], row);
370
372
  const values = columns.map(([name]) => output[name] ?? null);
371
- query.run(...values, ...values);
373
+ upsert.run(...values, ...values);
372
374
  outputs.push(output);
373
375
  }
374
376
  return outputs;