@truto/sqlite-builder 2.0.2-canary.26 → 2.0.2-canary.27
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 +22 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
UPDATE users
|
|
2
|
+
SET name = ${newName}, updated_at = ${new Date()}
|
|
3
|
+
WHERE id = ${userId}
|
|
4
|
+
`
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// DELETE
|
|
7
|
+
const deleteUser = sql`
|
|
8
|
+
DELETE FROM users
|
|
9
|
+
WHERE id = ${userId}
|
|
10
|
+
`
|
|
11
|
+
```
|
|
7
12
|
|
|
8
|
-
###
|
|
13
|
+
### Dynamic Queries
|
|
9
14
|
|
|
10
15
|
```typescript
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
INSERT INTO users (${sql.ident(insertColumns)})
|
|
17
|
-
VALUES (${name}, ${email}, ${age})
|
|
18
|
-
`
|
|
16
|
+
// Dynamic WHERE conditions
|
|
17
|
+
const filters = []
|
|
18
|
+
if (name) filters.push(sql`name = ${name}`)
|
|
19
|
+
if (minAge) filters.push(sql`age >= ${minAge}`)
|
|
20
|
+
if (isActive !== undefined) filters.push(sql`active = ${isActive}`)
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const getUser = sql`
|
|
23
|
-
SELECT ${sql.ident(selectColumns)} FROM users
|
|
24
|
-
WHERE id = ${userId}
|
|
25
|
-
`
|
|
22
|
+
const whereClause =
|
|
23
|
+
filters.length > 0 ? sql.join(filters, ' AND ') : sql.raw('1=1')
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const query = sql`
|
|
26
|
+
SELECT * FROM users
|
|
27
|
+
WHERE ${whereClause}
|
|
28
|
+
ORDER BY created_at DESC
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@truto/sqlite-builder","version":"2.0.2-canary.
|
|
1
|
+
{"name":"@truto/sqlite-builder","version":"2.0.2-canary.27","description":"debug canary","license":"MIT","main":"index.js"}
|