@profullstack/libsql-pg 0.1.1 → 0.1.3
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 +6 -2
- package/src/schema.js +10 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/libsql-pg",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Drop-in replacement for @libsql/client that talks to Postgres, plus the tools to move a Turso/libSQL database into it: the same execute/batch/transaction surface, SQLite idioms rewritten on the way through, a schema converter and a row copier.",
|
|
6
6
|
"keywords": [
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"LICENSE"
|
|
48
48
|
],
|
|
49
49
|
"scripts": {
|
|
50
|
-
"test": "node --test
|
|
50
|
+
"test": "node --test test/*.test.js",
|
|
51
51
|
"test:unit": "node --test test/rewrite.test.js test/bind.test.js test/result.test.js test/errors.test.js test/schema.test.js test/copy-plan.test.js"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
+
"@profullstack/libsql-pg": "^0.1.1",
|
|
60
61
|
"pg": "^8.13.0"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
@@ -68,6 +69,9 @@
|
|
|
68
69
|
}
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
72
|
+
"@libsql/client": "^0.15.15"
|
|
73
|
+
},
|
|
74
|
+
"optionalDependencies": {
|
|
71
75
|
"@libsql/client": "^0.15.0"
|
|
72
76
|
}
|
|
73
77
|
}
|
package/src/schema.js
CHANGED
|
@@ -154,9 +154,12 @@ function convertColumnConstraints(constraints, { type, ctx, opts }) {
|
|
|
154
154
|
/** Remove a DEFAULT clause (a literal or a parenthesised expression). */
|
|
155
155
|
function stripDefault(c) {
|
|
156
156
|
const mask = codeMask(c);
|
|
157
|
-
const m = /(?<!\bby)\sdefault
|
|
157
|
+
const m = /(?<!\bby)\sdefault(?=\s)/i.exec(mask);
|
|
158
158
|
if (!m) return c;
|
|
159
|
+
// The mask blanks string literals to spaces, so the gap after DEFAULT is
|
|
160
|
+
// measured on the text: `default 'x' check (...)` must not skip past 'x'.
|
|
159
161
|
let end = m.index + m[0].length;
|
|
162
|
+
end += /^\s*/.exec(c.slice(end))[0].length;
|
|
160
163
|
if (mask[end] === '(') end = matchParen(mask, end) + 1;
|
|
161
164
|
else {
|
|
162
165
|
const rest = /^('[^']*(?:''[^']*)*'|[^\s]+)/.exec(c.slice(end));
|
|
@@ -175,9 +178,10 @@ function stripDefault(c) {
|
|
|
175
178
|
*/
|
|
176
179
|
function rewriteDefault(c, type, ctx, notes) {
|
|
177
180
|
const mask = codeMask(c);
|
|
178
|
-
const m = /(?<!\bby)\sdefault
|
|
181
|
+
const m = /(?<!\bby)\sdefault(?=\s)/i.exec(mask);
|
|
179
182
|
if (!m) return c;
|
|
180
|
-
|
|
183
|
+
let start = m.index + m[0].length;
|
|
184
|
+
start += /^\s*/.exec(c.slice(start))[0].length; // see stripDefault: literals are blank in the mask
|
|
181
185
|
let end;
|
|
182
186
|
if (mask[start] === '(') end = matchParen(mask, start) + 1;
|
|
183
187
|
else {
|
|
@@ -189,8 +193,10 @@ function rewriteDefault(c, type, ctx, notes) {
|
|
|
189
193
|
let out = bare;
|
|
190
194
|
const lower = bare.toLowerCase().replace(/\s+/g, '');
|
|
191
195
|
if (type === 'boolean' && /^[01]$/.test(bare)) out = bare === '1' ? 'true' : 'false';
|
|
192
|
-
else if (lower === 'current_timestamp' ||
|
|
196
|
+
else if (lower === 'current_timestamp' || lower === "datetime('now')") out = 'now()';
|
|
193
197
|
else if (/^strftime\('%y-%m-%dt%h:%m:%[fs]z?','now'\)$/.test(lower)) out = 'now()';
|
|
198
|
+
// datetime('now', '+7 days') and friends keep their modifiers: the function
|
|
199
|
+
// rewriter turns them into now() + interval '7 days'.
|
|
194
200
|
else out = rewriteFunctions(bare);
|
|
195
201
|
if (/gen_random_bytes/.test(out)) ctx.usesPgcrypto = true;
|
|
196
202
|
// to_char(...) as a default on a text column is fine; on timestamptz it is not.
|