evikit 2.6.1 → 2.7.1
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/package.json +1 -1
- package/server.js +4 -2
- package/sqlite.js +16 -14
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -207,9 +207,11 @@ export function json(output) {
|
|
|
207
207
|
|
|
208
208
|
/** @param {{ listen: (port: number, callback: () => void) => { close(): void, on(event: "error", callback: (error: unknown) => void ): void } }} app */
|
|
209
209
|
export function listen(app) {
|
|
210
|
+
const parallelism =
|
|
211
|
+
Number(process.env["PARALLELISM"]) || availableParallelism();
|
|
210
212
|
const port = Number(process.env["PORT"]) || 5173;
|
|
211
|
-
if (cluster.isPrimary &&
|
|
212
|
-
for (let i = 0; i <
|
|
213
|
+
if (cluster.isPrimary && parallelism > 1) {
|
|
214
|
+
for (let i = 0; i < parallelism; i++) {
|
|
213
215
|
cluster.fork({ i });
|
|
214
216
|
}
|
|
215
217
|
} else {
|
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
|
-
|
|
373
|
+
upsert.run(...values, ...values);
|
|
372
374
|
outputs.push(output);
|
|
373
375
|
}
|
|
374
376
|
return outputs;
|