bun-query-builder 0.2.31 → 0.2.32
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/bin/cli.js +56 -1
- package/dist/index.d.ts +1 -0
- package/dist/sql-fragments.d.ts +20 -0
- package/dist/src/index.js +56 -0
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -12641,6 +12641,61 @@ function renderInPredicate(column, values, negated, placeholders) {
|
|
|
12641
12641
|
return negated ? TRUE_PREDICATE : FALSE_PREDICATE;
|
|
12642
12642
|
return `${column} ${negated ? "NOT IN" : "IN"} (${placeholders})`;
|
|
12643
12643
|
}
|
|
12644
|
+
function toDialectPlaceholders(sql, dialect) {
|
|
12645
|
+
if (dialect !== "postgres")
|
|
12646
|
+
return sql;
|
|
12647
|
+
let out = "";
|
|
12648
|
+
let index = 0;
|
|
12649
|
+
let position = 0;
|
|
12650
|
+
while (position < sql.length) {
|
|
12651
|
+
const char = sql[position];
|
|
12652
|
+
if (char === "'") {
|
|
12653
|
+
const end = closingQuote(sql, position, "'");
|
|
12654
|
+
out += sql.slice(position, end);
|
|
12655
|
+
position = end;
|
|
12656
|
+
continue;
|
|
12657
|
+
}
|
|
12658
|
+
if (char === '"') {
|
|
12659
|
+
const end = closingQuote(sql, position, '"');
|
|
12660
|
+
out += sql.slice(position, end);
|
|
12661
|
+
position = end;
|
|
12662
|
+
continue;
|
|
12663
|
+
}
|
|
12664
|
+
if (char === "$") {
|
|
12665
|
+
const tag = sql.slice(position).match(/^\$[A-Z_a-z]\w*\$|^\$\$/)?.[0];
|
|
12666
|
+
if (tag) {
|
|
12667
|
+
const close = sql.indexOf(tag, position + tag.length);
|
|
12668
|
+
const end = close === -1 ? sql.length : close + tag.length;
|
|
12669
|
+
out += sql.slice(position, end);
|
|
12670
|
+
position = end;
|
|
12671
|
+
continue;
|
|
12672
|
+
}
|
|
12673
|
+
}
|
|
12674
|
+
if (char === "?") {
|
|
12675
|
+
index++;
|
|
12676
|
+
out += `$${index}`;
|
|
12677
|
+
position++;
|
|
12678
|
+
continue;
|
|
12679
|
+
}
|
|
12680
|
+
out += char;
|
|
12681
|
+
position++;
|
|
12682
|
+
}
|
|
12683
|
+
return out;
|
|
12684
|
+
}
|
|
12685
|
+
function closingQuote(sql, start, quote) {
|
|
12686
|
+
let position = start + 1;
|
|
12687
|
+
while (position < sql.length) {
|
|
12688
|
+
if (sql[position] === quote) {
|
|
12689
|
+
if (sql[position + 1] === quote) {
|
|
12690
|
+
position += 2;
|
|
12691
|
+
continue;
|
|
12692
|
+
}
|
|
12693
|
+
return position + 1;
|
|
12694
|
+
}
|
|
12695
|
+
position++;
|
|
12696
|
+
}
|
|
12697
|
+
return sql.length;
|
|
12698
|
+
}
|
|
12644
12699
|
var FALSE_PREDICATE = "1 = 0", TRUE_PREDICATE = "1 = 1";
|
|
12645
12700
|
|
|
12646
12701
|
// src/client.ts
|
|
@@ -32133,7 +32188,7 @@ function getPrefix() {
|
|
|
32133
32188
|
}
|
|
32134
32189
|
var prefix = getPrefix();
|
|
32135
32190
|
// package.json
|
|
32136
|
-
var version2 = "0.2.
|
|
32191
|
+
var version2 = "0.2.32";
|
|
32137
32192
|
|
|
32138
32193
|
// bin/cli.ts
|
|
32139
32194
|
init_actions();
|
package/dist/index.d.ts
CHANGED
|
@@ -50,3 +50,4 @@ export * from './types';
|
|
|
50
50
|
export { type ModelDefinition, defineModel } from './model';
|
|
51
51
|
// Explicit re-exports for model registry functions
|
|
52
52
|
export { getModel, getAllModels, getModelRegistry, hasModel, clearModelRegistry, registerModel } from './model';
|
|
53
|
+
export { toDialectPlaceholders } from './sql-fragments';
|
package/dist/sql-fragments.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SupportedDialect } from './types';
|
|
1
2
|
/**
|
|
2
3
|
* Render a WHERE body (without the `WHERE` keyword) from an ordered term list.
|
|
3
4
|
*
|
|
@@ -32,6 +33,25 @@ export declare function renderWhereTerms(terms: readonly WhereTerm[]): string;
|
|
|
32
33
|
* failure as the `IN ()` bug itself.
|
|
33
34
|
*/
|
|
34
35
|
export declare function renderInPredicate(column: string, values: any[], negated: boolean, placeholders: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Rewrite `?` placeholders into the numbered form Postgres requires.
|
|
38
|
+
*
|
|
39
|
+
* Raw SQL written with `?` runs on SQLite and MySQL and is a syntax error on
|
|
40
|
+
* Postgres, which reports it as a problem with whatever token follows: a WHERE
|
|
41
|
+
* built as `project_id = ? AND …` is rejected with `syntax error at or near
|
|
42
|
+
* "AND"`, which sends the reader looking at the wrong part of the query. An
|
|
43
|
+
* application that developed against SQLite therefore finds out at the point
|
|
44
|
+
* its raw queries first meet Postgres, and the error does not name the cause.
|
|
45
|
+
*
|
|
46
|
+
* Only unquoted placeholders are rewritten. A `?` inside a string literal, a
|
|
47
|
+
* quoted identifier, or a dollar-quoted block is data and is left exactly as
|
|
48
|
+
* written — the naive global replace is the reason this needs to be a function
|
|
49
|
+
* with tests rather than one line at a call site.
|
|
50
|
+
*
|
|
51
|
+
* Dialects that already take `?` get the string back unchanged, so this is safe
|
|
52
|
+
* to apply unconditionally.
|
|
53
|
+
*/
|
|
54
|
+
export declare function toDialectPlaceholders(sql: string, dialect: SupportedDialect): string;
|
|
35
55
|
/**
|
|
36
56
|
* Constant predicates, for the cases where a collection is empty.
|
|
37
57
|
*
|
package/dist/src/index.js
CHANGED
|
@@ -12640,6 +12640,61 @@ function renderInPredicate(column, values, negated, placeholders) {
|
|
|
12640
12640
|
return negated ? TRUE_PREDICATE : FALSE_PREDICATE;
|
|
12641
12641
|
return `${column} ${negated ? "NOT IN" : "IN"} (${placeholders})`;
|
|
12642
12642
|
}
|
|
12643
|
+
function toDialectPlaceholders(sql, dialect) {
|
|
12644
|
+
if (dialect !== "postgres")
|
|
12645
|
+
return sql;
|
|
12646
|
+
let out = "";
|
|
12647
|
+
let index = 0;
|
|
12648
|
+
let position = 0;
|
|
12649
|
+
while (position < sql.length) {
|
|
12650
|
+
const char = sql[position];
|
|
12651
|
+
if (char === "'") {
|
|
12652
|
+
const end = closingQuote(sql, position, "'");
|
|
12653
|
+
out += sql.slice(position, end);
|
|
12654
|
+
position = end;
|
|
12655
|
+
continue;
|
|
12656
|
+
}
|
|
12657
|
+
if (char === '"') {
|
|
12658
|
+
const end = closingQuote(sql, position, '"');
|
|
12659
|
+
out += sql.slice(position, end);
|
|
12660
|
+
position = end;
|
|
12661
|
+
continue;
|
|
12662
|
+
}
|
|
12663
|
+
if (char === "$") {
|
|
12664
|
+
const tag = sql.slice(position).match(/^\$[A-Z_a-z]\w*\$|^\$\$/)?.[0];
|
|
12665
|
+
if (tag) {
|
|
12666
|
+
const close = sql.indexOf(tag, position + tag.length);
|
|
12667
|
+
const end = close === -1 ? sql.length : close + tag.length;
|
|
12668
|
+
out += sql.slice(position, end);
|
|
12669
|
+
position = end;
|
|
12670
|
+
continue;
|
|
12671
|
+
}
|
|
12672
|
+
}
|
|
12673
|
+
if (char === "?") {
|
|
12674
|
+
index++;
|
|
12675
|
+
out += `$${index}`;
|
|
12676
|
+
position++;
|
|
12677
|
+
continue;
|
|
12678
|
+
}
|
|
12679
|
+
out += char;
|
|
12680
|
+
position++;
|
|
12681
|
+
}
|
|
12682
|
+
return out;
|
|
12683
|
+
}
|
|
12684
|
+
function closingQuote(sql, start, quote) {
|
|
12685
|
+
let position = start + 1;
|
|
12686
|
+
while (position < sql.length) {
|
|
12687
|
+
if (sql[position] === quote) {
|
|
12688
|
+
if (sql[position + 1] === quote) {
|
|
12689
|
+
position += 2;
|
|
12690
|
+
continue;
|
|
12691
|
+
}
|
|
12692
|
+
return position + 1;
|
|
12693
|
+
}
|
|
12694
|
+
position++;
|
|
12695
|
+
}
|
|
12696
|
+
return sql.length;
|
|
12697
|
+
}
|
|
12643
12698
|
var FALSE_PREDICATE = "1 = 0", TRUE_PREDICATE = "1 = 1";
|
|
12644
12699
|
|
|
12645
12700
|
// src/client.ts
|
|
@@ -30068,6 +30123,7 @@ export {
|
|
|
30068
30123
|
toTableName,
|
|
30069
30124
|
toModelInstance,
|
|
30070
30125
|
toDynamoDBItem,
|
|
30126
|
+
toDialectPlaceholders,
|
|
30071
30127
|
tinker,
|
|
30072
30128
|
tableNameFor,
|
|
30073
30129
|
tableInfo,
|
package/package.json
CHANGED