@m2k-5f/pgtx 1.3.0 → 1.3.11
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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Clause } from "./base.clause";
|
|
2
|
+
import { CompiledSqlQuery } from "../utils";
|
|
3
|
+
export declare class WhereClause<T extends Record<string, any>> extends Clause {
|
|
4
|
+
private _value;
|
|
5
|
+
constructor(_value: T);
|
|
6
|
+
static create<T extends Record<string, any>>(whereMap: T): WhereClause<T>;
|
|
7
|
+
map(argCounter: number): CompiledSqlQuery;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=where.clause.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"where.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/where.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,qBAAa,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,SAAQ,MAAM;IAE9D,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,CAAC;WAGP,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;IAItD,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB;CAcrD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhereClause = void 0;
|
|
4
|
+
const base_clause_1 = require("./base.clause");
|
|
5
|
+
class WhereClause extends base_clause_1.Clause {
|
|
6
|
+
constructor(_value) {
|
|
7
|
+
super();
|
|
8
|
+
this._value = _value;
|
|
9
|
+
}
|
|
10
|
+
static create(whereMap) {
|
|
11
|
+
return new WhereClause(whereMap);
|
|
12
|
+
}
|
|
13
|
+
map(argCounter) {
|
|
14
|
+
const args = [];
|
|
15
|
+
const entries = Object.entries(this._value).filter(([_, value]) => value !== undefined);
|
|
16
|
+
if (entries.length === 0)
|
|
17
|
+
throw new Error('Where clause has no data to update. All values are `undefined`');
|
|
18
|
+
const text = entries.map(([key, value]) => {
|
|
19
|
+
args.push(value);
|
|
20
|
+
return `${key} = $${argCounter++}`;
|
|
21
|
+
}).join(' AND ');
|
|
22
|
+
return { text, args, argCounter };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.WhereClause = WhereClause;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { Connection } from "./connection";
|
|
|
9
9
|
import { Transaction } from "./transaction";
|
|
10
10
|
import { excludeClause } from "./clauses/exclude.clause";
|
|
11
11
|
import { EmptyClause } from "./clauses/empty.clause";
|
|
12
|
+
import { WhereClause } from "./clauses/where.clause";
|
|
12
13
|
/**
|
|
13
14
|
* Core SQL tagging utility for Pgtx.
|
|
14
15
|
* Provides type-safe helpers for building dynamic queries with recursive support.
|
|
@@ -53,6 +54,19 @@ export declare const sql: {
|
|
|
53
54
|
* // Result: SELECT * FROM users
|
|
54
55
|
*/
|
|
55
56
|
empty: EmptyClause;
|
|
57
|
+
/**
|
|
58
|
+
* Generates a list of conditions for a WHERE clause from a JavaScript object.
|
|
59
|
+
* Works similarly to sql.update, but uses ' AND ' as a separator instead of a comma.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* sql`SELECT * FROM users WHERE ${sql.where({ active: true, role: 'admin' })}`
|
|
63
|
+
* // Result: active = $1 AND role = $2
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* sql`DELETE FROM tasks WHERE ${sql.where({ id: 10, user_id: 5 })}`
|
|
67
|
+
* // Result: id = $1 AND user_id = $2
|
|
68
|
+
*/
|
|
69
|
+
where: typeof WhereClause.create;
|
|
56
70
|
/**
|
|
57
71
|
* Safely escapes SQL identifiers (table or column names) using double quotes.
|
|
58
72
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAe,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAe,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;GAGG;AACH,eAAO,MAAM,GAAG;IACZ;;;;;;;;;;;OAWG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;;;KAWC;;IAGD;;;;;;;;;;OAUG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;CAEN,CAAA;AAGD;;;GAGG;AAEH,OAAO,EAAC,UAAU,IAAI,UAAU,EAAC,CAAA;AAEjC,OAAO,EAAC,WAAW,IAAI,WAAW,EAAC,CAAA;AAEnC,OAAO,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const transaction_1 = require("./transaction");
|
|
|
15
15
|
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_1.Transaction; } });
|
|
16
16
|
const exclude_clause_1 = require("./clauses/exclude.clause");
|
|
17
17
|
const empty_clause_1 = require("./clauses/empty.clause");
|
|
18
|
+
const where_clause_1 = require("./clauses/where.clause");
|
|
18
19
|
/**
|
|
19
20
|
* Core SQL tagging utility for Pgtx.
|
|
20
21
|
* Provides type-safe helpers for building dynamic queries with recursive support.
|
|
@@ -59,6 +60,19 @@ exports.sql = {
|
|
|
59
60
|
* // Result: SELECT * FROM users
|
|
60
61
|
*/
|
|
61
62
|
empty: empty_clause_1.emptyClause,
|
|
63
|
+
/**
|
|
64
|
+
* Generates a list of conditions for a WHERE clause from a JavaScript object.
|
|
65
|
+
* Works similarly to sql.update, but uses ' AND ' as a separator instead of a comma.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* sql`SELECT * FROM users WHERE ${sql.where({ active: true, role: 'admin' })}`
|
|
69
|
+
* // Result: active = $1 AND role = $2
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* sql`DELETE FROM tasks WHERE ${sql.where({ id: 10, user_id: 5 })}`
|
|
73
|
+
* // Result: id = $1 AND user_id = $2
|
|
74
|
+
*/
|
|
75
|
+
where: where_clause_1.WhereClause.create,
|
|
62
76
|
/**
|
|
63
77
|
* Safely escapes SQL identifiers (table or column names) using double quotes.
|
|
64
78
|
*
|