@b4moss/crudian 0.3.1 → 0.6.0
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 +332 -22
- package/dist/bun-sqlite/index.d.ts +1 -1
- package/dist/bun-sqlite/index.d.ts.map +1 -1
- package/dist/drizzle/index.d.ts +1 -1
- package/dist/drizzle/index.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/libsql/crud.d.ts +31 -0
- package/dist/libsql/crud.d.ts.map +1 -0
- package/dist/libsql/crud.js +62 -0
- package/dist/libsql/index.d.ts +8 -0
- package/dist/libsql/index.d.ts.map +1 -0
- package/dist/libsql/index.js +6 -0
- package/dist/prisma/crud.d.ts.map +1 -1
- package/dist/prisma/crud.js +13 -3
- package/dist/prisma/index.d.ts +1 -1
- package/dist/prisma/index.d.ts.map +1 -1
- package/dist/sqlite/async-crud.d.ts +2 -1
- package/dist/sqlite/async-crud.d.ts.map +1 -1
- package/dist/sqlite/async-crud.js +14 -5
- package/dist/sqlite/sync-crud.d.ts +2 -1
- package/dist/sqlite/sync-crud.d.ts.map +1 -1
- package/dist/sqlite/sync-crud.js +11 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +17 -5
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
CRUD abstraction for DDD repositories.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
One npm package, adapter subpaths. Shared contracts live at the package root; backends are imported from subpaths. Callers inject their own DB/client — crudian never opens connections or reads env secrets for you.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -10,15 +10,18 @@ Single npm package with adapter subpaths. Shared contracts live at the package r
|
|
|
10
10
|
npm install @b4moss/crudian
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Install only the peer deps for the adapter you use:
|
|
14
14
|
|
|
15
|
-
| Subpath | Peer dependencies |
|
|
16
|
-
|
|
17
|
-
| `@b4moss/crudian/bun-sqlite` | Bun (`bun:sqlite`) |
|
|
18
|
-
| `@b4moss/crudian/drizzle` | `drizzle-orm`, `better-sqlite3` |
|
|
19
|
-
| `@b4moss/crudian/prisma` | `@prisma/client` |
|
|
15
|
+
| Subpath | Runtime | Sync / async | Peer dependencies |
|
|
16
|
+
|---------|---------|--------------|-------------------|
|
|
17
|
+
| `@b4moss/crudian/bun-sqlite` | Bun | sync | Bun (`bun:sqlite`) |
|
|
18
|
+
| `@b4moss/crudian/drizzle` | Node.js 24+ | sync | `drizzle-orm`, `better-sqlite3` |
|
|
19
|
+
| `@b4moss/crudian/prisma` | Node.js 24+ | async | `@prisma/client` |
|
|
20
|
+
| `@b4moss/crudian/libsql` | Node.js 24+ / Bun | async | `@libsql/client` |
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
Node must not import `@b4moss/crudian/bun-sqlite` (resolves to an explicit error stub).
|
|
23
|
+
|
|
24
|
+
## Quick start (adapters)
|
|
22
25
|
|
|
23
26
|
### Shared contracts
|
|
24
27
|
|
|
@@ -26,7 +29,7 @@ Adapter peers (install only what you use):
|
|
|
26
29
|
import { where, CrudianError } from "@b4moss/crudian"
|
|
27
30
|
```
|
|
28
31
|
|
|
29
|
-
### Bun (`bun:sqlite`)
|
|
32
|
+
### Bun (`bun:sqlite`) — sync
|
|
30
33
|
|
|
31
34
|
```ts
|
|
32
35
|
import { Database } from "bun:sqlite"
|
|
@@ -34,15 +37,19 @@ import { createCrud } from "@b4moss/crudian/bun-sqlite"
|
|
|
34
37
|
import { where } from "@b4moss/crudian"
|
|
35
38
|
|
|
36
39
|
const db = new Database(":memory:")
|
|
40
|
+
db.exec(`
|
|
41
|
+
CREATE TABLE items (
|
|
42
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
43
|
+
name TEXT NOT NULL,
|
|
44
|
+
score INTEGER,
|
|
45
|
+
note TEXT
|
|
46
|
+
)
|
|
47
|
+
`)
|
|
37
48
|
const crud = createCrud(db)
|
|
38
|
-
|
|
39
|
-
const row = crud.create("items", { name: "alpha", score: 1 })
|
|
40
|
-
const found = crud.read("items", { where: where().eq("id", row.id) })
|
|
49
|
+
// raw DB is also available as crud.db
|
|
41
50
|
```
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### Drizzle (better-sqlite3)
|
|
52
|
+
### Drizzle (better-sqlite3) — sync
|
|
46
53
|
|
|
47
54
|
```ts
|
|
48
55
|
import Database from "better-sqlite3"
|
|
@@ -50,11 +57,17 @@ import { drizzle } from "drizzle-orm/better-sqlite3"
|
|
|
50
57
|
import { createCrud } from "@b4moss/crudian/drizzle"
|
|
51
58
|
|
|
52
59
|
const sqlite = new Database(":memory:")
|
|
60
|
+
sqlite.exec(`CREATE TABLE items (
|
|
61
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
62
|
+
name TEXT NOT NULL,
|
|
63
|
+
score INTEGER,
|
|
64
|
+
note TEXT
|
|
65
|
+
)`)
|
|
53
66
|
const db = drizzle(sqlite)
|
|
54
67
|
const crud = createCrud(db)
|
|
55
68
|
```
|
|
56
69
|
|
|
57
|
-
### Prisma (SQLite)
|
|
70
|
+
### Prisma (SQLite) — async
|
|
58
71
|
|
|
59
72
|
```ts
|
|
60
73
|
import { PrismaClient } from "@prisma/client"
|
|
@@ -66,15 +79,312 @@ const crud = createCrud(client)
|
|
|
66
79
|
await crud.create("items", { name: "alpha", score: 1 })
|
|
67
80
|
```
|
|
68
81
|
|
|
69
|
-
|
|
82
|
+
### libSQL (`@libsql/client`) — async
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { createClient } from "@libsql/client"
|
|
86
|
+
import { createCrud } from "@b4moss/crudian/libsql"
|
|
87
|
+
|
|
88
|
+
const client = createClient({
|
|
89
|
+
url: process.env.LIBSQL_URL ?? "file:local.db",
|
|
90
|
+
authToken: process.env.LIBSQL_AUTH_TOKEN, // optional; set for remote hosts
|
|
91
|
+
})
|
|
92
|
+
const crud = createCrud(client)
|
|
93
|
+
|
|
94
|
+
await crud.create("items", { name: "alpha", score: 1 })
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
URL / auth token belong on the caller-created client (typically from `.env`).
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## API reference (all methods)
|
|
102
|
+
|
|
103
|
+
Examples below use the **sync** Bun adapter. For `prisma` / `libsql`, `await` every call (same shapes).
|
|
104
|
+
|
|
105
|
+
Assume a table:
|
|
106
|
+
|
|
107
|
+
```sql
|
|
108
|
+
CREATE TABLE items (
|
|
109
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
110
|
+
name TEXT NOT NULL,
|
|
111
|
+
score INTEGER,
|
|
112
|
+
note TEXT
|
|
113
|
+
);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { Database } from "bun:sqlite"
|
|
118
|
+
import { createCrud } from "@b4moss/crudian/bun-sqlite"
|
|
119
|
+
import { where } from "@b4moss/crudian"
|
|
120
|
+
|
|
121
|
+
const db = new Database(":memory:")
|
|
122
|
+
db.exec(/* schema above */)
|
|
123
|
+
const crud = createCrud(db)
|
|
124
|
+
|
|
125
|
+
type Item = { id: number; name: string; score: number | null; note: string | null }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### `create(table, cols)` → row
|
|
129
|
+
|
|
130
|
+
Inserts one row and returns it (including generated `id`).
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const row = crud.create<Item>("items", { name: "alpha", score: 10, note: "n" })
|
|
134
|
+
// { id: 1, name: "alpha", score: 10, note: "n" }
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### `read(table, query?)` → row | `null`
|
|
138
|
+
|
|
139
|
+
Reads one row. Misses return `null` (does not throw).
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
const found = crud.read<Item>("items", {
|
|
143
|
+
columns: ["id", "name"],
|
|
144
|
+
where: where().eq("id", row.id),
|
|
145
|
+
})
|
|
146
|
+
// { id: 1, name: "alpha" }
|
|
147
|
+
|
|
148
|
+
const missing = crud.read<Item>("items", { where: where().eq("id", 999) })
|
|
149
|
+
// null
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### `update(table, cols, query)` → row | `null`
|
|
153
|
+
|
|
154
|
+
Updates matching rows; returns the updated row. Zero matches → `null`. `where` is required.
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
const updated = crud.update<Item>(
|
|
158
|
+
"items",
|
|
159
|
+
{ score: 9 },
|
|
160
|
+
{ where: where().eq("id", row.id) },
|
|
161
|
+
)
|
|
162
|
+
// { id: 1, name: "alpha", score: 9, note: "n" }
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### `delete(table, query)` → number
|
|
166
|
+
|
|
167
|
+
Deletes matching rows; returns affected count. `where` is required.
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
const deleted = crud.delete("items", { where: where().eq("id", row.id) })
|
|
171
|
+
// 1
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### `search(table, query?)` → `{ items, nextCursor, hasMore, total }`
|
|
175
|
+
|
|
176
|
+
Canonical list API. Cursor pagination on `id` ascending. `total` is the full where-match count (ignores `limit` / `cursor`).
|
|
177
|
+
|
|
178
|
+
`SearchQuery` fields:
|
|
179
|
+
|
|
180
|
+
| Field | Meaning |
|
|
181
|
+
|-------|---------|
|
|
182
|
+
| `columns?` | Column list for `SELECT` (same idea as `read`). Omit → `*` |
|
|
183
|
+
| `where?` | Condition builder / node |
|
|
184
|
+
| `limit?` | Page size (default `20`) |
|
|
185
|
+
| `cursor?` | Raw `id` cursor (keyset); rows with `id > cursor` |
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
for (let i = 0; i < 5; i++) {
|
|
189
|
+
crud.create("items", { name: `n${i}`, score: i })
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const page1 = crud.search<Item>("items", { limit: 2 })
|
|
193
|
+
// {
|
|
194
|
+
// items: [ { id: 1, ... }, { id: 2, ... } ],
|
|
195
|
+
// nextCursor: 2,
|
|
196
|
+
// hasMore: true,
|
|
197
|
+
// total: 5,
|
|
198
|
+
// }
|
|
199
|
+
|
|
200
|
+
const page2 = crud.search<Item>("items", {
|
|
201
|
+
limit: 2,
|
|
202
|
+
cursor: page1.nextCursor,
|
|
203
|
+
})
|
|
204
|
+
// items ids [3, 4], total still 5
|
|
205
|
+
|
|
206
|
+
const filtered = crud.search<Item>("items", {
|
|
207
|
+
columns: ["id", "name"],
|
|
208
|
+
where: where().gte("score", 3),
|
|
209
|
+
limit: 10,
|
|
210
|
+
})
|
|
211
|
+
// each item is { id, name } only
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### `list(table, query?)` → same as `search`
|
|
215
|
+
|
|
216
|
+
Thin alias of `search` (same `SearchQuery`, including `columns`).
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
const a = crud.list<Item>("items", {
|
|
220
|
+
columns: ["id", "name"],
|
|
221
|
+
limit: 10,
|
|
222
|
+
})
|
|
223
|
+
const b = crud.search<Item>("items", {
|
|
224
|
+
columns: ["id", "name"],
|
|
225
|
+
limit: 10,
|
|
226
|
+
})
|
|
227
|
+
// a and b are deep-equal
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### `count(table, query?)` → number
|
|
231
|
+
|
|
232
|
+
Where-match count only (`CountQuery` is `{ where? }`). No `limit` / `cursor` / `columns`.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
crud.count("items") // 5
|
|
236
|
+
crud.count("items", { where: where().eq("name", "n0") }) // 1
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### `upsert(table, cols)` → row
|
|
240
|
+
|
|
241
|
+
Conflict target is primary key `id`. Inserts or updates; returns the row. `id` is required in `cols`.
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
const inserted = crud.upsert<Item>("items", { id: 10, name: "new", score: 1 })
|
|
245
|
+
const again = crud.upsert<Item>("items", { id: 10, name: "upd", score: 9 })
|
|
246
|
+
// again.name === "upd"
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### `duplicate(table, query)` → row | `null`
|
|
250
|
+
|
|
251
|
+
Copies the first matching row (new `id`). Optional `overrides`. Zero matches → `null`. `where` is required.
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
const source = crud.create<Item>("items", { name: "a", score: 1, note: "n" })
|
|
255
|
+
const copy = crud.duplicate<Item>("items", {
|
|
256
|
+
where: where().eq("id", source.id),
|
|
257
|
+
overrides: { name: "b" },
|
|
258
|
+
})
|
|
259
|
+
// copy.id !== source.id, copy.name === "b"
|
|
260
|
+
|
|
261
|
+
const none = crud.duplicate<Item>("items", { where: where().eq("id", 999) })
|
|
262
|
+
// null
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### `bulkCreate(table, rows)` → number
|
|
266
|
+
|
|
267
|
+
Inserts many rows; returns inserted count. Empty array → `0`.
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
const n = crud.bulkCreate("items", [
|
|
271
|
+
{ name: "x", score: 1 },
|
|
272
|
+
{ name: "y", score: 2 },
|
|
273
|
+
])
|
|
274
|
+
// 2
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### `bulkUpdate(table, cols, query)` → number
|
|
278
|
+
|
|
279
|
+
Updates many rows; returns affected count. `where` is required.
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
const n = crud.bulkUpdate(
|
|
283
|
+
"items",
|
|
284
|
+
{ score: 8 },
|
|
285
|
+
{ where: where().eq("name", "x") },
|
|
286
|
+
)
|
|
287
|
+
// 1
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### `bulkDelete(table, query)` → number
|
|
291
|
+
|
|
292
|
+
Deletes many rows; returns affected count. `where` is required.
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
const n = crud.bulkDelete("items", { where: where().eq("name", "y") })
|
|
296
|
+
// 1
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### `bulkUpsert(table, rows)` → number
|
|
300
|
+
|
|
301
|
+
Upserts many rows (each row needs `id`); returns processed count. Empty array → `0`.
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
const n = crud.bulkUpsert("items", [
|
|
305
|
+
{ id: 100, name: "z", score: 1 },
|
|
306
|
+
{ id: 10, name: "z2", score: 2 },
|
|
307
|
+
])
|
|
308
|
+
// 2
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### `transaction(fn)` → `fn` return value
|
|
312
|
+
|
|
313
|
+
Runs `fn` inside a transaction helper. Crudian does **not** auto-wrap each CRUD call; use this when you need atomic multi-step work. Success commits; throw rolls back.
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
const result = crud.transaction(() => {
|
|
317
|
+
crud.create("items", { name: "a", score: 1 })
|
|
318
|
+
crud.create("items", { name: "b", score: 2 })
|
|
319
|
+
return "ok"
|
|
320
|
+
})
|
|
321
|
+
// result === "ok"; both rows visible afterward
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
crud.transaction(() => {
|
|
325
|
+
crud.create("items", { name: "c", score: 3 })
|
|
326
|
+
throw new Error("boom")
|
|
327
|
+
})
|
|
328
|
+
} catch {
|
|
329
|
+
// partial writes from that callback are rolled back
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Async adapters:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
await crud.transaction(async () => {
|
|
337
|
+
await crud.create("items", { name: "a", score: 1 })
|
|
338
|
+
await crud.create("items", { name: "b", score: 2 })
|
|
339
|
+
})
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## `where()` builder
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
import { where } from "@b4moss/crudian"
|
|
348
|
+
|
|
349
|
+
where().eq("name", "alpha")
|
|
350
|
+
where().ne("score", 0)
|
|
351
|
+
where().lt("score", 10)
|
|
352
|
+
where().lte("score", 10)
|
|
353
|
+
where().gt("score", 0)
|
|
354
|
+
where().gte("score", 0)
|
|
355
|
+
where().in("name", ["a", "b"])
|
|
356
|
+
where().like("name", "a%")
|
|
357
|
+
where().isNull("note")
|
|
358
|
+
where().isNotNull("note")
|
|
359
|
+
|
|
360
|
+
where()
|
|
361
|
+
.eq("name", "alpha")
|
|
362
|
+
.and(where().gte("score", 5))
|
|
363
|
+
|
|
364
|
+
where()
|
|
365
|
+
.eq("name", "alpha")
|
|
366
|
+
.or(where().eq("name", "beta"))
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
Nestable `and` / `or`. Empty `in([])` is rejected.
|
|
70
370
|
|
|
71
|
-
|
|
371
|
+
---
|
|
72
372
|
|
|
73
|
-
|
|
373
|
+
## Behavior notes
|
|
74
374
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
375
|
+
| Topic | Behavior |
|
|
376
|
+
|-------|----------|
|
|
377
|
+
| Entry | `createCrud(db)` — inject a caller-owned client; exposed as `crud.db` |
|
|
378
|
+
| Sync vs async | `bun-sqlite` / `drizzle` sync; `prisma` / `libsql` return `Promise`s |
|
|
379
|
+
| `read` / `update` / `duplicate` miss | `null` |
|
|
380
|
+
| `delete` / bulk miss | `0` |
|
|
381
|
+
| Upsert conflict | primary key `id` |
|
|
382
|
+
| Pagination | cursor on `id` ASC only (no offset) |
|
|
383
|
+
| `columns` | optional on `read` / `search` / `list`; omit → `*` |
|
|
384
|
+
| `search.total` / `count` | full where count; not page length |
|
|
385
|
+
| Errors | minimal `CrudianError`; other errors propagate from the driver |
|
|
386
|
+
| Identifiers | string required; no format validation |
|
|
387
|
+
| Out of scope | relations, migrations, full-text search, ORM models |
|
|
78
388
|
|
|
79
389
|
## License
|
|
80
390
|
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* Node.js resolves `package.json` exports to `node-stub` instead of this file.
|
|
6
6
|
*/
|
|
7
7
|
export { createCrud, type BunSqliteCrud } from "./crud.js";
|
|
8
|
-
export { CrudianError, where, WhereBuilder, type Row, type SearchResult, type SearchQuery, type ReadQuery, } from "../index.js";
|
|
8
|
+
export { CrudianError, where, WhereBuilder, type Row, type SearchResult, type SearchQuery, type CountQuery, type ReadQuery, } from "../index.js";
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bun-sqlite/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AAC1D,OAAO,EACL,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,GACf,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bun-sqlite/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AAC1D,OAAO,EACL,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,aAAa,CAAA"}
|
package/dist/drizzle/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* Import via: `import { createCrud } from "@b4moss/crudian/drizzle"`
|
|
4
4
|
*/
|
|
5
5
|
export { createCrud, type DrizzleCrud } from "./crud.js";
|
|
6
|
-
export type { Row, SearchResult, WhereInput, ReadQuery, SearchQuery, DeleteQuery, UpdateQuery, DuplicateQuery, } from "../types.js";
|
|
6
|
+
export type { Row, SearchResult, WhereInput, ReadQuery, SearchQuery, CountQuery, DeleteQuery, UpdateQuery, DuplicateQuery, } from "../types.js";
|
|
7
7
|
export { CrudianError, where, WhereBuilder, type Op, type CondNode, type GroupNode, type WhereNode, } from "../index.js";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AACxD,YAAY,EACV,GAAG,EACH,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,KAAK,EAAE,EACP,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AACxD,YAAY,EACV,GAAG,EACH,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,KAAK,EAAE,EACP,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,aAAa,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* - @b4moss/crudian/bun-sqlite
|
|
5
5
|
* - @b4moss/crudian/drizzle
|
|
6
6
|
* - @b4moss/crudian/prisma
|
|
7
|
+
* - @b4moss/crudian/libsql
|
|
7
8
|
*/
|
|
8
9
|
export { CrudianError, assertString } from "./errors.js";
|
|
9
10
|
export { WhereBuilder, where, isWhereBuilder, type Op, type CondNode, type GroupNode, type WhereNode, } from "./where.js";
|
|
10
|
-
export type { Row, SearchResult, WhereInput, ReadQuery, SearchQuery, DeleteQuery, UpdateQuery, DuplicateQuery, } from "./types.js";
|
|
11
|
+
export type { Row, SearchResult, WhereInput, ReadQuery, SearchQuery, CountQuery, DeleteQuery, UpdateQuery, DuplicateQuery, } from "./types.js";
|
|
11
12
|
//# 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":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EACL,YAAY,EACZ,KAAK,EACL,cAAc,EACd,KAAK,EAAE,EACP,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,YAAY,CAAA;AACnB,YAAY,EACV,GAAG,EACH,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type AsyncSqliteCrud } from "../sqlite/async-crud.js";
|
|
2
|
+
import type { Row } from "../types.js";
|
|
3
|
+
/** Result shape used by the libSQL executor bridge. */
|
|
4
|
+
export type LibsqlResultSet = {
|
|
5
|
+
rows: Array<Row | unknown>;
|
|
6
|
+
rowsAffected: number;
|
|
7
|
+
};
|
|
8
|
+
/** Minimal execute surface shared by Client and Transaction. */
|
|
9
|
+
export type LibsqlExecutor = {
|
|
10
|
+
execute(stmt: {
|
|
11
|
+
sql: string;
|
|
12
|
+
args?: unknown[];
|
|
13
|
+
} | string): Promise<LibsqlResultSet>;
|
|
14
|
+
};
|
|
15
|
+
/** Minimal surface of @libsql/client Client used by the adapter. */
|
|
16
|
+
export type LibsqlLikeClient = LibsqlExecutor & {
|
|
17
|
+
transaction(mode?: "write" | "read" | "deferred"): Promise<LibsqlLikeTransaction>;
|
|
18
|
+
};
|
|
19
|
+
export type LibsqlLikeTransaction = LibsqlExecutor & {
|
|
20
|
+
commit(): Promise<void>;
|
|
21
|
+
rollback(): Promise<void>;
|
|
22
|
+
close(): void;
|
|
23
|
+
};
|
|
24
|
+
export type LibsqlCrud = AsyncSqliteCrud<LibsqlLikeClient>;
|
|
25
|
+
/**
|
|
26
|
+
* Create a Crud bound to a libSQL client (`@libsql/client`).
|
|
27
|
+
* Methods are async. The injected client is exposed as `crud.db`.
|
|
28
|
+
* Auth / URL are configured on the caller-created client (e.g. from env).
|
|
29
|
+
*/
|
|
30
|
+
export declare function createCrud(client: LibsqlLikeClient): LibsqlCrud;
|
|
31
|
+
//# sourceMappingURL=crud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../src/libsql/crud.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEtC,uDAAuD;AACvD,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,gEAAgE;AAChE,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CACL,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,GAAG,MAAM,GAC/C,OAAO,CAAC,eAAe,CAAC,CAAA;CAC5B,CAAA;AAED,oEAAoE;AACpE,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG;IAC9C,WAAW,CACT,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,GACnC,OAAO,CAAC,qBAAqB,CAAC,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG;IACnD,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,KAAK,IAAI,IAAI,CAAA;CACd,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAA;AAa1D;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CA6C/D"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CrudianError } from "../index.js";
|
|
2
|
+
import { createAsyncSqliteCrud, } from "../sqlite/async-crud.js";
|
|
3
|
+
function normalizeRow(row) {
|
|
4
|
+
if (row == null || typeof row !== "object") {
|
|
5
|
+
throw new CrudianError("expected row object");
|
|
6
|
+
}
|
|
7
|
+
const out = { ...row };
|
|
8
|
+
for (const [k, v] of Object.entries(out)) {
|
|
9
|
+
if (typeof v === "bigint")
|
|
10
|
+
out[k] = Number(v);
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a Crud bound to a libSQL client (`@libsql/client`).
|
|
16
|
+
* Methods are async. The injected client is exposed as `crud.db`.
|
|
17
|
+
* Auth / URL are configured on the caller-created client (e.g. from env).
|
|
18
|
+
*/
|
|
19
|
+
export function createCrud(client) {
|
|
20
|
+
if (client == null) {
|
|
21
|
+
throw new CrudianError("db is required");
|
|
22
|
+
}
|
|
23
|
+
if (typeof client !== "object" ||
|
|
24
|
+
typeof client.execute !== "function" ||
|
|
25
|
+
typeof client.transaction !== "function") {
|
|
26
|
+
throw new CrudianError("db must be a libSQL client");
|
|
27
|
+
}
|
|
28
|
+
let active = client;
|
|
29
|
+
return createAsyncSqliteCrud(client, {
|
|
30
|
+
async run(sql, args = []) {
|
|
31
|
+
const result = await active.execute({ sql, args });
|
|
32
|
+
return { changes: Number(result.rowsAffected ?? 0) };
|
|
33
|
+
},
|
|
34
|
+
async get(sql, args = []) {
|
|
35
|
+
const result = await active.execute({ sql, args });
|
|
36
|
+
const row = result.rows[0];
|
|
37
|
+
return row == null ? undefined : normalizeRow(row);
|
|
38
|
+
},
|
|
39
|
+
async all(sql, args = []) {
|
|
40
|
+
const result = await active.execute({ sql, args });
|
|
41
|
+
return result.rows.map((row) => normalizeRow(row));
|
|
42
|
+
},
|
|
43
|
+
async transaction(fn) {
|
|
44
|
+
const tx = await client.transaction("write");
|
|
45
|
+
const prev = active;
|
|
46
|
+
active = tx;
|
|
47
|
+
try {
|
|
48
|
+
const value = await fn();
|
|
49
|
+
await tx.commit();
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
await tx.rollback();
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
active = prev;
|
|
58
|
+
tx.close();
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* libSQL adapter for @b4moss/crudian.
|
|
3
|
+
* Import via: `import { createCrud } from "@b4moss/crudian/libsql"`
|
|
4
|
+
*/
|
|
5
|
+
export { createCrud, type LibsqlCrud, type LibsqlLikeClient, type LibsqlLikeTransaction, type LibsqlExecutor, type LibsqlResultSet, } from "./crud.js";
|
|
6
|
+
export type { Row, SearchResult, WhereInput, ReadQuery, SearchQuery, CountQuery, DeleteQuery, UpdateQuery, DuplicateQuery, } from "../types.js";
|
|
7
|
+
export { CrudianError, where, WhereBuilder, type Op, type CondNode, type GroupNode, type WhereNode, } from "../index.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/libsql/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,UAAU,EACV,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAA;AAClB,YAAY,EACV,GAAG,EACH,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,KAAK,EAAE,EACP,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,aAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../src/prisma/crud.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAA;AAGhC,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACvE,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAC7E,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,gBAAgB,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACtE,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAA;AAU1D;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../src/prisma/crud.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAA;AAGhC,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACvE,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAC7E,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,gBAAgB,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACtE,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAA;AAU1D;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CA0C/D"}
|
package/dist/prisma/crud.js
CHANGED
|
@@ -29,13 +29,14 @@ export function createCrud(client) {
|
|
|
29
29
|
return { changes: Number(changes ?? 0) };
|
|
30
30
|
},
|
|
31
31
|
async get(sql, args = []) {
|
|
32
|
-
const
|
|
32
|
+
const result = await active.$queryRawUnsafe(sql, ...args);
|
|
33
|
+
const rows = normalizeQueryResult(result);
|
|
33
34
|
const row = rows[0];
|
|
34
35
|
return row == null ? undefined : normalizeRow(row);
|
|
35
36
|
},
|
|
36
37
|
async all(sql, args = []) {
|
|
37
|
-
const
|
|
38
|
-
return
|
|
38
|
+
const result = await active.$queryRawUnsafe(sql, ...args);
|
|
39
|
+
return normalizeQueryResult(result).map(normalizeRow);
|
|
39
40
|
},
|
|
40
41
|
async transaction(fn) {
|
|
41
42
|
return client.$transaction(async (tx) => {
|
|
@@ -51,3 +52,12 @@ export function createCrud(client) {
|
|
|
51
52
|
},
|
|
52
53
|
});
|
|
53
54
|
}
|
|
55
|
+
function normalizeQueryResult(result) {
|
|
56
|
+
if (result == null)
|
|
57
|
+
return [];
|
|
58
|
+
if (Array.isArray(result))
|
|
59
|
+
return result;
|
|
60
|
+
if (typeof result === "object")
|
|
61
|
+
return [result];
|
|
62
|
+
return [];
|
|
63
|
+
}
|
package/dist/prisma/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* Import via: `import { createCrud } from "@b4moss/crudian/prisma"`
|
|
4
4
|
*/
|
|
5
5
|
export { createCrud, type PrismaCrud, type PrismaLikeClient } from "./crud.js";
|
|
6
|
-
export type { Row, SearchResult, WhereInput, ReadQuery, SearchQuery, DeleteQuery, UpdateQuery, DuplicateQuery, } from "../types.js";
|
|
6
|
+
export type { Row, SearchResult, WhereInput, ReadQuery, SearchQuery, CountQuery, DeleteQuery, UpdateQuery, DuplicateQuery, } from "../types.js";
|
|
7
7
|
export { CrudianError, where, WhereBuilder, type Op, type CondNode, type GroupNode, type WhereNode, } from "../index.js";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prisma/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC9E,YAAY,EACV,GAAG,EACH,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,KAAK,EAAE,EACP,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prisma/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC9E,YAAY,EACV,GAAG,EACH,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,KAAK,EAAE,EACP,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,GACf,MAAM,aAAa,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DeleteQuery, type DuplicateQuery, type ReadQuery, type Row, type SearchQuery, type SearchResult, type UpdateQuery } from "../index.js";
|
|
1
|
+
import { type CountQuery, type DeleteQuery, type DuplicateQuery, type ReadQuery, type Row, type SearchQuery, type SearchResult, type UpdateQuery } from "../index.js";
|
|
2
2
|
export type AsyncSqliteExecutor = {
|
|
3
3
|
run(sql: string, args?: unknown[]): Promise<{
|
|
4
4
|
changes: number;
|
|
@@ -21,6 +21,7 @@ export type AsyncSqliteCrud<TDb> = {
|
|
|
21
21
|
bulkUpsert(table: string, rows: Record<string, unknown>[]): Promise<number>;
|
|
22
22
|
search<T extends Row = Row>(table: string, query?: SearchQuery): Promise<SearchResult<T>>;
|
|
23
23
|
list<T extends Row = Row>(table: string, query?: SearchQuery): Promise<SearchResult<T>>;
|
|
24
|
+
count(table: string, query?: CountQuery): Promise<number>;
|
|
24
25
|
transaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
25
26
|
};
|
|
26
27
|
export declare function createAsyncSqliteC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EAC7B,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAAA;IAClB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9D,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC3E,MAAM,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,EACxB,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3B,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,EACtB,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACzD,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACjD,CAAA;AAoBD,wBAAgB,qBAAqB,CAAC,GAAG,EACvC,EAAE,EAAE,GAAG,EACP,EAAE,EAAE,mBAAmB,GACtB,eAAe,CAAC,GAAG,CAAC,CAmStB"}
|
|
@@ -32,10 +32,9 @@ export function createAsyncSqliteCrud(db, ex) {
|
|
|
32
32
|
const colSql = keys.map((k) => quoteIdent(k)).join(", ");
|
|
33
33
|
const placeholders = keys.map(() => "?").join(", ");
|
|
34
34
|
const args = keys.map((k) => cols[k]);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const row = await ex.get(`SELECT * FROM ${tbl} WHERE "id" = ?`, [id]);
|
|
35
|
+
// Single-statement insert+fetch avoids last_insert_rowid() across pooled
|
|
36
|
+
// connections (Prisma SQLite), which can return an empty row after COUNT.
|
|
37
|
+
const row = await ex.get(`INSERT INTO ${tbl} (${colSql}) VALUES (${placeholders}) RETURNING *`, args);
|
|
39
38
|
return rowFromObject(row);
|
|
40
39
|
},
|
|
41
40
|
async read(table, query = {}) {
|
|
@@ -115,11 +114,21 @@ export function createAsyncSqliteCrud(db, ex) {
|
|
|
115
114
|
const nextCursor = hasMore && last != null && (typeof last.id === "number" || typeof last.id === "string")
|
|
116
115
|
? last.id
|
|
117
116
|
: null;
|
|
118
|
-
|
|
117
|
+
const total = await crud.count(table, { where: query.where });
|
|
118
|
+
return { items, nextCursor, hasMore, total };
|
|
119
119
|
},
|
|
120
120
|
async list(table, query) {
|
|
121
121
|
return crud.search(table, query);
|
|
122
122
|
},
|
|
123
|
+
async count(table, query = {}) {
|
|
124
|
+
assertString(table, "table");
|
|
125
|
+
const tbl = quoteIdent(table);
|
|
126
|
+
const where = compileWhere(resolveWhere(query.where));
|
|
127
|
+
const sql = `SELECT COUNT(*) AS ${quoteIdent("row_count")} FROM ${tbl}` +
|
|
128
|
+
(where.sql ? ` WHERE ${where.sql}` : "");
|
|
129
|
+
const row = await ex.get(sql, where.args);
|
|
130
|
+
return Number(row?.row_count ?? 0);
|
|
131
|
+
},
|
|
123
132
|
async upsert(table, cols) {
|
|
124
133
|
assertString(table, "table");
|
|
125
134
|
if (cols == null || typeof cols !== "object" || Array.isArray(cols)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DeleteQuery, type DuplicateQuery, type ReadQuery, type Row, type SearchQuery, type SearchResult, type UpdateQuery } from "../index.js";
|
|
1
|
+
import { type CountQuery, type DeleteQuery, type DuplicateQuery, type ReadQuery, type Row, type SearchQuery, type SearchResult, type UpdateQuery } from "../index.js";
|
|
2
2
|
export type SyncSqliteExecutor = {
|
|
3
3
|
run(sql: string, args?: unknown[]): {
|
|
4
4
|
changes: number;
|
|
@@ -21,6 +21,7 @@ export type SyncSqliteCrud<TDb> = {
|
|
|
21
21
|
bulkUpsert(table: string, rows: Record<string, unknown>[]): number;
|
|
22
22
|
search<T extends Row = Row>(table: string, query?: SearchQuery): SearchResult<T>;
|
|
23
23
|
list<T extends Row = Row>(table: string, query?: SearchQuery): SearchResult<T>;
|
|
24
|
+
count(table: string, query?: CountQuery): number;
|
|
24
25
|
transaction<T>(fn: () => T): T;
|
|
25
26
|
};
|
|
26
27
|
export declare function createSyncSqliteCrud<TDb>(db: TDb, ex: SyncSqliteExecutor): SyncSqliteCrud<TDb>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-crud.d.ts","sourceRoot":"","sources":["../../src/sqlite/sync-crud.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,GAAG,EACR,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,aAAa,CAAA;AAGpB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IACvD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,GAAG,GAAG,SAAS,CAAA;IACnD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,GAAG,EAAE,CAAA;IACzC,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,cAAc,CAAC,GAAG,IAAI;IAChC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAA;IAChB,MAAM,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,EAAE,KAAK,EA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;IAClE,MAAM,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;IAChF,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;IAC9E,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,MAAM,CAAA;IAChD,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;CAC/B,CAAA;AAoBD,wBAAgB,oBAAoB,CAAC,GAAG,EACtC,EAAE,EAAE,GAAG,EACP,EAAE,EAAE,kBAAkB,GACrB,cAAc,CAAC,GAAG,CAAC,CAuQrB"}
|
package/dist/sqlite/sync-crud.js
CHANGED
|
@@ -115,11 +115,21 @@ export function createSyncSqliteCrud(db, ex) {
|
|
|
115
115
|
const nextCursor = hasMore && last != null && (typeof last.id === "number" || typeof last.id === "string")
|
|
116
116
|
? last.id
|
|
117
117
|
: null;
|
|
118
|
-
|
|
118
|
+
const total = crud.count(table, { where: query.where });
|
|
119
|
+
return { items, nextCursor, hasMore, total };
|
|
119
120
|
},
|
|
120
121
|
list(table, query) {
|
|
121
122
|
return crud.search(table, query);
|
|
122
123
|
},
|
|
124
|
+
count(table, query = {}) {
|
|
125
|
+
assertString(table, "table");
|
|
126
|
+
const tbl = quoteIdent(table);
|
|
127
|
+
const where = compileWhere(resolveWhere(query.where));
|
|
128
|
+
const sql = `SELECT COUNT(*) AS ${quoteIdent("row_count")} FROM ${tbl}` +
|
|
129
|
+
(where.sql ? ` WHERE ${where.sql}` : "");
|
|
130
|
+
const row = ex.get(sql, where.args);
|
|
131
|
+
return Number(row?.row_count ?? 0);
|
|
132
|
+
},
|
|
123
133
|
upsert(table, cols) {
|
|
124
134
|
assertString(table, "table");
|
|
125
135
|
if (cols == null || typeof cols !== "object" || Array.isArray(cols)) {
|
package/dist/types.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type SearchResult<T = Row> = {
|
|
|
4
4
|
items: T[];
|
|
5
5
|
nextCursor: number | string | null;
|
|
6
6
|
hasMore: boolean;
|
|
7
|
+
/** Rows matching `where` (ignores limit/cursor). */
|
|
8
|
+
total: number;
|
|
7
9
|
};
|
|
8
10
|
export type WhereInput = WhereBuilder | WhereNode;
|
|
9
11
|
export type ReadQuery = {
|
|
@@ -17,6 +19,9 @@ export type SearchQuery = {
|
|
|
17
19
|
/** Raw `id` cursor (keyset). */
|
|
18
20
|
cursor?: number | string | null;
|
|
19
21
|
};
|
|
22
|
+
export type CountQuery = {
|
|
23
|
+
where?: WhereInput;
|
|
24
|
+
};
|
|
20
25
|
export type DeleteQuery = {
|
|
21
26
|
where: WhereInput;
|
|
22
27
|
};
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI;IAClC,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAClC,OAAO,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI;IAClC,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAClC,OAAO,EAAE,OAAO,CAAA;IAChB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,SAAS,CAAA;AAEjD,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,UAAU,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b4moss/crudian",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "CRUD abstraction for DDD repositories",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"types": "./dist/prisma/index.d.ts",
|
|
26
26
|
"import": "./dist/prisma/index.js",
|
|
27
27
|
"default": "./dist/prisma/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./libsql": {
|
|
30
|
+
"types": "./dist/libsql/index.d.ts",
|
|
31
|
+
"import": "./dist/libsql/index.js",
|
|
32
|
+
"default": "./dist/libsql/index.js"
|
|
28
33
|
}
|
|
29
34
|
},
|
|
30
35
|
"files": [
|
|
@@ -36,21 +41,26 @@
|
|
|
36
41
|
"build": "tsc -p tsconfig.json",
|
|
37
42
|
"prepublishOnly": "npm run build",
|
|
38
43
|
"prisma:generate": "prisma generate --schema prisma/schema.prisma",
|
|
39
|
-
"test": "bun run test:bun-sqlite && bun run test:drizzle && bun run test:prisma",
|
|
44
|
+
"test": "bun run test:bun-sqlite && bun run test:drizzle && bun run test:prisma && bun run test:libsql",
|
|
40
45
|
"test:bun-sqlite": "bun test src/bun-sqlite",
|
|
41
46
|
"test:drizzle": "tsx --test src/drizzle/crud.test.ts",
|
|
42
|
-
"test:prisma": "bun run prisma:generate && tsx --test src/prisma/crud.test.ts"
|
|
47
|
+
"test:prisma": "bun run prisma:generate && tsx --test src/prisma/crud.test.ts",
|
|
48
|
+
"test:libsql": "tsx --test src/libsql/crud.test.ts"
|
|
43
49
|
},
|
|
44
50
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
51
|
+
"node": ">=24",
|
|
46
52
|
"bun": ">=1.0.0"
|
|
47
53
|
},
|
|
48
54
|
"peerDependencies": {
|
|
55
|
+
"@libsql/client": "^0.14.0 || ^0.15.0 || ^0.17.0",
|
|
49
56
|
"@prisma/client": "^6.0.0",
|
|
50
57
|
"better-sqlite3": "^11.0.0",
|
|
51
58
|
"drizzle-orm": "^0.39.0 || ^0.40.0 || ^0.41.0 || ^0.44.0"
|
|
52
59
|
},
|
|
53
60
|
"peerDependenciesMeta": {
|
|
61
|
+
"@libsql/client": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
54
64
|
"@prisma/client": {
|
|
55
65
|
"optional": true
|
|
56
66
|
},
|
|
@@ -62,9 +72,10 @@
|
|
|
62
72
|
}
|
|
63
73
|
},
|
|
64
74
|
"devDependencies": {
|
|
75
|
+
"@libsql/client": "^0.17.4",
|
|
65
76
|
"@prisma/client": "^6.14.0",
|
|
66
77
|
"@types/better-sqlite3": "^7.6.13",
|
|
67
|
-
"better-sqlite3": "^
|
|
78
|
+
"better-sqlite3": "^13",
|
|
68
79
|
"bun-types": "^1.2.0",
|
|
69
80
|
"drizzle-orm": "^0.44.4",
|
|
70
81
|
"prisma": "^6.14.0",
|
|
@@ -78,6 +89,7 @@
|
|
|
78
89
|
"bun",
|
|
79
90
|
"drizzle",
|
|
80
91
|
"prisma",
|
|
92
|
+
"libsql",
|
|
81
93
|
"ddd"
|
|
82
94
|
],
|
|
83
95
|
"repository": {
|