@m2k-5f/pgtx 1.0.2 → 1.0.4

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Pgtx 🚀
1
+ ## Pgtx 🚀
2
2
 
3
3
  A lightweight, **high-performance** SQL query builder for `node-postgres` (pg).
4
4
  Experience ORM-like convenience (auto-inserts, updates, recursive fragments) with the transparency and speed of raw SQL.
@@ -68,7 +68,7 @@ await pool.query`
68
68
  // SQL: INSERT INTO users ... VALUES ($1, (SELECT id FROM roles WHERE name = $2)) WHERE status = $3 AND age > $4
69
69
  ```
70
70
 
71
- ## 2. Transactions
71
+ ### 2. Transactions
72
72
  Automatic BEGIN, COMMIT, and ROLLBACK. Use savepoint for nested logic.
73
73
 
74
74
  ```typescript
@@ -84,7 +84,7 @@ await pool.begin(async (tx) => {
84
84
  // Main transaction commits or rolls back based on callback success
85
85
  ```
86
86
 
87
- ## 3. Bulk Inserts (sql.insert)
87
+ ### 3. Bulk Inserts (sql.insert)
88
88
  Automatically extracts columns from the first object. Supports single objects and arrays.
89
89
 
90
90
  ```typescript
@@ -97,7 +97,7 @@ await pool.query`INSERT INTO users ${sql.insert(users)}`
97
97
  // SQL: INSERT INTO users (name, email) VALUES ($1, $2), ($3, $4)
98
98
  ```
99
99
 
100
- ## 4. Prepared Statements
100
+ ### 4. Prepared Statements
101
101
  Pre-parse SQL on the database server for maximum performance in hot loops.
102
102
 
103
103
  ```typescript
@@ -129,7 +129,7 @@ await pool.query`SELECT * FROM users WHERE ${sql.array(conds, ' AND ')}`
129
129
  // SQL: SELECT * FROM users WHERE active = true AND age > $1
130
130
  ```
131
131
 
132
- ## 6. Dynamic Updates (sql.update)
132
+ ### 6. Dynamic Updates (sql.update)
133
133
  Easily generate SET clauses from plain JavaScript objects.
134
134
 
135
135
  ```typescript
package/dist/index.d.ts CHANGED
@@ -1,2 +1,92 @@
1
- export {};
1
+ import { arrayClause } from "./clauses/array.clause";
2
+ import { fragmentClause } from "./clauses/fragment.clause";
3
+ import { identClause } from "./clauses/iden.caluse";
4
+ import { Pool as PgtxPool } from "./pool";
5
+ import { staticClause } from "./clauses/static.clause";
6
+ import { updateClause } from "./clauses/update.clause";
7
+ import { valueClause } from "./clauses/values.clause";
8
+ /**
9
+ * Core SQL tagging utility for Pgtx.
10
+ * Provides type-safe helpers for building dynamic queries with recursive support.
11
+ */
12
+ export declare const sql: {
13
+ /**
14
+ * Creates a VALUES clause for INSERT queries.
15
+ * Supports single objects and arrays of objects.
16
+ *
17
+ * @example
18
+ * sql.insert({ name: 'Ivan', age: 25 })
19
+ * // Result: (name, age) VALUES ($1, $2)
20
+ *
21
+ * @example
22
+ * sql.insert([{ id: 1 }, { id: 2 }])
23
+ * // Result: (id) VALUES ($1), ($2)
24
+ */
25
+ insert: typeof valueClause;
26
+ /**
27
+ * Generates a SET clause for UPDATE queries from a JavaScript object.
28
+ *
29
+ * @example
30
+ * sql.update({ status: 'active', updated_at: new Date() })
31
+ * // Result: status = $1, updated_at = $2
32
+ */
33
+ update: typeof updateClause;
34
+ /**
35
+ * Safely escapes SQL identifiers (table or column names) using double quotes.
36
+ *
37
+ * @example
38
+ * sql.ident('users')
39
+ * // Result: "users"
40
+ *
41
+ * @example
42
+ * sql.ident('table.column')
43
+ * // Result: "table.column"
44
+ */
45
+ ident: typeof identClause;
46
+ /**
47
+ * Injects raw, unescaped SQL strings.
48
+ * ⚠️ Use with caution to prevent SQL injection!
49
+ *
50
+ * @example
51
+ * sql.literal('DESC')
52
+ * // Result: DESC
53
+ */
54
+ literal: typeof staticClause;
55
+ /**
56
+ * Creates a reusable, recursive SQL fragment.
57
+ * Fragments can be nested within each other; argument numbering is handled automatically.
58
+ *
59
+ * @example
60
+ * const filter = sql.fragment`age > ${18}`;
61
+ * sql`SELECT * FROM users WHERE ${filter} AND status = ${'active'}`
62
+ * // Result: SELECT * FROM users WHERE age > $1 AND status = $2
63
+ */
64
+ fragment: typeof fragmentClause;
65
+ /**
66
+ * Formats an array for dynamic lists (IN clauses, column lists, or joined conditions).
67
+ * Supports recursive Clauses (fragments, idents) within the array.
68
+ *
69
+ * @example
70
+ * // Case A: IN clause (manual brackets)
71
+ * sql`WHERE id IN (${sql.array([1, 2])})`
72
+ * // Result: WHERE id IN ($1, $2)
73
+ *
74
+ * @example
75
+ * // Case B: Dynamic WHERE conditions
76
+ * const conds = [sql.fragment`a = 1`, sql.fragment`b = ${2}`];
77
+ * sql`WHERE ${sql.array(conds, ' AND ')}`
78
+ * // Result: WHERE a = 1 AND b = $1
79
+ *
80
+ * @example
81
+ * // Case C: Column list
82
+ * sql`SELECT ${sql.array([sql.ident('id'), sql.ident('name')])}`
83
+ * // Result: SELECT "id", "name"
84
+ */
85
+ array: typeof arrayClause;
86
+ };
87
+ /**
88
+ * Main Pgtx Connection Pool.
89
+ * Manages connections, transactions (including SAVEPOINTs), and prepared statements.
90
+ */
91
+ export declare const Pool: typeof PgtxPool;
2
92
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
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,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,GAAG;IACZ;;;;;;;;;;;OAWG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;;;OAUG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;CAEN,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,iBAAW,CAAA"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pool = exports.sql = void 0;
3
4
  const array_clause_1 = require("./clauses/array.clause");
4
5
  const fragment_clause_1 = require("./clauses/fragment.clause");
5
6
  const iden_caluse_1 = require("./clauses/iden.caluse");
@@ -11,7 +12,7 @@ const values_clause_1 = require("./clauses/values.clause");
11
12
  * Core SQL tagging utility for Pgtx.
12
13
  * Provides type-safe helpers for building dynamic queries with recursive support.
13
14
  */
14
- const sql = {
15
+ exports.sql = {
15
16
  /**
16
17
  * Creates a VALUES clause for INSERT queries.
17
18
  * Supports single objects and arrays of objects.
@@ -90,5 +91,4 @@ const sql = {
90
91
  * Main Pgtx Connection Pool.
91
92
  * Manages connections, transactions (including SAVEPOINTs), and prepared statements.
92
93
  */
93
- const Pool = pool_1.Pool;
94
- module.exports = [Pool, sql];
94
+ exports.Pool = pool_1.Pool;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m2k-5f/pgtx",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Lightweight, high-performance SQL toolkit for node-postgres",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",