@agentforge/tools 0.16.38 → 0.16.39
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/index.cjs +53 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -36
- package/dist/index.d.ts +16 -36
- package/dist/index.js +53 -112
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -5230,11 +5230,6 @@ interface QueryExecutionContext {
|
|
|
5230
5230
|
*/
|
|
5231
5231
|
declare function executeQuery(manager: ConnectionManager, input: QueryInput, context?: QueryExecutionContext): Promise<QueryExecutionResult>;
|
|
5232
5232
|
|
|
5233
|
-
/**
|
|
5234
|
-
* Query builder helpers for relational CRUD operations.
|
|
5235
|
-
* @module query/query-builder
|
|
5236
|
-
*/
|
|
5237
|
-
|
|
5238
5233
|
/**
|
|
5239
5234
|
* Supported scalar values for INSERT payloads.
|
|
5240
5235
|
*/
|
|
@@ -5277,10 +5272,6 @@ interface BuiltInsertQuery {
|
|
|
5277
5272
|
idColumn: string;
|
|
5278
5273
|
supportsReturning: boolean;
|
|
5279
5274
|
}
|
|
5280
|
-
/**
|
|
5281
|
-
* Build a safe parameterized INSERT query from structured input.
|
|
5282
|
-
*/
|
|
5283
|
-
declare function buildInsertQuery(input: InsertQueryInput): BuiltInsertQuery;
|
|
5284
5275
|
/**
|
|
5285
5276
|
* Supported scalar values for UPDATE payloads.
|
|
5286
5277
|
*/
|
|
@@ -5290,17 +5281,19 @@ type UpdateValue = InsertValue;
|
|
|
5290
5281
|
*/
|
|
5291
5282
|
type UpdateData = Record<string, UpdateValue>;
|
|
5292
5283
|
/**
|
|
5293
|
-
* WHERE operator types
|
|
5284
|
+
* WHERE operator types shared by UPDATE/DELETE/SELECT conditions.
|
|
5294
5285
|
*/
|
|
5295
5286
|
type UpdateWhereOperator = 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'like' | 'in' | 'notIn' | 'isNull' | 'isNotNull';
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
*/
|
|
5299
|
-
interface UpdateWhereCondition {
|
|
5287
|
+
type WhereConditionValue = string | number | boolean | null | Array<string | number>;
|
|
5288
|
+
interface BaseWhereCondition {
|
|
5300
5289
|
column: string;
|
|
5301
5290
|
operator: UpdateWhereOperator;
|
|
5302
|
-
value?:
|
|
5291
|
+
value?: WhereConditionValue;
|
|
5303
5292
|
}
|
|
5293
|
+
/**
|
|
5294
|
+
* WHERE condition for UPDATE queries.
|
|
5295
|
+
*/
|
|
5296
|
+
type UpdateWhereCondition = BaseWhereCondition;
|
|
5304
5297
|
/**
|
|
5305
5298
|
* Optional optimistic lock condition appended to WHERE.
|
|
5306
5299
|
*/
|
|
@@ -5330,11 +5323,7 @@ interface BuiltUpdateQuery {
|
|
|
5330
5323
|
/**
|
|
5331
5324
|
* WHERE condition for DELETE queries.
|
|
5332
5325
|
*/
|
|
5333
|
-
|
|
5334
|
-
column: string;
|
|
5335
|
-
operator: UpdateWhereOperator;
|
|
5336
|
-
value?: string | number | boolean | null | Array<string | number>;
|
|
5337
|
-
}
|
|
5326
|
+
type DeleteWhereCondition = BaseWhereCondition;
|
|
5338
5327
|
/**
|
|
5339
5328
|
* Soft-delete configuration.
|
|
5340
5329
|
*/
|
|
@@ -5361,14 +5350,6 @@ interface BuiltDeleteQuery {
|
|
|
5361
5350
|
usesSoftDelete: boolean;
|
|
5362
5351
|
softDeleteColumn?: string;
|
|
5363
5352
|
}
|
|
5364
|
-
/**
|
|
5365
|
-
* Build a safe parameterized UPDATE query from structured input.
|
|
5366
|
-
*/
|
|
5367
|
-
declare function buildUpdateQuery(input: UpdateQueryInput): BuiltUpdateQuery;
|
|
5368
|
-
/**
|
|
5369
|
-
* Build a safe parameterized DELETE query from structured input.
|
|
5370
|
-
*/
|
|
5371
|
-
declare function buildDeleteQuery(input: DeleteQueryInput): BuiltDeleteQuery;
|
|
5372
5353
|
/**
|
|
5373
5354
|
* ORDER BY direction for SELECT queries.
|
|
5374
5355
|
*/
|
|
@@ -5383,11 +5364,7 @@ interface SelectOrderBy {
|
|
|
5383
5364
|
/**
|
|
5384
5365
|
* WHERE condition for SELECT queries.
|
|
5385
5366
|
*/
|
|
5386
|
-
|
|
5387
|
-
column: string;
|
|
5388
|
-
operator: UpdateWhereOperator;
|
|
5389
|
-
value?: string | number | boolean | null | Array<string | number>;
|
|
5390
|
-
}
|
|
5367
|
+
type SelectWhereCondition = BaseWhereCondition;
|
|
5391
5368
|
/**
|
|
5392
5369
|
* Builder input for SELECT queries.
|
|
5393
5370
|
*/
|
|
@@ -5400,9 +5377,12 @@ interface SelectQueryInput {
|
|
|
5400
5377
|
offset?: number;
|
|
5401
5378
|
vendor: DatabaseVendor;
|
|
5402
5379
|
}
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5380
|
+
|
|
5381
|
+
declare function buildInsertQuery(input: InsertQueryInput): BuiltInsertQuery;
|
|
5382
|
+
|
|
5383
|
+
declare function buildUpdateQuery(input: UpdateQueryInput): BuiltUpdateQuery;
|
|
5384
|
+
declare function buildDeleteQuery(input: DeleteQueryInput): BuiltDeleteQuery;
|
|
5385
|
+
|
|
5406
5386
|
declare function buildSelectQuery(input: SelectQueryInput): SQL;
|
|
5407
5387
|
|
|
5408
5388
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -5230,11 +5230,6 @@ interface QueryExecutionContext {
|
|
|
5230
5230
|
*/
|
|
5231
5231
|
declare function executeQuery(manager: ConnectionManager, input: QueryInput, context?: QueryExecutionContext): Promise<QueryExecutionResult>;
|
|
5232
5232
|
|
|
5233
|
-
/**
|
|
5234
|
-
* Query builder helpers for relational CRUD operations.
|
|
5235
|
-
* @module query/query-builder
|
|
5236
|
-
*/
|
|
5237
|
-
|
|
5238
5233
|
/**
|
|
5239
5234
|
* Supported scalar values for INSERT payloads.
|
|
5240
5235
|
*/
|
|
@@ -5277,10 +5272,6 @@ interface BuiltInsertQuery {
|
|
|
5277
5272
|
idColumn: string;
|
|
5278
5273
|
supportsReturning: boolean;
|
|
5279
5274
|
}
|
|
5280
|
-
/**
|
|
5281
|
-
* Build a safe parameterized INSERT query from structured input.
|
|
5282
|
-
*/
|
|
5283
|
-
declare function buildInsertQuery(input: InsertQueryInput): BuiltInsertQuery;
|
|
5284
5275
|
/**
|
|
5285
5276
|
* Supported scalar values for UPDATE payloads.
|
|
5286
5277
|
*/
|
|
@@ -5290,17 +5281,19 @@ type UpdateValue = InsertValue;
|
|
|
5290
5281
|
*/
|
|
5291
5282
|
type UpdateData = Record<string, UpdateValue>;
|
|
5292
5283
|
/**
|
|
5293
|
-
* WHERE operator types
|
|
5284
|
+
* WHERE operator types shared by UPDATE/DELETE/SELECT conditions.
|
|
5294
5285
|
*/
|
|
5295
5286
|
type UpdateWhereOperator = 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'like' | 'in' | 'notIn' | 'isNull' | 'isNotNull';
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
*/
|
|
5299
|
-
interface UpdateWhereCondition {
|
|
5287
|
+
type WhereConditionValue = string | number | boolean | null | Array<string | number>;
|
|
5288
|
+
interface BaseWhereCondition {
|
|
5300
5289
|
column: string;
|
|
5301
5290
|
operator: UpdateWhereOperator;
|
|
5302
|
-
value?:
|
|
5291
|
+
value?: WhereConditionValue;
|
|
5303
5292
|
}
|
|
5293
|
+
/**
|
|
5294
|
+
* WHERE condition for UPDATE queries.
|
|
5295
|
+
*/
|
|
5296
|
+
type UpdateWhereCondition = BaseWhereCondition;
|
|
5304
5297
|
/**
|
|
5305
5298
|
* Optional optimistic lock condition appended to WHERE.
|
|
5306
5299
|
*/
|
|
@@ -5330,11 +5323,7 @@ interface BuiltUpdateQuery {
|
|
|
5330
5323
|
/**
|
|
5331
5324
|
* WHERE condition for DELETE queries.
|
|
5332
5325
|
*/
|
|
5333
|
-
|
|
5334
|
-
column: string;
|
|
5335
|
-
operator: UpdateWhereOperator;
|
|
5336
|
-
value?: string | number | boolean | null | Array<string | number>;
|
|
5337
|
-
}
|
|
5326
|
+
type DeleteWhereCondition = BaseWhereCondition;
|
|
5338
5327
|
/**
|
|
5339
5328
|
* Soft-delete configuration.
|
|
5340
5329
|
*/
|
|
@@ -5361,14 +5350,6 @@ interface BuiltDeleteQuery {
|
|
|
5361
5350
|
usesSoftDelete: boolean;
|
|
5362
5351
|
softDeleteColumn?: string;
|
|
5363
5352
|
}
|
|
5364
|
-
/**
|
|
5365
|
-
* Build a safe parameterized UPDATE query from structured input.
|
|
5366
|
-
*/
|
|
5367
|
-
declare function buildUpdateQuery(input: UpdateQueryInput): BuiltUpdateQuery;
|
|
5368
|
-
/**
|
|
5369
|
-
* Build a safe parameterized DELETE query from structured input.
|
|
5370
|
-
*/
|
|
5371
|
-
declare function buildDeleteQuery(input: DeleteQueryInput): BuiltDeleteQuery;
|
|
5372
5353
|
/**
|
|
5373
5354
|
* ORDER BY direction for SELECT queries.
|
|
5374
5355
|
*/
|
|
@@ -5383,11 +5364,7 @@ interface SelectOrderBy {
|
|
|
5383
5364
|
/**
|
|
5384
5365
|
* WHERE condition for SELECT queries.
|
|
5385
5366
|
*/
|
|
5386
|
-
|
|
5387
|
-
column: string;
|
|
5388
|
-
operator: UpdateWhereOperator;
|
|
5389
|
-
value?: string | number | boolean | null | Array<string | number>;
|
|
5390
|
-
}
|
|
5367
|
+
type SelectWhereCondition = BaseWhereCondition;
|
|
5391
5368
|
/**
|
|
5392
5369
|
* Builder input for SELECT queries.
|
|
5393
5370
|
*/
|
|
@@ -5400,9 +5377,12 @@ interface SelectQueryInput {
|
|
|
5400
5377
|
offset?: number;
|
|
5401
5378
|
vendor: DatabaseVendor;
|
|
5402
5379
|
}
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5380
|
+
|
|
5381
|
+
declare function buildInsertQuery(input: InsertQueryInput): BuiltInsertQuery;
|
|
5382
|
+
|
|
5383
|
+
declare function buildUpdateQuery(input: UpdateQueryInput): BuiltUpdateQuery;
|
|
5384
|
+
declare function buildDeleteQuery(input: DeleteQueryInput): BuiltDeleteQuery;
|
|
5385
|
+
|
|
5406
5386
|
declare function buildSelectQuery(input: SelectQueryInput): SQL;
|
|
5407
5387
|
|
|
5408
5388
|
/**
|
package/dist/index.js
CHANGED
|
@@ -5065,11 +5065,9 @@ function rowsHaveHomogeneousColumns(rows) {
|
|
|
5065
5065
|
function buildSingleRowInsert(table, row, vendor) {
|
|
5066
5066
|
const columns = Object.keys(row);
|
|
5067
5067
|
if (columns.length === 0) {
|
|
5068
|
-
|
|
5069
|
-
return sql.raw(`INSERT INTO ${quotedTable2} DEFAULT VALUES`);
|
|
5068
|
+
return sql.raw(`INSERT INTO ${quoteQualifiedIdentifier(table, vendor)} DEFAULT VALUES`);
|
|
5070
5069
|
}
|
|
5071
5070
|
columns.forEach((column) => validateIdentifier(column, "Insert column"));
|
|
5072
|
-
const quotedTable = quoteQualifiedIdentifier(table, vendor);
|
|
5073
5071
|
const quotedColumns = columns.map((column) => quoteIdentifier(column, vendor)).join(", ");
|
|
5074
5072
|
const valueFragments = columns.map((column) => {
|
|
5075
5073
|
const value = row[column];
|
|
@@ -5080,7 +5078,9 @@ function buildSingleRowInsert(table, row, vendor) {
|
|
|
5080
5078
|
});
|
|
5081
5079
|
return sql.join(
|
|
5082
5080
|
[
|
|
5083
|
-
sql.raw(
|
|
5081
|
+
sql.raw(
|
|
5082
|
+
`INSERT INTO ${quoteQualifiedIdentifier(table, vendor)} (${quotedColumns}) VALUES (`
|
|
5083
|
+
),
|
|
5084
5084
|
sql.join(valueFragments, sql.raw(", ")),
|
|
5085
5085
|
sql.raw(")")
|
|
5086
5086
|
],
|
|
@@ -5091,12 +5091,13 @@ function buildInsertValuesQuery(table, columns, rows, vendor) {
|
|
|
5091
5091
|
if (vendor === "sqlite" && !rowsHaveHomogeneousColumns(rows)) {
|
|
5092
5092
|
return rows.map((row) => buildSingleRowInsert(table, row, vendor));
|
|
5093
5093
|
}
|
|
5094
|
-
const quotedTable = quoteQualifiedIdentifier(table, vendor);
|
|
5095
5094
|
const quotedColumns = columns.map((column) => quoteIdentifier(column, vendor)).join(", ");
|
|
5096
5095
|
const rowTuples = rows.map((row) => buildValuesTuple(columns, row));
|
|
5097
5096
|
return sql.join(
|
|
5098
5097
|
[
|
|
5099
|
-
sql.raw(
|
|
5098
|
+
sql.raw(
|
|
5099
|
+
`INSERT INTO ${quoteQualifiedIdentifier(table, vendor)} (${quotedColumns}) VALUES `
|
|
5100
|
+
),
|
|
5100
5101
|
sql.join(rowTuples, sql.raw(", "))
|
|
5101
5102
|
],
|
|
5102
5103
|
sql.raw("")
|
|
@@ -5106,8 +5107,7 @@ function buildInsertDefaultValuesQuery(table, rowCount, vendor) {
|
|
|
5106
5107
|
if (rowCount > 1) {
|
|
5107
5108
|
throw new Error("Batch INSERT with only DEFAULT VALUES is not supported");
|
|
5108
5109
|
}
|
|
5109
|
-
|
|
5110
|
-
return sql.raw(`INSERT INTO ${quotedTable} DEFAULT VALUES`);
|
|
5110
|
+
return sql.raw(`INSERT INTO ${quoteQualifiedIdentifier(table, vendor)} DEFAULT VALUES`);
|
|
5111
5111
|
}
|
|
5112
5112
|
function buildInsertQuery(input) {
|
|
5113
5113
|
validateQualifiedIdentifier(input.table, "Table name");
|
|
@@ -5130,9 +5130,7 @@ function buildInsertQuery(input) {
|
|
|
5130
5130
|
let queries = valuesResult;
|
|
5131
5131
|
if (returningMode !== "none" && supportsReturning) {
|
|
5132
5132
|
const returningClause = returningMode === "id" ? sql.raw(` RETURNING ${quoteIdentifier(idColumn, input.vendor)}`) : sql.raw(" RETURNING *");
|
|
5133
|
-
queries = queries.map(
|
|
5134
|
-
(q) => sql.join([q, returningClause], sql.raw(""))
|
|
5135
|
-
);
|
|
5133
|
+
queries = queries.map((query2) => sql.join([query2, returningClause], sql.raw("")));
|
|
5136
5134
|
}
|
|
5137
5135
|
return {
|
|
5138
5136
|
query: queries,
|
|
@@ -5144,14 +5142,10 @@ function buildInsertQuery(input) {
|
|
|
5144
5142
|
}
|
|
5145
5143
|
let query = valuesResult;
|
|
5146
5144
|
if (returningMode !== "none" && supportsReturning) {
|
|
5147
|
-
|
|
5148
|
-
query
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
);
|
|
5152
|
-
} else {
|
|
5153
|
-
query = sql.join([query, sql.raw(" RETURNING *")], sql.raw(""));
|
|
5154
|
-
}
|
|
5145
|
+
query = returningMode === "id" ? sql.join(
|
|
5146
|
+
[query, sql.raw(` RETURNING ${quoteIdentifier(idColumn, input.vendor)}`)],
|
|
5147
|
+
sql.raw("")
|
|
5148
|
+
) : sql.join([query, sql.raw(" RETURNING *")], sql.raw(""));
|
|
5155
5149
|
}
|
|
5156
5150
|
return {
|
|
5157
5151
|
query,
|
|
@@ -5161,23 +5155,7 @@ function buildInsertQuery(input) {
|
|
|
5161
5155
|
supportsReturning
|
|
5162
5156
|
};
|
|
5163
5157
|
}
|
|
5164
|
-
function
|
|
5165
|
-
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
5166
|
-
throw new Error("Update data must be an object");
|
|
5167
|
-
}
|
|
5168
|
-
const keys = Object.keys(data);
|
|
5169
|
-
if (keys.length === 0) {
|
|
5170
|
-
throw new Error("Update data must not be empty");
|
|
5171
|
-
}
|
|
5172
|
-
keys.forEach((column) => {
|
|
5173
|
-
validateIdentifier(column, "Update column");
|
|
5174
|
-
if (data[column] === void 0) {
|
|
5175
|
-
throw new Error(`Update value for column "${column}" must not be undefined`);
|
|
5176
|
-
}
|
|
5177
|
-
});
|
|
5178
|
-
return data;
|
|
5179
|
-
}
|
|
5180
|
-
function buildUpdateWhereCondition(condition, vendor) {
|
|
5158
|
+
function buildWhereCondition(condition, vendor) {
|
|
5181
5159
|
validateIdentifier(condition.column, "WHERE column");
|
|
5182
5160
|
const column = sql.raw(quoteIdentifier(condition.column, vendor));
|
|
5183
5161
|
switch (condition.operator) {
|
|
@@ -5226,12 +5204,12 @@ function buildUpdateWhereCondition(condition, vendor) {
|
|
|
5226
5204
|
if (!Array.isArray(condition.value) || condition.value.length === 0) {
|
|
5227
5205
|
throw new Error(`IN operator requires a non-empty array value for column ${condition.column}`);
|
|
5228
5206
|
}
|
|
5229
|
-
return sql`${column} IN (${sql.join(condition.value.map((
|
|
5207
|
+
return sql`${column} IN (${sql.join(condition.value.map((value) => sql`${value}`), sql.raw(", "))})`;
|
|
5230
5208
|
case "notIn":
|
|
5231
5209
|
if (!Array.isArray(condition.value) || condition.value.length === 0) {
|
|
5232
5210
|
throw new Error(`NOT IN operator requires a non-empty array value for column ${condition.column}`);
|
|
5233
5211
|
}
|
|
5234
|
-
return sql`${column} NOT IN (${sql.join(condition.value.map((
|
|
5212
|
+
return sql`${column} NOT IN (${sql.join(condition.value.map((value) => sql`${value}`), sql.raw(", "))})`;
|
|
5235
5213
|
case "isNull":
|
|
5236
5214
|
if (condition.value !== void 0) {
|
|
5237
5215
|
throw new Error(`IS NULL operator must not include value for column ${condition.column}`);
|
|
@@ -5244,6 +5222,24 @@ function buildUpdateWhereCondition(condition, vendor) {
|
|
|
5244
5222
|
return sql`${column} IS NOT NULL`;
|
|
5245
5223
|
}
|
|
5246
5224
|
}
|
|
5225
|
+
|
|
5226
|
+
// src/data/relational/query/query-builder-mutation.ts
|
|
5227
|
+
function normalizeUpdateData(data) {
|
|
5228
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
5229
|
+
throw new Error("Update data must be an object");
|
|
5230
|
+
}
|
|
5231
|
+
const keys = Object.keys(data);
|
|
5232
|
+
if (keys.length === 0) {
|
|
5233
|
+
throw new Error("Update data must not be empty");
|
|
5234
|
+
}
|
|
5235
|
+
keys.forEach((column) => {
|
|
5236
|
+
validateIdentifier(column, "Update column");
|
|
5237
|
+
if (data[column] === void 0) {
|
|
5238
|
+
throw new Error(`Update value for column "${column}" must not be undefined`);
|
|
5239
|
+
}
|
|
5240
|
+
});
|
|
5241
|
+
return data;
|
|
5242
|
+
}
|
|
5247
5243
|
function buildUpdateQuery(input) {
|
|
5248
5244
|
validateQualifiedIdentifier(input.table, "Table name");
|
|
5249
5245
|
const normalizedData = normalizeUpdateData(input.data);
|
|
@@ -5252,7 +5248,7 @@ function buildUpdateQuery(input) {
|
|
|
5252
5248
|
return sql`${quotedColumn} = ${value}`;
|
|
5253
5249
|
});
|
|
5254
5250
|
const whereConditions = (input.where ?? []).map(
|
|
5255
|
-
(condition) =>
|
|
5251
|
+
(condition) => buildWhereCondition(condition, input.vendor)
|
|
5256
5252
|
);
|
|
5257
5253
|
if (input.optimisticLock) {
|
|
5258
5254
|
validateIdentifier(input.optimisticLock.column, "Optimistic lock column");
|
|
@@ -5263,7 +5259,9 @@ function buildUpdateQuery(input) {
|
|
|
5263
5259
|
whereConditions.push(sql`${lockColumn} = ${input.optimisticLock.expectedValue}`);
|
|
5264
5260
|
}
|
|
5265
5261
|
if (whereConditions.length === 0 && !input.allowFullTableUpdate) {
|
|
5266
|
-
throw new Error(
|
|
5262
|
+
throw new Error(
|
|
5263
|
+
"WHERE conditions are required for UPDATE queries. Set allowFullTableUpdate=true to override."
|
|
5264
|
+
);
|
|
5267
5265
|
}
|
|
5268
5266
|
let query = sql.join(
|
|
5269
5267
|
[
|
|
@@ -5273,7 +5271,10 @@ function buildUpdateQuery(input) {
|
|
|
5273
5271
|
sql.raw("")
|
|
5274
5272
|
);
|
|
5275
5273
|
if (whereConditions.length > 0) {
|
|
5276
|
-
query = sql.join(
|
|
5274
|
+
query = sql.join(
|
|
5275
|
+
[query, sql.raw(" WHERE "), sql.join(whereConditions, sql.raw(" AND "))],
|
|
5276
|
+
sql.raw("")
|
|
5277
|
+
);
|
|
5277
5278
|
}
|
|
5278
5279
|
return {
|
|
5279
5280
|
query,
|
|
@@ -5284,10 +5285,12 @@ function buildUpdateQuery(input) {
|
|
|
5284
5285
|
function buildDeleteQuery(input) {
|
|
5285
5286
|
validateQualifiedIdentifier(input.table, "Table name");
|
|
5286
5287
|
const whereConditions = (input.where ?? []).map(
|
|
5287
|
-
(condition) =>
|
|
5288
|
+
(condition) => buildWhereCondition(condition, input.vendor)
|
|
5288
5289
|
);
|
|
5289
5290
|
if (whereConditions.length === 0 && !input.allowFullTableDelete) {
|
|
5290
|
-
throw new Error(
|
|
5291
|
+
throw new Error(
|
|
5292
|
+
"WHERE conditions are required for DELETE queries. Set allowFullTableDelete=true to override."
|
|
5293
|
+
);
|
|
5291
5294
|
}
|
|
5292
5295
|
const softDeleteColumn = input.softDelete?.column ?? "deleted_at";
|
|
5293
5296
|
const softDeleteValue = input.softDelete?.value ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -5306,7 +5309,10 @@ function buildDeleteQuery(input) {
|
|
|
5306
5309
|
query = sql.raw(`DELETE FROM ${quoteQualifiedIdentifier(input.table, input.vendor)}`);
|
|
5307
5310
|
}
|
|
5308
5311
|
if (whereConditions.length > 0) {
|
|
5309
|
-
query = sql.join(
|
|
5312
|
+
query = sql.join(
|
|
5313
|
+
[query, sql.raw(" WHERE "), sql.join(whereConditions, sql.raw(" AND "))],
|
|
5314
|
+
sql.raw("")
|
|
5315
|
+
);
|
|
5310
5316
|
}
|
|
5311
5317
|
return {
|
|
5312
5318
|
query,
|
|
@@ -5315,73 +5321,6 @@ function buildDeleteQuery(input) {
|
|
|
5315
5321
|
softDeleteColumn: input.softDelete ? softDeleteColumn : void 0
|
|
5316
5322
|
};
|
|
5317
5323
|
}
|
|
5318
|
-
function buildSelectWhereCondition(condition, vendor) {
|
|
5319
|
-
validateIdentifier(condition.column, "WHERE column");
|
|
5320
|
-
const column = sql.raw(quoteIdentifier(condition.column, vendor));
|
|
5321
|
-
switch (condition.operator) {
|
|
5322
|
-
case "eq":
|
|
5323
|
-
if (condition.value === void 0) {
|
|
5324
|
-
throw new Error(`EQ operator requires a value for column ${condition.column}`);
|
|
5325
|
-
}
|
|
5326
|
-
if (condition.value === null) {
|
|
5327
|
-
throw new Error("null is only allowed with isNull/isNotNull operators");
|
|
5328
|
-
}
|
|
5329
|
-
return sql`${column} = ${condition.value}`;
|
|
5330
|
-
case "ne":
|
|
5331
|
-
if (condition.value === void 0) {
|
|
5332
|
-
throw new Error(`NE operator requires a value for column ${condition.column}`);
|
|
5333
|
-
}
|
|
5334
|
-
if (condition.value === null) {
|
|
5335
|
-
throw new Error("null is only allowed with isNull/isNotNull operators");
|
|
5336
|
-
}
|
|
5337
|
-
return sql`${column} != ${condition.value}`;
|
|
5338
|
-
case "gt":
|
|
5339
|
-
if (typeof condition.value !== "string" && typeof condition.value !== "number") {
|
|
5340
|
-
throw new Error(`GT operator requires a string or number value for column ${condition.column}`);
|
|
5341
|
-
}
|
|
5342
|
-
return sql`${column} > ${condition.value}`;
|
|
5343
|
-
case "lt":
|
|
5344
|
-
if (typeof condition.value !== "string" && typeof condition.value !== "number") {
|
|
5345
|
-
throw new Error(`LT operator requires a string or number value for column ${condition.column}`);
|
|
5346
|
-
}
|
|
5347
|
-
return sql`${column} < ${condition.value}`;
|
|
5348
|
-
case "gte":
|
|
5349
|
-
if (typeof condition.value !== "string" && typeof condition.value !== "number") {
|
|
5350
|
-
throw new Error(`GTE operator requires a string or number value for column ${condition.column}`);
|
|
5351
|
-
}
|
|
5352
|
-
return sql`${column} >= ${condition.value}`;
|
|
5353
|
-
case "lte":
|
|
5354
|
-
if (typeof condition.value !== "string" && typeof condition.value !== "number") {
|
|
5355
|
-
throw new Error(`LTE operator requires a string or number value for column ${condition.column}`);
|
|
5356
|
-
}
|
|
5357
|
-
return sql`${column} <= ${condition.value}`;
|
|
5358
|
-
case "like":
|
|
5359
|
-
if (typeof condition.value !== "string") {
|
|
5360
|
-
throw new Error(`LIKE operator requires a string value for column ${condition.column}`);
|
|
5361
|
-
}
|
|
5362
|
-
return sql`${column} LIKE ${condition.value}`;
|
|
5363
|
-
case "in":
|
|
5364
|
-
if (!Array.isArray(condition.value) || condition.value.length === 0) {
|
|
5365
|
-
throw new Error(`IN operator requires a non-empty array value for column ${condition.column}`);
|
|
5366
|
-
}
|
|
5367
|
-
return sql`${column} IN (${sql.join(condition.value.map((v) => sql`${v}`), sql.raw(", "))})`;
|
|
5368
|
-
case "notIn":
|
|
5369
|
-
if (!Array.isArray(condition.value) || condition.value.length === 0) {
|
|
5370
|
-
throw new Error(`NOT IN operator requires a non-empty array value for column ${condition.column}`);
|
|
5371
|
-
}
|
|
5372
|
-
return sql`${column} NOT IN (${sql.join(condition.value.map((v) => sql`${v}`), sql.raw(", "))})`;
|
|
5373
|
-
case "isNull":
|
|
5374
|
-
if (condition.value !== void 0) {
|
|
5375
|
-
throw new Error(`IS NULL operator must not include value for column ${condition.column}`);
|
|
5376
|
-
}
|
|
5377
|
-
return sql`${column} IS NULL`;
|
|
5378
|
-
case "isNotNull":
|
|
5379
|
-
if (condition.value !== void 0) {
|
|
5380
|
-
throw new Error(`IS NOT NULL operator must not include value for column ${condition.column}`);
|
|
5381
|
-
}
|
|
5382
|
-
return sql`${column} IS NOT NULL`;
|
|
5383
|
-
}
|
|
5384
|
-
}
|
|
5385
5324
|
function buildSelectQuery(input) {
|
|
5386
5325
|
validateQualifiedIdentifier(input.table, "Table name");
|
|
5387
5326
|
let query = sql.raw("SELECT ");
|
|
@@ -5399,7 +5338,9 @@ function buildSelectQuery(input) {
|
|
|
5399
5338
|
sql.raw("")
|
|
5400
5339
|
);
|
|
5401
5340
|
if (input.where && input.where.length > 0) {
|
|
5402
|
-
const whereConditions = input.where.map(
|
|
5341
|
+
const whereConditions = input.where.map(
|
|
5342
|
+
(condition) => buildWhereCondition(condition, input.vendor)
|
|
5343
|
+
);
|
|
5403
5344
|
query = sql.join(
|
|
5404
5345
|
[query, sql.raw(" WHERE "), sql.join(whereConditions, sql.raw(" AND "))],
|
|
5405
5346
|
sql.raw("")
|