latticesql 1.6.9 → 1.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.
- package/README.md +11 -9
- package/dist/cli.js +35 -17
- package/dist/index.cjs +29 -17
- package/dist/index.js +36 -17
- package/dist/postgres-worker.cjs +36 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -2127,14 +2127,14 @@ Lattice ships with two storage adapters and a pluggable interface so you can bri
|
|
|
2127
2127
|
|
|
2128
2128
|
The `Lattice` constructor inspects the first argument and picks the right adapter:
|
|
2129
2129
|
|
|
2130
|
-
| First argument
|
|
2131
|
-
|
|
2132
|
-
| `'/abs/path/to/db.sqlite'` (or any plain path) | `SQLiteAdapter`
|
|
2133
|
-
| `':memory:'`
|
|
2134
|
-
| `'file:/abs/path/to/db.sqlite'`
|
|
2135
|
-
| `'postgres://user:pass@host:5432/db'`
|
|
2136
|
-
| `'postgresql://user:pass@host:5432/db'`
|
|
2137
|
-
| any string + `{ adapter: myAdapter }`
|
|
2130
|
+
| First argument | Adapter | When to use |
|
|
2131
|
+
| ---------------------------------------------- | ----------------- | --------------------------------------------------------- |
|
|
2132
|
+
| `'/abs/path/to/db.sqlite'` (or any plain path) | `SQLiteAdapter` | Default. Local file, no server. |
|
|
2133
|
+
| `':memory:'` | `SQLiteAdapter` | In-memory SQLite. Great for tests. |
|
|
2134
|
+
| `'file:/abs/path/to/db.sqlite'` | `SQLiteAdapter` | Same as the plain path form, with the scheme spelled out. |
|
|
2135
|
+
| `'postgres://user:pass@host:5432/db'` | `PostgresAdapter` | Postgres-compatible cloud DB (Supabase, Neon, RDS, …). |
|
|
2136
|
+
| `'postgresql://user:pass@host:5432/db'` | `PostgresAdapter` | Same as `postgres://`. |
|
|
2137
|
+
| any string + `{ adapter: myAdapter }` | your adapter | Bring your own implementation. |
|
|
2138
2138
|
|
|
2139
2139
|
```ts
|
|
2140
2140
|
import { Lattice } from 'latticesql';
|
|
@@ -2200,7 +2200,9 @@ Pass your implementation via `options.adapter`:
|
|
|
2200
2200
|
import { Lattice } from 'latticesql';
|
|
2201
2201
|
import type { StorageAdapter } from 'latticesql';
|
|
2202
2202
|
|
|
2203
|
-
class MyMySQLAdapter implements StorageAdapter {
|
|
2203
|
+
class MyMySQLAdapter implements StorageAdapter {
|
|
2204
|
+
/* … */
|
|
2205
|
+
}
|
|
2204
2206
|
|
|
2205
2207
|
const lattice = new Lattice('ignored', { adapter: new MyMySQLAdapter() });
|
|
2206
2208
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
2
8
|
|
|
3
9
|
// src/cli.ts
|
|
4
10
|
import { resolve as resolve4, dirname as dirname5 } from "path";
|
|
@@ -467,9 +473,20 @@ var SQLiteAdapter = class {
|
|
|
467
473
|
import path from "path";
|
|
468
474
|
import { fileURLToPath } from "url";
|
|
469
475
|
import { createRequire } from "module";
|
|
470
|
-
var
|
|
471
|
-
|
|
472
|
-
|
|
476
|
+
var _moduleContext = null;
|
|
477
|
+
function moduleContext() {
|
|
478
|
+
if (_moduleContext) return _moduleContext;
|
|
479
|
+
const importMetaUrl = import.meta.url;
|
|
480
|
+
if (importMetaUrl) {
|
|
481
|
+
_moduleContext = {
|
|
482
|
+
dir: path.dirname(fileURLToPath(importMetaUrl)),
|
|
483
|
+
require: createRequire(importMetaUrl)
|
|
484
|
+
};
|
|
485
|
+
} else {
|
|
486
|
+
_moduleContext = { dir: __dirname, require: __require };
|
|
487
|
+
}
|
|
488
|
+
return _moduleContext;
|
|
489
|
+
}
|
|
473
490
|
var PostgresAdapter = class {
|
|
474
491
|
_connectionString;
|
|
475
492
|
_workerPath;
|
|
@@ -477,20 +494,21 @@ var PostgresAdapter = class {
|
|
|
477
494
|
_opened = false;
|
|
478
495
|
constructor(connectionString, options = {}) {
|
|
479
496
|
this._connectionString = connectionString;
|
|
480
|
-
this._workerPath = options.workerPath ?? path.join(
|
|
497
|
+
this._workerPath = options.workerPath ?? path.join(moduleContext().dir, "postgres-worker.cjs");
|
|
481
498
|
}
|
|
482
499
|
open() {
|
|
483
500
|
if (this._opened) return;
|
|
501
|
+
const ctxRequire = moduleContext().require;
|
|
484
502
|
let createSyncFn;
|
|
485
503
|
try {
|
|
486
|
-
({ createSyncFn } =
|
|
504
|
+
({ createSyncFn } = ctxRequire("synckit"));
|
|
487
505
|
} catch (err) {
|
|
488
506
|
throw new Error(
|
|
489
507
|
"PostgresAdapter requires 'synckit'. Install with: npm install synckit\nUnderlying error: " + (err instanceof Error ? err.message : String(err))
|
|
490
508
|
);
|
|
491
509
|
}
|
|
492
510
|
try {
|
|
493
|
-
|
|
511
|
+
ctxRequire("pg");
|
|
494
512
|
} catch (err) {
|
|
495
513
|
throw new Error(
|
|
496
514
|
"PostgresAdapter requires 'pg'. Install with: npm install pg\nUnderlying error: " + (err instanceof Error ? err.message : String(err))
|
|
@@ -558,7 +576,7 @@ function translateDialect(sql) {
|
|
|
558
576
|
}
|
|
559
577
|
let hadInsertOrIgnore = false;
|
|
560
578
|
let s = mapCodeRegions(sql, (code) => {
|
|
561
|
-
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1
|
|
579
|
+
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1) => {
|
|
562
580
|
hadInsertOrIgnore = true;
|
|
563
581
|
return `INSERT${w1}INTO`;
|
|
564
582
|
});
|
|
@@ -568,7 +586,7 @@ function translateDialect(sql) {
|
|
|
568
586
|
}
|
|
569
587
|
s = mapCodeRegions(
|
|
570
588
|
s,
|
|
571
|
-
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1
|
|
589
|
+
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1) => {
|
|
572
590
|
return `CREATE${w1}OR REPLACE VIEW`;
|
|
573
591
|
})
|
|
574
592
|
);
|
|
@@ -610,7 +628,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
610
628
|
i += 2;
|
|
611
629
|
continue;
|
|
612
630
|
}
|
|
613
|
-
out += sql
|
|
631
|
+
out += sql.charAt(i);
|
|
614
632
|
if (sql[i] === "'") {
|
|
615
633
|
i++;
|
|
616
634
|
break;
|
|
@@ -625,7 +643,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
625
643
|
out += '"';
|
|
626
644
|
i++;
|
|
627
645
|
while (i < sql.length) {
|
|
628
|
-
out += sql
|
|
646
|
+
out += sql.charAt(i);
|
|
629
647
|
if (sql[i] === '"') {
|
|
630
648
|
i++;
|
|
631
649
|
break;
|
|
@@ -638,7 +656,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
638
656
|
if (ch === "-" && sql[i + 1] === "-") {
|
|
639
657
|
flushCode(i);
|
|
640
658
|
while (i < sql.length && sql[i] !== "\n") {
|
|
641
|
-
out += sql
|
|
659
|
+
out += sql.charAt(i);
|
|
642
660
|
i++;
|
|
643
661
|
}
|
|
644
662
|
codeStart = i;
|
|
@@ -649,7 +667,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
649
667
|
out += "/*";
|
|
650
668
|
i += 2;
|
|
651
669
|
while (i < sql.length && !(sql[i] === "*" && sql[i + 1] === "/")) {
|
|
652
|
-
out += sql
|
|
670
|
+
out += sql.charAt(i);
|
|
653
671
|
i++;
|
|
654
672
|
}
|
|
655
673
|
if (i < sql.length) {
|
|
@@ -723,7 +741,7 @@ function rewriteParams(sql) {
|
|
|
723
741
|
i += 2;
|
|
724
742
|
continue;
|
|
725
743
|
}
|
|
726
|
-
out += sql
|
|
744
|
+
out += sql.charAt(i);
|
|
727
745
|
if (sql[i] === "'") {
|
|
728
746
|
i++;
|
|
729
747
|
break;
|
|
@@ -736,7 +754,7 @@ function rewriteParams(sql) {
|
|
|
736
754
|
out += ch;
|
|
737
755
|
i++;
|
|
738
756
|
while (i < sql.length) {
|
|
739
|
-
out += sql
|
|
757
|
+
out += sql.charAt(i);
|
|
740
758
|
if (sql[i] === '"') {
|
|
741
759
|
i++;
|
|
742
760
|
break;
|
|
@@ -747,7 +765,7 @@ function rewriteParams(sql) {
|
|
|
747
765
|
}
|
|
748
766
|
if (ch === "-" && sql[i + 1] === "-") {
|
|
749
767
|
while (i < sql.length && sql[i] !== "\n") {
|
|
750
|
-
out += sql
|
|
768
|
+
out += sql.charAt(i);
|
|
751
769
|
i++;
|
|
752
770
|
}
|
|
753
771
|
continue;
|
|
@@ -756,7 +774,7 @@ function rewriteParams(sql) {
|
|
|
756
774
|
out += "/*";
|
|
757
775
|
i += 2;
|
|
758
776
|
while (i < sql.length && !(sql[i] === "*" && sql[i + 1] === "/")) {
|
|
759
|
-
out += sql
|
|
777
|
+
out += sql.charAt(i);
|
|
760
778
|
i++;
|
|
761
779
|
}
|
|
762
780
|
if (i < sql.length) {
|
|
@@ -770,7 +788,7 @@ function rewriteParams(sql) {
|
|
|
770
788
|
i++;
|
|
771
789
|
continue;
|
|
772
790
|
}
|
|
773
|
-
out += ch;
|
|
791
|
+
out += ch ?? "";
|
|
774
792
|
i++;
|
|
775
793
|
}
|
|
776
794
|
return out;
|
package/dist/index.cjs
CHANGED
|
@@ -217,9 +217,20 @@ var import_node_path3 = __toESM(require("path"), 1);
|
|
|
217
217
|
var import_node_url = require("url");
|
|
218
218
|
var import_node_module = require("module");
|
|
219
219
|
var import_meta = {};
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
var _moduleContext = null;
|
|
221
|
+
function moduleContext() {
|
|
222
|
+
if (_moduleContext) return _moduleContext;
|
|
223
|
+
const importMetaUrl = import_meta.url;
|
|
224
|
+
if (importMetaUrl) {
|
|
225
|
+
_moduleContext = {
|
|
226
|
+
dir: import_node_path3.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl)),
|
|
227
|
+
require: (0, import_node_module.createRequire)(importMetaUrl)
|
|
228
|
+
};
|
|
229
|
+
} else {
|
|
230
|
+
_moduleContext = { dir: __dirname, require };
|
|
231
|
+
}
|
|
232
|
+
return _moduleContext;
|
|
233
|
+
}
|
|
223
234
|
var PostgresAdapter = class {
|
|
224
235
|
_connectionString;
|
|
225
236
|
_workerPath;
|
|
@@ -227,20 +238,21 @@ var PostgresAdapter = class {
|
|
|
227
238
|
_opened = false;
|
|
228
239
|
constructor(connectionString, options = {}) {
|
|
229
240
|
this._connectionString = connectionString;
|
|
230
|
-
this._workerPath = options.workerPath ?? import_node_path3.default.join(
|
|
241
|
+
this._workerPath = options.workerPath ?? import_node_path3.default.join(moduleContext().dir, "postgres-worker.cjs");
|
|
231
242
|
}
|
|
232
243
|
open() {
|
|
233
244
|
if (this._opened) return;
|
|
245
|
+
const ctxRequire = moduleContext().require;
|
|
234
246
|
let createSyncFn;
|
|
235
247
|
try {
|
|
236
|
-
({ createSyncFn } =
|
|
248
|
+
({ createSyncFn } = ctxRequire("synckit"));
|
|
237
249
|
} catch (err) {
|
|
238
250
|
throw new Error(
|
|
239
251
|
"PostgresAdapter requires 'synckit'. Install with: npm install synckit\nUnderlying error: " + (err instanceof Error ? err.message : String(err))
|
|
240
252
|
);
|
|
241
253
|
}
|
|
242
254
|
try {
|
|
243
|
-
|
|
255
|
+
ctxRequire("pg");
|
|
244
256
|
} catch (err) {
|
|
245
257
|
throw new Error(
|
|
246
258
|
"PostgresAdapter requires 'pg'. Install with: npm install pg\nUnderlying error: " + (err instanceof Error ? err.message : String(err))
|
|
@@ -308,7 +320,7 @@ function translateDialect(sql) {
|
|
|
308
320
|
}
|
|
309
321
|
let hadInsertOrIgnore = false;
|
|
310
322
|
let s = mapCodeRegions(sql, (code) => {
|
|
311
|
-
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1
|
|
323
|
+
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1) => {
|
|
312
324
|
hadInsertOrIgnore = true;
|
|
313
325
|
return `INSERT${w1}INTO`;
|
|
314
326
|
});
|
|
@@ -318,7 +330,7 @@ function translateDialect(sql) {
|
|
|
318
330
|
}
|
|
319
331
|
s = mapCodeRegions(
|
|
320
332
|
s,
|
|
321
|
-
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1
|
|
333
|
+
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1) => {
|
|
322
334
|
return `CREATE${w1}OR REPLACE VIEW`;
|
|
323
335
|
})
|
|
324
336
|
);
|
|
@@ -360,7 +372,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
360
372
|
i += 2;
|
|
361
373
|
continue;
|
|
362
374
|
}
|
|
363
|
-
out += sql
|
|
375
|
+
out += sql.charAt(i);
|
|
364
376
|
if (sql[i] === "'") {
|
|
365
377
|
i++;
|
|
366
378
|
break;
|
|
@@ -375,7 +387,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
375
387
|
out += '"';
|
|
376
388
|
i++;
|
|
377
389
|
while (i < sql.length) {
|
|
378
|
-
out += sql
|
|
390
|
+
out += sql.charAt(i);
|
|
379
391
|
if (sql[i] === '"') {
|
|
380
392
|
i++;
|
|
381
393
|
break;
|
|
@@ -388,7 +400,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
388
400
|
if (ch === "-" && sql[i + 1] === "-") {
|
|
389
401
|
flushCode(i);
|
|
390
402
|
while (i < sql.length && sql[i] !== "\n") {
|
|
391
|
-
out += sql
|
|
403
|
+
out += sql.charAt(i);
|
|
392
404
|
i++;
|
|
393
405
|
}
|
|
394
406
|
codeStart = i;
|
|
@@ -399,7 +411,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
399
411
|
out += "/*";
|
|
400
412
|
i += 2;
|
|
401
413
|
while (i < sql.length && !(sql[i] === "*" && sql[i + 1] === "/")) {
|
|
402
|
-
out += sql
|
|
414
|
+
out += sql.charAt(i);
|
|
403
415
|
i++;
|
|
404
416
|
}
|
|
405
417
|
if (i < sql.length) {
|
|
@@ -473,7 +485,7 @@ function rewriteParams(sql) {
|
|
|
473
485
|
i += 2;
|
|
474
486
|
continue;
|
|
475
487
|
}
|
|
476
|
-
out += sql
|
|
488
|
+
out += sql.charAt(i);
|
|
477
489
|
if (sql[i] === "'") {
|
|
478
490
|
i++;
|
|
479
491
|
break;
|
|
@@ -486,7 +498,7 @@ function rewriteParams(sql) {
|
|
|
486
498
|
out += ch;
|
|
487
499
|
i++;
|
|
488
500
|
while (i < sql.length) {
|
|
489
|
-
out += sql
|
|
501
|
+
out += sql.charAt(i);
|
|
490
502
|
if (sql[i] === '"') {
|
|
491
503
|
i++;
|
|
492
504
|
break;
|
|
@@ -497,7 +509,7 @@ function rewriteParams(sql) {
|
|
|
497
509
|
}
|
|
498
510
|
if (ch === "-" && sql[i + 1] === "-") {
|
|
499
511
|
while (i < sql.length && sql[i] !== "\n") {
|
|
500
|
-
out += sql
|
|
512
|
+
out += sql.charAt(i);
|
|
501
513
|
i++;
|
|
502
514
|
}
|
|
503
515
|
continue;
|
|
@@ -506,7 +518,7 @@ function rewriteParams(sql) {
|
|
|
506
518
|
out += "/*";
|
|
507
519
|
i += 2;
|
|
508
520
|
while (i < sql.length && !(sql[i] === "*" && sql[i + 1] === "/")) {
|
|
509
|
-
out += sql
|
|
521
|
+
out += sql.charAt(i);
|
|
510
522
|
i++;
|
|
511
523
|
}
|
|
512
524
|
if (i < sql.length) {
|
|
@@ -520,7 +532,7 @@ function rewriteParams(sql) {
|
|
|
520
532
|
i++;
|
|
521
533
|
continue;
|
|
522
534
|
}
|
|
523
|
-
out += ch;
|
|
535
|
+
out += ch ?? "";
|
|
524
536
|
i++;
|
|
525
537
|
}
|
|
526
538
|
return out;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/lattice.ts
|
|
2
9
|
import { v4 as uuidv4 } from "uuid";
|
|
3
10
|
|
|
@@ -152,9 +159,20 @@ var SQLiteAdapter = class {
|
|
|
152
159
|
import path from "path";
|
|
153
160
|
import { fileURLToPath } from "url";
|
|
154
161
|
import { createRequire } from "module";
|
|
155
|
-
var
|
|
156
|
-
|
|
157
|
-
|
|
162
|
+
var _moduleContext = null;
|
|
163
|
+
function moduleContext() {
|
|
164
|
+
if (_moduleContext) return _moduleContext;
|
|
165
|
+
const importMetaUrl = import.meta.url;
|
|
166
|
+
if (importMetaUrl) {
|
|
167
|
+
_moduleContext = {
|
|
168
|
+
dir: path.dirname(fileURLToPath(importMetaUrl)),
|
|
169
|
+
require: createRequire(importMetaUrl)
|
|
170
|
+
};
|
|
171
|
+
} else {
|
|
172
|
+
_moduleContext = { dir: __dirname, require: __require };
|
|
173
|
+
}
|
|
174
|
+
return _moduleContext;
|
|
175
|
+
}
|
|
158
176
|
var PostgresAdapter = class {
|
|
159
177
|
_connectionString;
|
|
160
178
|
_workerPath;
|
|
@@ -162,20 +180,21 @@ var PostgresAdapter = class {
|
|
|
162
180
|
_opened = false;
|
|
163
181
|
constructor(connectionString, options = {}) {
|
|
164
182
|
this._connectionString = connectionString;
|
|
165
|
-
this._workerPath = options.workerPath ?? path.join(
|
|
183
|
+
this._workerPath = options.workerPath ?? path.join(moduleContext().dir, "postgres-worker.cjs");
|
|
166
184
|
}
|
|
167
185
|
open() {
|
|
168
186
|
if (this._opened) return;
|
|
187
|
+
const ctxRequire = moduleContext().require;
|
|
169
188
|
let createSyncFn;
|
|
170
189
|
try {
|
|
171
|
-
({ createSyncFn } =
|
|
190
|
+
({ createSyncFn } = ctxRequire("synckit"));
|
|
172
191
|
} catch (err) {
|
|
173
192
|
throw new Error(
|
|
174
193
|
"PostgresAdapter requires 'synckit'. Install with: npm install synckit\nUnderlying error: " + (err instanceof Error ? err.message : String(err))
|
|
175
194
|
);
|
|
176
195
|
}
|
|
177
196
|
try {
|
|
178
|
-
|
|
197
|
+
ctxRequire("pg");
|
|
179
198
|
} catch (err) {
|
|
180
199
|
throw new Error(
|
|
181
200
|
"PostgresAdapter requires 'pg'. Install with: npm install pg\nUnderlying error: " + (err instanceof Error ? err.message : String(err))
|
|
@@ -243,7 +262,7 @@ function translateDialect(sql) {
|
|
|
243
262
|
}
|
|
244
263
|
let hadInsertOrIgnore = false;
|
|
245
264
|
let s = mapCodeRegions(sql, (code) => {
|
|
246
|
-
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1
|
|
265
|
+
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1) => {
|
|
247
266
|
hadInsertOrIgnore = true;
|
|
248
267
|
return `INSERT${w1}INTO`;
|
|
249
268
|
});
|
|
@@ -253,7 +272,7 @@ function translateDialect(sql) {
|
|
|
253
272
|
}
|
|
254
273
|
s = mapCodeRegions(
|
|
255
274
|
s,
|
|
256
|
-
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1
|
|
275
|
+
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1) => {
|
|
257
276
|
return `CREATE${w1}OR REPLACE VIEW`;
|
|
258
277
|
})
|
|
259
278
|
);
|
|
@@ -295,7 +314,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
295
314
|
i += 2;
|
|
296
315
|
continue;
|
|
297
316
|
}
|
|
298
|
-
out += sql
|
|
317
|
+
out += sql.charAt(i);
|
|
299
318
|
if (sql[i] === "'") {
|
|
300
319
|
i++;
|
|
301
320
|
break;
|
|
@@ -310,7 +329,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
310
329
|
out += '"';
|
|
311
330
|
i++;
|
|
312
331
|
while (i < sql.length) {
|
|
313
|
-
out += sql
|
|
332
|
+
out += sql.charAt(i);
|
|
314
333
|
if (sql[i] === '"') {
|
|
315
334
|
i++;
|
|
316
335
|
break;
|
|
@@ -323,7 +342,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
323
342
|
if (ch === "-" && sql[i + 1] === "-") {
|
|
324
343
|
flushCode(i);
|
|
325
344
|
while (i < sql.length && sql[i] !== "\n") {
|
|
326
|
-
out += sql
|
|
345
|
+
out += sql.charAt(i);
|
|
327
346
|
i++;
|
|
328
347
|
}
|
|
329
348
|
codeStart = i;
|
|
@@ -334,7 +353,7 @@ function mapCodeRegions(sql, xform) {
|
|
|
334
353
|
out += "/*";
|
|
335
354
|
i += 2;
|
|
336
355
|
while (i < sql.length && !(sql[i] === "*" && sql[i + 1] === "/")) {
|
|
337
|
-
out += sql
|
|
356
|
+
out += sql.charAt(i);
|
|
338
357
|
i++;
|
|
339
358
|
}
|
|
340
359
|
if (i < sql.length) {
|
|
@@ -408,7 +427,7 @@ function rewriteParams(sql) {
|
|
|
408
427
|
i += 2;
|
|
409
428
|
continue;
|
|
410
429
|
}
|
|
411
|
-
out += sql
|
|
430
|
+
out += sql.charAt(i);
|
|
412
431
|
if (sql[i] === "'") {
|
|
413
432
|
i++;
|
|
414
433
|
break;
|
|
@@ -421,7 +440,7 @@ function rewriteParams(sql) {
|
|
|
421
440
|
out += ch;
|
|
422
441
|
i++;
|
|
423
442
|
while (i < sql.length) {
|
|
424
|
-
out += sql
|
|
443
|
+
out += sql.charAt(i);
|
|
425
444
|
if (sql[i] === '"') {
|
|
426
445
|
i++;
|
|
427
446
|
break;
|
|
@@ -432,7 +451,7 @@ function rewriteParams(sql) {
|
|
|
432
451
|
}
|
|
433
452
|
if (ch === "-" && sql[i + 1] === "-") {
|
|
434
453
|
while (i < sql.length && sql[i] !== "\n") {
|
|
435
|
-
out += sql
|
|
454
|
+
out += sql.charAt(i);
|
|
436
455
|
i++;
|
|
437
456
|
}
|
|
438
457
|
continue;
|
|
@@ -441,7 +460,7 @@ function rewriteParams(sql) {
|
|
|
441
460
|
out += "/*";
|
|
442
461
|
i += 2;
|
|
443
462
|
while (i < sql.length && !(sql[i] === "*" && sql[i + 1] === "/")) {
|
|
444
|
-
out += sql
|
|
463
|
+
out += sql.charAt(i);
|
|
445
464
|
i++;
|
|
446
465
|
}
|
|
447
466
|
if (i < sql.length) {
|
|
@@ -455,7 +474,7 @@ function rewriteParams(sql) {
|
|
|
455
474
|
i++;
|
|
456
475
|
continue;
|
|
457
476
|
}
|
|
458
|
-
out += ch;
|
|
477
|
+
out += ch ?? "";
|
|
459
478
|
i++;
|
|
460
479
|
}
|
|
461
480
|
return out;
|
package/dist/postgres-worker.cjs
CHANGED
|
@@ -39,6 +39,42 @@ function ensureClient() {
|
|
|
39
39
|
jeErr instanceof Error ? jeErr.message : jeErr
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
|
+
try {
|
|
43
|
+
await client.query(
|
|
44
|
+
`CREATE OR REPLACE FUNCTION strftime(format text, modifier text)
|
|
45
|
+
RETURNS text
|
|
46
|
+
LANGUAGE plpgsql
|
|
47
|
+
IMMUTABLE
|
|
48
|
+
AS $fn$
|
|
49
|
+
DECLARE ts timestamptz;
|
|
50
|
+
BEGIN
|
|
51
|
+
IF modifier = 'now' THEN
|
|
52
|
+
ts := now();
|
|
53
|
+
ELSE
|
|
54
|
+
ts := modifier::timestamptz;
|
|
55
|
+
END IF;
|
|
56
|
+
RETURN to_char(
|
|
57
|
+
ts AT TIME ZONE 'UTC',
|
|
58
|
+
replace(replace(replace(replace(replace(replace(replace(replace(
|
|
59
|
+
format,
|
|
60
|
+
'%Y', 'YYYY'),
|
|
61
|
+
'%m', 'MM'),
|
|
62
|
+
'%d', 'DD'),
|
|
63
|
+
'%H', 'HH24'),
|
|
64
|
+
'%M', 'MI'),
|
|
65
|
+
'%S', 'SS'),
|
|
66
|
+
'%f', 'MS'),
|
|
67
|
+
'T', '"T"')
|
|
68
|
+
);
|
|
69
|
+
END;
|
|
70
|
+
$fn$;`
|
|
71
|
+
);
|
|
72
|
+
} catch (sfErr) {
|
|
73
|
+
console.warn(
|
|
74
|
+
"[PostgresAdapter] could not register strftime polyfill:",
|
|
75
|
+
sfErr instanceof Error ? sfErr.message : sfErr
|
|
76
|
+
);
|
|
77
|
+
}
|
|
42
78
|
return { ok: true };
|
|
43
79
|
}
|
|
44
80
|
case "close": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "latticesql",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Persistent structured memory for AI agent systems — pluggable SQLite or Postgres backend, LLM context bridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,10 +42,12 @@
|
|
|
42
42
|
"prepublishOnly": "npm run check:generic && npm run build && npm run typecheck && npm test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"better-sqlite3": "^12.8.0",
|
|
46
45
|
"uuid": "^13.0.0",
|
|
47
46
|
"yaml": "^2.8.3"
|
|
48
47
|
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"better-sqlite3": ">=11 <13"
|
|
50
|
+
},
|
|
49
51
|
"optionalDependencies": {
|
|
50
52
|
"pg": "^8.11.0",
|
|
51
53
|
"synckit": "^0.9.0"
|
|
@@ -56,6 +58,7 @@
|
|
|
56
58
|
"@types/node": "^22.0.0",
|
|
57
59
|
"@types/pg": "^8.11.0",
|
|
58
60
|
"@vitest/coverage-v8": "^2.1.9",
|
|
61
|
+
"better-sqlite3": "^12.8.0",
|
|
59
62
|
"eslint": "^9.0.0",
|
|
60
63
|
"pg": "^8.11.0",
|
|
61
64
|
"prettier": "^3.3.0",
|