@profullstack/libsql-pg 0.1.2 → 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.
Files changed (2) hide show
  1. package/package.json +2 -2
  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.2",
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 \"test/*.test.js\"",
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": {
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\s+/i.exec(mask);
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\s+/i.exec(mask);
181
+ const m = /(?<!\bby)\sdefault(?=\s)/i.exec(mask);
179
182
  if (!m) return c;
180
- const start = m.index + m[0].length;
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' || /^datetime\('now'/.test(lower)) out = 'now()';
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.