@m2k-5f/pgtx 1.0.3 → 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 +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
132
|
+
### 6. Dynamic Updates (sql.update)
|
|
133
133
|
Easily generate SET clauses from plain JavaScript objects.
|
|
134
134
|
|
|
135
135
|
```typescript
|