bun-query-builder 0.2.22 → 0.2.24
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 +59 -3
- package/dist/client.d.ts +4 -0
- package/dist/src/index.js +58 -2
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -15771,6 +15771,14 @@ function createQueryBuilder(state) {
|
|
|
15771
15771
|
left = expression.text;
|
|
15772
15772
|
params.push(...expression.parameters);
|
|
15773
15773
|
}
|
|
15774
|
+
if (safeOperator.toLowerCase() === "in" || safeOperator.toLowerCase() === "not in") {
|
|
15775
|
+
const values = Array.isArray(value) ? value : [value];
|
|
15776
|
+
const placeholders = getPlaceholders(values.length, params.length + 1);
|
|
15777
|
+
sqlText = `${sqlText} ${getWhereKeyword()} ${left} ${safeOperator.toUpperCase()} (${placeholders})`;
|
|
15778
|
+
params.push(...values);
|
|
15779
|
+
built = _sql.unsafe(sqlText, params);
|
|
15780
|
+
return this;
|
|
15781
|
+
}
|
|
15774
15782
|
const paramIndex = params.length + 1;
|
|
15775
15783
|
sqlText = `${sqlText} ${getWhereKeyword()} ${left} ${safeOperator} ${getPlaceholder(paramIndex)}`;
|
|
15776
15784
|
params.push(value);
|
|
@@ -15780,6 +15788,14 @@ function createQueryBuilder(state) {
|
|
|
15780
15788
|
if (Array.isArray(expr)) {
|
|
15781
15789
|
const [col, op2, val] = expr;
|
|
15782
15790
|
const safeOperator = assertSafeWhereOperator(op2, "updateTable.where");
|
|
15791
|
+
if (safeOperator.toLowerCase() === "in" || safeOperator.toLowerCase() === "not in") {
|
|
15792
|
+
const values = Array.isArray(val) ? val : [val];
|
|
15793
|
+
const placeholders = getPlaceholders(values.length, params.length + 1);
|
|
15794
|
+
sqlText = `${sqlText} ${getWhereKeyword()} ${quoteId(String(col))} ${safeOperator.toUpperCase()} (${placeholders})`;
|
|
15795
|
+
params.push(...values);
|
|
15796
|
+
built = _sql.unsafe(sqlText, params);
|
|
15797
|
+
return this;
|
|
15798
|
+
}
|
|
15783
15799
|
const paramIndex = params.length + 1;
|
|
15784
15800
|
sqlText = `${sqlText} ${getWhereKeyword()} ${quoteId(String(col))} ${safeOperator} ${getPlaceholder(paramIndex)}`;
|
|
15785
15801
|
params.push(val);
|
|
@@ -15800,6 +15816,18 @@ function createQueryBuilder(state) {
|
|
|
15800
15816
|
}
|
|
15801
15817
|
return this;
|
|
15802
15818
|
},
|
|
15819
|
+
whereNull(column) {
|
|
15820
|
+
const keyword = SQL_PATTERNS.WHERE.test(sqlText) ? "AND" : "WHERE";
|
|
15821
|
+
sqlText = `${sqlText} ${keyword} ${quoteId(String(column))} IS NULL`;
|
|
15822
|
+
built = _sql.unsafe(sqlText, params);
|
|
15823
|
+
return this;
|
|
15824
|
+
},
|
|
15825
|
+
whereNotNull(column) {
|
|
15826
|
+
const keyword = SQL_PATTERNS.WHERE.test(sqlText) ? "AND" : "WHERE";
|
|
15827
|
+
sqlText = `${sqlText} ${keyword} ${quoteId(String(column))} IS NOT NULL`;
|
|
15828
|
+
built = _sql.unsafe(sqlText, params);
|
|
15829
|
+
return this;
|
|
15830
|
+
},
|
|
15803
15831
|
returning(...cols) {
|
|
15804
15832
|
const retText = `${sqlText} RETURNING ${cols.join(", ")}`;
|
|
15805
15833
|
const q = params.length > 0 ? _sql.unsafe(retText, params) : _sql.unsafe(retText);
|
|
@@ -15898,16 +15926,34 @@ function createQueryBuilder(state) {
|
|
|
15898
15926
|
where(expr, op, value) {
|
|
15899
15927
|
whereCondition = expr;
|
|
15900
15928
|
if (typeof expr === "string" && op !== undefined) {
|
|
15929
|
+
const safeOperator = assertSafeWhereOperator(op, "deleteFrom.where");
|
|
15930
|
+
if (safeOperator.toLowerCase() === "in" || safeOperator.toLowerCase() === "not in") {
|
|
15931
|
+
const values = Array.isArray(value) ? value : [value];
|
|
15932
|
+
const placeholders = getPlaceholders(values.length, delParams.length + 1);
|
|
15933
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(expr)} ${safeOperator.toUpperCase()} (${placeholders})`;
|
|
15934
|
+
delParams.push(...values);
|
|
15935
|
+
built = null;
|
|
15936
|
+
return this;
|
|
15937
|
+
}
|
|
15901
15938
|
const paramIndex = delParams.length + 1;
|
|
15902
|
-
sqlText += ` ${getWhereKeyword()} ${quoteId(expr)} ${
|
|
15939
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(expr)} ${safeOperator} ${getPlaceholder(paramIndex)}`;
|
|
15903
15940
|
delParams.push(value);
|
|
15904
15941
|
built = null;
|
|
15905
15942
|
return this;
|
|
15906
15943
|
}
|
|
15907
15944
|
if (Array.isArray(expr)) {
|
|
15908
15945
|
const [col, oper, val] = expr;
|
|
15946
|
+
const safeOperator = assertSafeWhereOperator(oper, "deleteFrom.where");
|
|
15947
|
+
if (safeOperator.toLowerCase() === "in" || safeOperator.toLowerCase() === "not in") {
|
|
15948
|
+
const values = Array.isArray(val) ? val : [val];
|
|
15949
|
+
const placeholders = getPlaceholders(values.length, delParams.length + 1);
|
|
15950
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(String(col))} ${safeOperator.toUpperCase()} (${placeholders})`;
|
|
15951
|
+
delParams.push(...values);
|
|
15952
|
+
built = null;
|
|
15953
|
+
return this;
|
|
15954
|
+
}
|
|
15909
15955
|
const paramIndex = delParams.length + 1;
|
|
15910
|
-
sqlText += ` ${getWhereKeyword()} ${quoteId(String(col))} ${
|
|
15956
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(String(col))} ${safeOperator} ${getPlaceholder(paramIndex)}`;
|
|
15911
15957
|
delParams.push(val);
|
|
15912
15958
|
built = null;
|
|
15913
15959
|
return this;
|
|
@@ -15927,6 +15973,16 @@ function createQueryBuilder(state) {
|
|
|
15927
15973
|
built = applyWhere({}, ensureDelBuilt(), expr);
|
|
15928
15974
|
return this;
|
|
15929
15975
|
},
|
|
15976
|
+
whereNull(column) {
|
|
15977
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(String(column))} IS NULL`;
|
|
15978
|
+
built = null;
|
|
15979
|
+
return this;
|
|
15980
|
+
},
|
|
15981
|
+
whereNotNull(column) {
|
|
15982
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(String(column))} IS NOT NULL`;
|
|
15983
|
+
built = null;
|
|
15984
|
+
return this;
|
|
15985
|
+
},
|
|
15930
15986
|
returning(...cols) {
|
|
15931
15987
|
const retText = `${sqlText} RETURNING ${cols.join(", ")}`;
|
|
15932
15988
|
const q = delParams.length > 0 ? _sql.unsafe(retText, delParams) : _sql.unsafe(retText);
|
|
@@ -31634,7 +31690,7 @@ function getPrefix() {
|
|
|
31634
31690
|
}
|
|
31635
31691
|
var prefix = getPrefix();
|
|
31636
31692
|
// package.json
|
|
31637
|
-
var version2 = "0.2.
|
|
31693
|
+
var version2 = "0.2.24";
|
|
31638
31694
|
|
|
31639
31695
|
// bin/cli.ts
|
|
31640
31696
|
init_actions();
|
package/dist/client.d.ts
CHANGED
|
@@ -238,6 +238,8 @@ export declare interface InsertQueryBuilder<DB extends DatabaseSchema<any>, TTab
|
|
|
238
238
|
export declare interface UpdateQueryBuilder<DB extends DatabaseSchema<any>, TTable extends keyof DB & string> {
|
|
239
239
|
set: (values: Partial<{ [K in keyof DB[TTable]['columns']]: DB[TTable]['columns'][K] | SqlFragment }>) => UpdateQueryBuilder<DB, TTable>
|
|
240
240
|
where: (expr: WhereExpression<DB[TTable]['columns']> | string | SqlFragment, op?: WhereOperator, value?: any) => UpdateQueryBuilder<DB, TTable>
|
|
241
|
+
whereNull: <K extends keyof DB[TTable]['columns'] & string>(column: K) => UpdateQueryBuilder<DB, TTable>
|
|
242
|
+
whereNotNull: <K extends keyof DB[TTable]['columns'] & string>(column: K) => UpdateQueryBuilder<DB, TTable>
|
|
241
243
|
returning: <K extends keyof DB[TTable]['columns'] & string>(...cols: K[]) => SelectQueryBuilder<DB, TTable, Pick<DB[TTable]['columns'], K>>
|
|
242
244
|
toSQL: () => string
|
|
243
245
|
execute: () => Promise<number>
|
|
@@ -247,6 +249,8 @@ export declare interface UpdateQueryBuilder<DB extends DatabaseSchema<any>, TTab
|
|
|
247
249
|
}
|
|
248
250
|
export declare interface DeleteQueryBuilder<DB extends DatabaseSchema<any>, TTable extends keyof DB & string> {
|
|
249
251
|
where: (expr: WhereExpression<DB[TTable]['columns']> | string, op?: WhereOperator, value?: any) => DeleteQueryBuilder<DB, TTable>
|
|
252
|
+
whereNull: <K extends keyof DB[TTable]['columns'] & string>(column: K) => DeleteQueryBuilder<DB, TTable>
|
|
253
|
+
whereNotNull: <K extends keyof DB[TTable]['columns'] & string>(column: K) => DeleteQueryBuilder<DB, TTable>
|
|
250
254
|
returning: <K extends keyof DB[TTable]['columns'] & string>(...cols: K[]) => SelectQueryBuilder<DB, TTable, Pick<DB[TTable]['columns'], K>>
|
|
251
255
|
toSQL: () => string
|
|
252
256
|
execute: () => Promise<number>
|
package/dist/src/index.js
CHANGED
|
@@ -15770,6 +15770,14 @@ function createQueryBuilder(state) {
|
|
|
15770
15770
|
left = expression.text;
|
|
15771
15771
|
params.push(...expression.parameters);
|
|
15772
15772
|
}
|
|
15773
|
+
if (safeOperator.toLowerCase() === "in" || safeOperator.toLowerCase() === "not in") {
|
|
15774
|
+
const values = Array.isArray(value) ? value : [value];
|
|
15775
|
+
const placeholders = getPlaceholders(values.length, params.length + 1);
|
|
15776
|
+
sqlText = `${sqlText} ${getWhereKeyword()} ${left} ${safeOperator.toUpperCase()} (${placeholders})`;
|
|
15777
|
+
params.push(...values);
|
|
15778
|
+
built = _sql.unsafe(sqlText, params);
|
|
15779
|
+
return this;
|
|
15780
|
+
}
|
|
15773
15781
|
const paramIndex = params.length + 1;
|
|
15774
15782
|
sqlText = `${sqlText} ${getWhereKeyword()} ${left} ${safeOperator} ${getPlaceholder(paramIndex)}`;
|
|
15775
15783
|
params.push(value);
|
|
@@ -15779,6 +15787,14 @@ function createQueryBuilder(state) {
|
|
|
15779
15787
|
if (Array.isArray(expr)) {
|
|
15780
15788
|
const [col, op2, val] = expr;
|
|
15781
15789
|
const safeOperator = assertSafeWhereOperator(op2, "updateTable.where");
|
|
15790
|
+
if (safeOperator.toLowerCase() === "in" || safeOperator.toLowerCase() === "not in") {
|
|
15791
|
+
const values = Array.isArray(val) ? val : [val];
|
|
15792
|
+
const placeholders = getPlaceholders(values.length, params.length + 1);
|
|
15793
|
+
sqlText = `${sqlText} ${getWhereKeyword()} ${quoteId(String(col))} ${safeOperator.toUpperCase()} (${placeholders})`;
|
|
15794
|
+
params.push(...values);
|
|
15795
|
+
built = _sql.unsafe(sqlText, params);
|
|
15796
|
+
return this;
|
|
15797
|
+
}
|
|
15782
15798
|
const paramIndex = params.length + 1;
|
|
15783
15799
|
sqlText = `${sqlText} ${getWhereKeyword()} ${quoteId(String(col))} ${safeOperator} ${getPlaceholder(paramIndex)}`;
|
|
15784
15800
|
params.push(val);
|
|
@@ -15799,6 +15815,18 @@ function createQueryBuilder(state) {
|
|
|
15799
15815
|
}
|
|
15800
15816
|
return this;
|
|
15801
15817
|
},
|
|
15818
|
+
whereNull(column) {
|
|
15819
|
+
const keyword = SQL_PATTERNS.WHERE.test(sqlText) ? "AND" : "WHERE";
|
|
15820
|
+
sqlText = `${sqlText} ${keyword} ${quoteId(String(column))} IS NULL`;
|
|
15821
|
+
built = _sql.unsafe(sqlText, params);
|
|
15822
|
+
return this;
|
|
15823
|
+
},
|
|
15824
|
+
whereNotNull(column) {
|
|
15825
|
+
const keyword = SQL_PATTERNS.WHERE.test(sqlText) ? "AND" : "WHERE";
|
|
15826
|
+
sqlText = `${sqlText} ${keyword} ${quoteId(String(column))} IS NOT NULL`;
|
|
15827
|
+
built = _sql.unsafe(sqlText, params);
|
|
15828
|
+
return this;
|
|
15829
|
+
},
|
|
15802
15830
|
returning(...cols) {
|
|
15803
15831
|
const retText = `${sqlText} RETURNING ${cols.join(", ")}`;
|
|
15804
15832
|
const q = params.length > 0 ? _sql.unsafe(retText, params) : _sql.unsafe(retText);
|
|
@@ -15897,16 +15925,34 @@ function createQueryBuilder(state) {
|
|
|
15897
15925
|
where(expr, op, value) {
|
|
15898
15926
|
whereCondition = expr;
|
|
15899
15927
|
if (typeof expr === "string" && op !== undefined) {
|
|
15928
|
+
const safeOperator = assertSafeWhereOperator(op, "deleteFrom.where");
|
|
15929
|
+
if (safeOperator.toLowerCase() === "in" || safeOperator.toLowerCase() === "not in") {
|
|
15930
|
+
const values = Array.isArray(value) ? value : [value];
|
|
15931
|
+
const placeholders = getPlaceholders(values.length, delParams.length + 1);
|
|
15932
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(expr)} ${safeOperator.toUpperCase()} (${placeholders})`;
|
|
15933
|
+
delParams.push(...values);
|
|
15934
|
+
built = null;
|
|
15935
|
+
return this;
|
|
15936
|
+
}
|
|
15900
15937
|
const paramIndex = delParams.length + 1;
|
|
15901
|
-
sqlText += ` ${getWhereKeyword()} ${quoteId(expr)} ${
|
|
15938
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(expr)} ${safeOperator} ${getPlaceholder(paramIndex)}`;
|
|
15902
15939
|
delParams.push(value);
|
|
15903
15940
|
built = null;
|
|
15904
15941
|
return this;
|
|
15905
15942
|
}
|
|
15906
15943
|
if (Array.isArray(expr)) {
|
|
15907
15944
|
const [col, oper, val] = expr;
|
|
15945
|
+
const safeOperator = assertSafeWhereOperator(oper, "deleteFrom.where");
|
|
15946
|
+
if (safeOperator.toLowerCase() === "in" || safeOperator.toLowerCase() === "not in") {
|
|
15947
|
+
const values = Array.isArray(val) ? val : [val];
|
|
15948
|
+
const placeholders = getPlaceholders(values.length, delParams.length + 1);
|
|
15949
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(String(col))} ${safeOperator.toUpperCase()} (${placeholders})`;
|
|
15950
|
+
delParams.push(...values);
|
|
15951
|
+
built = null;
|
|
15952
|
+
return this;
|
|
15953
|
+
}
|
|
15908
15954
|
const paramIndex = delParams.length + 1;
|
|
15909
|
-
sqlText += ` ${getWhereKeyword()} ${quoteId(String(col))} ${
|
|
15955
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(String(col))} ${safeOperator} ${getPlaceholder(paramIndex)}`;
|
|
15910
15956
|
delParams.push(val);
|
|
15911
15957
|
built = null;
|
|
15912
15958
|
return this;
|
|
@@ -15926,6 +15972,16 @@ function createQueryBuilder(state) {
|
|
|
15926
15972
|
built = applyWhere({}, ensureDelBuilt(), expr);
|
|
15927
15973
|
return this;
|
|
15928
15974
|
},
|
|
15975
|
+
whereNull(column) {
|
|
15976
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(String(column))} IS NULL`;
|
|
15977
|
+
built = null;
|
|
15978
|
+
return this;
|
|
15979
|
+
},
|
|
15980
|
+
whereNotNull(column) {
|
|
15981
|
+
sqlText += ` ${getWhereKeyword()} ${quoteId(String(column))} IS NOT NULL`;
|
|
15982
|
+
built = null;
|
|
15983
|
+
return this;
|
|
15984
|
+
},
|
|
15929
15985
|
returning(...cols) {
|
|
15930
15986
|
const retText = `${sqlText} RETURNING ${cols.join(", ")}`;
|
|
15931
15987
|
const q = delParams.length > 0 ? _sql.unsafe(retText, delParams) : _sql.unsafe(retText);
|
package/package.json
CHANGED