@m2k-5f/pgtx 1.2.2 → 1.3.1

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,8 @@
1
+ import { CompiledSqlQuery } from "../utils";
2
+ import { Clause } from "./base.clause";
3
+ export declare class EmptyClause extends Clause {
4
+ static new(): EmptyClause;
5
+ map(argCounter: number): CompiledSqlQuery;
6
+ }
7
+ export declare const emptyClause: EmptyClause;
8
+ //# sourceMappingURL=empty.clause.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"empty.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/empty.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGvC,qBAAa,WAAY,SAAQ,MAAM;IACnC,MAAM,CAAC,GAAG;IAIV,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB;CAG5C;AAED,eAAO,MAAM,WAAW,aAAoB,CAAA"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emptyClause = exports.EmptyClause = void 0;
4
+ const base_clause_1 = require("./base.clause");
5
+ class EmptyClause extends base_clause_1.Clause {
6
+ static new() {
7
+ return new this();
8
+ }
9
+ map(argCounter) {
10
+ return { argCounter, args: [], text: "" };
11
+ }
12
+ }
13
+ exports.EmptyClause = EmptyClause;
14
+ exports.emptyClause = EmptyClause.new();
@@ -0,0 +1,9 @@
1
+ import { CompiledSqlQuery } from "../utils";
2
+ import { Clause } from "./base.clause";
3
+ export declare class ExcludeUpdateClause extends Clause {
4
+ readonly fields: string[];
5
+ constructor(fields: string[]);
6
+ map(argCounter: number): CompiledSqlQuery;
7
+ }
8
+ export declare function excludeClause(fields: string[]): ExcludeUpdateClause;
9
+ //# sourceMappingURL=exclude.clause.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exclude.clause.d.ts","sourceRoot":"","sources":["../../src/clauses/exclude.clause.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,qBAAa,mBAAoB,SAAQ,MAAM;IAEvC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE;gBAAhB,MAAM,EAAE,MAAM,EAAE;IAGtB,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB;CAInD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,mBAAmB,CAEnE"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExcludeUpdateClause = void 0;
4
+ exports.excludeClause = excludeClause;
5
+ const base_clause_1 = require("./base.clause");
6
+ class ExcludeUpdateClause extends base_clause_1.Clause {
7
+ constructor(fields) {
8
+ super();
9
+ this.fields = fields;
10
+ }
11
+ map(argCounter) {
12
+ const text = this.fields.map(f => `${f} = EXCLUDED.${f}`).join(', ');
13
+ return { argCounter, args: [], text };
14
+ }
15
+ }
16
+ exports.ExcludeUpdateClause = ExcludeUpdateClause;
17
+ function excludeClause(fields) {
18
+ return new ExcludeUpdateClause(fields);
19
+ }
@@ -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;
@@ -7,8 +7,9 @@ import { Transaction } from "./transaction";
7
7
  */
