@qilin-agent/storage-sqlite 3.1.6 → 3.1.8

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 (2) hide show
  1. package/lib/index.js +4 -1
  2. package/package.json +6 -6
package/lib/index.js CHANGED
@@ -124,7 +124,8 @@ var SqliteKvUnit = class {
124
124
  this.tables.set(table, {
125
125
  upsert: db.prepare(`INSERT INTO "${physical}" (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`),
126
126
  remove: db.prepare(`DELETE FROM "${physical}" WHERE key = ?`),
127
- selectAll: db.prepare(`SELECT key, value FROM "${physical}"`)
127
+ selectAll: db.prepare(`SELECT key, value FROM "${physical}"`),
128
+ ...descriptor.retention === void 0 ? {} : { trim: db.prepare(`DELETE FROM "${physical}" WHERE rowid NOT IN (SELECT rowid FROM "${physical}" ORDER BY rowid DESC LIMIT ?)`) }
128
129
  });
129
130
  }
130
131
  this.globalUpsert = descriptor.hasGlobal ? db.prepare("INSERT INTO unit_globals (unit, value) VALUES (?, ?) ON CONFLICT(unit) DO UPDATE SET value = excluded.value") : void 0;
@@ -133,7 +134,9 @@ var SqliteKvUnit = class {
133
134
  loadAll() {
134
135
  return this.settle(() => {
135
136
  const tables = {};
137
+ const retention = this.descriptor.retention;
136
138
  for (const [name, statements] of this.tables) {
139
+ if (retention !== void 0) statements.trim?.run(retention.maxRecords);
137
140
  const records = Object.create(null);
138
141
  for (const row of statements.selectAll.all()) records[row.key] = this.parseValue(row.value, `table '${name}' key '${row.key}'`);
139
142
  tables[name] = records;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qilin-agent/storage-sqlite",
3
3
  "description": "SQLite storage backend (kv facet) for the QiLin storage hub",
4
- "version": "3.1.6",
4
+ "version": "3.1.8",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -30,14 +30,14 @@
30
30
  ],
31
31
  "license": "MIT",
32
32
  "peerDependencies": {
33
- "@qilin-agent/storage": "3.1.6",
34
- "@qilin-agent/kylin": "~4.0.5"
33
+ "@qilin-agent/storage": "3.1.8",
34
+ "@qilin-agent/kylin": "~4.0.6-alpha.2"
35
35
  },
36
36
  "dependencies": {
37
- "@qilin-agent/schemastery": "~3.18.5"
37
+ "@qilin-agent/schemastery": "~3.18.6-alpha.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@qilin-agent/storage": "3.1.6",
41
- "@qilin-agent/kylin": "~4.0.5"
40
+ "@qilin-agent/storage": "3.1.8",
41
+ "@qilin-agent/kylin": "~4.0.6-alpha.2"
42
42
  }
43
43
  }