@starkeep/storage-sqlite 0.8.0 → 0.9.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.
- package/dist/{adapter-DoVOV6K-.d.cts → adapter-Cm4K6kmH.d.cts} +8 -1
- package/dist/{adapter-DoVOV6K-.d.ts → adapter-Cm4K6kmH.d.ts} +8 -1
- package/dist/index.cjs +22 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -6
- package/dist/index.js.map +1 -1
- package/dist/node-entry.d.cts +1 -1
- package/dist/node-entry.d.ts +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { S as SqliteDatabaseAdapter, a as SqliteDatabaseAdapterOptions, b as SqliteDriver } from './adapter-
|
|
1
|
+
export { S as SqliteDatabaseAdapter, a as SqliteDatabaseAdapterOptions, b as SqliteDriver } from './adapter-Cm4K6kmH.cjs';
|
|
2
2
|
import { Kysely } from 'kysely';
|
|
3
3
|
import { RawDatabase, DigestBucket, ParsedQuery, BuildOptions, ParsedQueryResult } from '@starkeep/storage-adapter';
|
|
4
4
|
import { AppSyncableNamespaceStore, AppSyncableNamespace, AppSyncableTableInfo, AppSyncableApplier, ScanCapableApplier, AppSyncableRowEntry, AppSyncableWriteConditions, AppSyncableApplyOutcome, ScanSincePage, DeclaredColumn } from '@starkeep/shared-space-api';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { S as SqliteDatabaseAdapter, a as SqliteDatabaseAdapterOptions, b as SqliteDriver } from './adapter-
|
|
1
|
+
export { S as SqliteDatabaseAdapter, a as SqliteDatabaseAdapterOptions, b as SqliteDriver } from './adapter-Cm4K6kmH.js';
|
|
2
2
|
import { Kysely } from 'kysely';
|
|
3
3
|
import { RawDatabase, DigestBucket, ParsedQuery, BuildOptions, ParsedQueryResult } from '@starkeep/storage-adapter';
|
|
4
4
|
import { AppSyncableNamespaceStore, AppSyncableNamespace, AppSyncableTableInfo, AppSyncableApplier, ScanCapableApplier, AppSyncableRowEntry, AppSyncableWriteConditions, AppSyncableApplyOutcome, ScanSincePage, DeclaredColumn } from '@starkeep/shared-space-api';
|
package/dist/index.js
CHANGED
|
@@ -383,16 +383,32 @@ var SqliteDatabaseAdapter = class {
|
|
|
383
383
|
return this.getDatabase().prepare(sql5).all(...params.map(toSqliteParam));
|
|
384
384
|
}
|
|
385
385
|
async put(record) {
|
|
386
|
+
this.upsertRecord(record, false);
|
|
387
|
+
}
|
|
388
|
+
async putSnapshot(record) {
|
|
389
|
+
return this.upsertRecord(record, true);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* One upsert statement. With `onlyIfNewer` an existing row is replaced only
|
|
393
|
+
* by a strictly later `updated_at` (see `DatabaseAdapter.putSnapshot`), and
|
|
394
|
+
* the result says whether a row was written.
|
|
395
|
+
*/
|
|
396
|
+
upsertRecord(record, onlyIfNewer) {
|
|
386
397
|
const row = recordToRow(record);
|
|
387
398
|
const updateColumns = Object.keys(row).filter((column) => column !== "id");
|
|
388
|
-
const query = compiler.insertInto("shared_records").values({ ...row }).onConflict(
|
|
389
|
-
|
|
399
|
+
const query = compiler.insertInto("shared_records").values({ ...row }).onConflict((oc) => {
|
|
400
|
+
const update = oc.column("id").doUpdateSet(
|
|
390
401
|
(eb) => Object.fromEntries(
|
|
391
402
|
updateColumns.map((column) => [column, eb.ref(`excluded.${column}`)])
|
|
392
403
|
)
|
|
393
|
-
)
|
|
394
|
-
|
|
395
|
-
|
|
404
|
+
);
|
|
405
|
+
return onlyIfNewer ? update.where(
|
|
406
|
+
kSql.ref("excluded.updated_at"),
|
|
407
|
+
">",
|
|
408
|
+
kSql.ref("shared_records.updated_at")
|
|
409
|
+
) : update;
|
|
410
|
+
}).returning("id").compile();
|
|
411
|
+
return this.allRows(query.sql, ...query.parameters).length > 0;
|
|
396
412
|
}
|
|
397
413
|
async get(id) {
|
|
398
414
|
const query = compiler.selectFrom("shared_records").selectAll().where("id", "=", id).compile();
|
|
@@ -656,7 +672,7 @@ var SqliteDatabaseAdapter = class {
|
|
|
656
672
|
// ---- Label sync ---------------------------------------------------------
|
|
657
673
|
async putLabel(label) {
|
|
658
674
|
const query = buildLabelSnapshotUpsert(compiler, LABELS, label);
|
|
659
|
-
this.
|
|
675
|
+
return this.allRows(query.sql, ...query.parameters).length > 0;
|
|
660
676
|
}
|
|
661
677
|
async getLabel(recordId, appId, key, value) {
|
|
662
678
|
const query = buildGetLabel(compiler, LABELS, recordId, appId, key, value);
|