@truto/sqlite-builder 2.0.2-canary.20 → 2.0.2-canary.22

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.
Files changed (2) hide show
  1. package/README.md +23 -23
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,28 +1,28 @@
1
- verified_at: { exists: true },
2
- },
1
+ ],
2
+ }
3
+ ```
4
+
5
+ ### Integration with SQL Template
6
+
7
+ ```typescript
8
+ import { sql, compileFilter } from '@truto/sqlite-builder'
3
9
 
4
- // Recent orders
5
- $recent_orders: {
6
- created_at: { gte: '2024-01-01' },
7
- status: { in: ['completed', 'shipped'] },
8
- total: { gt: 50 },
9
- },
10
+ // Build the WHERE clause
11
+ const filter = {
12
+ status: 'ACTIVE',
13
+ age: { gte: 18 },
14
+ role: { in: ['USER', 'ADMIN'] },
10
15
  }
11
16
 
12
- const complexQuery = sql`
13
- SELECT
14
- u.id,
15
- u.name,
16
- u.email,
17
- p.verified_at,
18
- COUNT(ro.id) as recent_order_count,
19
- SUM(ro.total) as recent_order_total
20
- FROM users u
21
- JOIN profiles p ON u.id = p.user_id
22
- JOIN orders ro ON u.id = ro.user_id
23
- WHERE ${compileFilter(userOrderFilter)}
24
- GROUP BY u.id, u.name, u.email, p.verified_at
25
- HAVING recent_order_count > 0
26
- ORDER BY recent_order_total DESC
17
+ // Use in complete query — the filter fragment and the LIMIT value are
18
+ // collected in order, so query.values lines up with the placeholders.
19
+ const query = sql`
20
+ SELECT id, name, email, created_at
21
+ FROM users
22
+ WHERE ${compileFilter(filter)}
23
+ ORDER BY created_at DESC
24
+ LIMIT ${limit}
27
25
  `
28
26
 
27
+ // Execute with driver
28
+ const results = db.prepare(query.text).all(...query.values)
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@truto/sqlite-builder","version":"2.0.2-canary.20","description":"debug canary","license":"MIT","main":"index.js"}
1
+ {"name":"@truto/sqlite-builder","version":"2.0.2-canary.22","description":"debug canary","license":"MIT","main":"index.js"}