8
8
  export declare class Connection {
9
9
  private readonly client;
10
+ private readonly enableLogs;
10
11
  private isReleased;
11
- constructor(client: PoolClient);
12
+ constructor(client: PoolClient, enableLogs: boolean);
12
13
  /**
13
14
  * Checks if the connection is still open and not returned to the pool.
14
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AAC/C,OAAO,EAAE,i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/B,OAAO,CAAC,UAAU,CAAiB;gBAGd,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,OAAO;IAGxC;;OAEG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED;;;;;;;OAOG;IACU,OAAO,CAAC,OAAO,SAAS,cAAc,GAAG,GAAG,EAAE,OAAO,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE,EACpF,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAoB/C;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrC,OAAO,CAAC,WAAW;IAMnB;;;;;;OAMG;IACU,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,GAAG,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAcjH;;;;;;;;OAQG;IACU,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAmB/E"}
@@ -9,8 +9,9 @@ const cacher = new query_cacher_1.QueryCacher();
9
9
  * Always remember to call `.release()` when finished.
10
10
  */
11
11
  class Connection {
12
- constructor(client) {
12
+ constructor(client, enableLogs) {
13
13
  this.client = client;
14
+ this.enableLogs = enableLogs;
14
15
  this.isReleased = false;
15
16
  }
16
17
  /**
@@ -69,6 +70,9 @@ class Connection {
69
70
  async query(strings, ...values) {
70
71
  this.checkActive();
71
72
  const { text, args } = cacher.cachedBuild(strings, values, 1);
73
+ if (this.enableLogs) {
74
+ console.log(`\nQUERY: ${text}\n${args.length ? `ARGUMENTS: [${args}]\n` : ""}`);
75
+ }
72
76
  const result = await this.client.query(text, args);
73
77
  return result.rows;
74
78
  }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,9 @@ import { updateClause } from "./clauses/update.clause";
7
7
  import { insertClause } from "./clauses/insert.clause";
8
8
  import { Connection } from "./connection";
9
9
  import { Transaction } from "./transaction";
10
+ import { excludeClause } from "./clauses/exclude.clause";
11
+ import { EmptyClause } from "./clauses/empty.clause";
12
+ import { WhereClause } from "./clauses/where.clause";
10
13
  /**
11
14
  * Core SQL tagging utility for Pgtx.
12
15
  * Provides type-safe helpers for building dynamic queries with recursive support.
@@ -33,6 +36,37 @@ export declare const sql: {
33
36
  * // Result: status = $1, updated_at = $2
34
37
  */
35
38
  update: typeof updateClause;
39
+ /**
40
+ * Generates an assignment list for ON CONFLICT DO UPDATE using the EXCLUDED table.
41
+ *
42
+ * @example
43
+ * sql`INSERT INTO users ${sql.insert(data)} ON CONFLICT (id) DO UPDATE SET ${sql.excluded(['name', 'email'])}`
44
+ * // Result: name = EXCLUDED.name, email = EXCLUDED.email
45
+ */
46
+ excluded: typeof excludeClause;
47
+ /**
48
+ * Represents a safe empty SQL fragment.
49
+ * Useful for dynamic query building when a condition or list might be optional.
50
+ *
51
+ * @example
52
+ * const filters = [];
53
+ * sql`SELECT * FROM users ${filters.length ? sql.fragment`WHERE ...` : sql.empty}`
54
+ * // Result: SELECT * FROM users
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;
36
70
  /**
37
71
  * Safely escapes SQL identifiers (table or column names) using double quotes.
38
72
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"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O,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
@@ -13,6 +13,9 @@ const connection_1 = require("./connection");
13
13
  Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_1.Connection; } });
14
14
  const transaction_1 = require("./transaction");
15
15
  Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_1.Transaction; } });
16
+ const exclude_clause_1 = require("./clauses/exclude.clause");
17
+ const empty_clause_1 = require("./clauses/empty.clause");
18
+ const where_clause_1 = require("./clauses/where.clause");
16
19
  /**
17
20
  * Core SQL tagging utility for Pgtx.
18
21
  * Provides type-safe helpers for building dynamic queries with recursive support.
@@ -39,6 +42,37 @@ exports.sql = {
39
42
  * // Result: status = $1, updated_at = $2
40
43
  */
41
44
  update: update_clause_1.updateClause,
45
+ /**
46
+ * Generates an assignment list for ON CONFLICT DO UPDATE using the EXCLUDED table.
47
+ *
48
+ * @example
49
+ * sql`INSERT INTO users ${sql.insert(data)} ON CONFLICT (id) DO UPDATE SET ${sql.excluded(['name', 'email'])}`
50
+ * // Result: name = EXCLUDED.name, email = EXCLUDED.email
51
+ */
52
+ excluded: exclude_clause_1.excludeClause,
53
+ /**
54
+ * Represents a safe empty SQL fragment.
55
+ * Useful for dynamic query building when a condition or list might be optional.
56
+ *
57
+ * @example
58
+ * const filters = [];
59
+ * sql`SELECT * FROM users ${filters.length ? sql.fragment`WHERE ...` : sql.empty}`
60
+ * // Result: SELECT * FROM users
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,
42
76
  /**
43
77
  * Safely escapes SQL identifiers (table or column names) using double quotes.
44
78
  *
package/dist/pool.d.ts CHANGED
@@ -8,6 +8,7 @@ import { Transaction } from "./transaction";
8
8
  */
9
9
  export declare class Pool {
10
10
  private pool;
11
+ private enableLogs;
11
12
  constructor(config: PoolConfig);
12
13
  /**
13
14
  * Executes a one-off query.
@@ -1 +1 @@
1
- {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAC,MAAM,IAAI,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C;;;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AQG;IACU,OAAO,CAAC,OAAO,SAAS,cAAc,GAAG,GAAG,EAAE,OAAO,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE,EACpF,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAyB/C;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;IAK3C;;;;;;;;;OASG;IACU,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAc5E;;OAEG;IACH,IAAW,KAAK;;;;MAMf;IAED;;OAEG;IACI,KAAK;CAGf"}
package/dist/pool.js CHANGED
@@ -9,6 +9,7 @@ const connection_1 = require("./connection");
9
9
  */
10
10
  class Pool {
11
11
  constructor(config) {
12
+ this.enableLogs = config.enableLogs ?? false;
12
13
  this.pool = new pg_1.Pool(config);
13
14
  }
14
15
  /**
@@ -68,7 +69,7 @@ class Pool {
68
69
  */
69
70
  async acquire() {
70
71
  const client = await this.pool.connect();
71
- return new connection_1.Connection(client);
72
+ return new connection_1.Connection(client, this.enableLogs);
72
73
  }
73
74
  /**
74
75
  * Starts a managed transaction.
package/dist/types.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { PoolConfig as PgPoolConfig } from "pg";
2
- export type PoolConfig = PgPoolConfig;
2
+ export type PoolConfig = PgPoolConfig & {
3
+ enableLogs?: boolean;
4
+ };
3
5
  export type PreparedStatement<TResult extends any, Tparams extends any[]> = {
4
6
  text: string;
5
7
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,IAAI,CAAA;AAE/C,MAAM,MAAM,UAAU,GAAG,YAAY,CAAA;AAErC,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,GAAG,EAAE,OAAO,SAAS,GAAG,EAAE,IAAI;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;CACpD,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,IAAI,CAAA;AAE/C,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAC,CAAA;AAE9D,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,GAAG,EAAE,OAAO,SAAS,GAAG,EAAE,IAAI;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;CACpD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m2k-5f/pgtx",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "Lightweight, high-performance SQL toolkit for node-postgres",
5
5
  "files": [
6
6
  "dist",