@m2k-5f/pgtx 1.0.0 → 1.0.2
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 +13 -1
- package/dist/index.d.ts +1 -91
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,10 +16,22 @@ Experience ORM-like convenience (auto-inserts, updates, recursive fragments) wit
|
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
19
|
+
## 📦 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @m2k-5f/pgtx
|
|
23
|
+
# or
|
|
24
|
+
yarn add @m2k-5f/pgtx
|
|
25
|
+
# or
|
|
26
|
+
pnpm add @m2k-5f/pgtx
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
19
31
|
## 🚀 Quick Start
|
|
20
32
|
|
|
21
33
|
```typescript
|
|
22
|
-
import { sql, Pool } from
|
|
34
|
+
import { sql, Pool } from "@m2k-5f/pgtx";
|
|
23
35
|
|
|
24
36
|
const pool = new Pool({ /* pg.PoolConfig */ })
|
|
25
37
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,92 +1,2 @@
|
|
|
1
|
-
|
|
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;
|
|
1
|
+
export {};
|
|
92
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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":""}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Pool = exports.sql = void 0;
|
|
4
3
|
const array_clause_1 = require("./clauses/array.clause");
|
|
5
4
|
const fragment_clause_1 = require("./clauses/fragment.clause");
|
|
6
5
|
const iden_caluse_1 = require("./clauses/iden.caluse");
|
|
@@ -12,7 +11,7 @@ const values_clause_1 = require("./clauses/values.clause");
|
|
|
12
11
|
* Core SQL tagging utility for Pgtx.
|
|
13
12
|
* Provides type-safe helpers for building dynamic queries with recursive support.
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
const sql = {
|
|
16
15
|
/**
|
|
17
16
|
* Creates a VALUES clause for INSERT queries.
|
|
18
17
|
* Supports single objects and arrays of objects.
|
|
@@ -91,4 +90,5 @@ exports.sql = {
|
|
|
91
90
|
* Main Pgtx Connection Pool.
|
|
92
91
|
* Manages connections, transactions (including SAVEPOINTs), and prepared statements.
|
|
93
92
|
*/
|
|
94
|
-
|
|
93
|
+
const Pool = pool_1.Pool;
|
|
94
|
+
module.exports = [Pool, sql];
|