d1-kyt 0.9.3 → 0.9.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 +29 -14
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,28 +3,43 @@
|
|
|
3
3
|
Type-safe [Cloudflare D1](https://developers.cloudflare.com/d1/) toolkit built on [Kysely](https://kysely.dev/) and [Valibot](https://valibot.dev/). Define your schema once in Valibot — get SQL migrations and fully-typed queries with no code generation.
|
|
4
4
|
|
|
5
5
|
```typescript
|
|
6
|
-
import { defineTable, InferDB, createQueryBuilder } from 'd1-kyt';
|
|
7
|
-
import { queryAll, queryFirst, queryRun } from 'd1-kyt';
|
|
6
|
+
import { defineTable, InferDB, createQueryBuilder, queryAll, queryFirst, queryRun } from 'd1-kyt';
|
|
8
7
|
import * as v from 'valibot';
|
|
9
8
|
|
|
9
|
+
export const users = defineTable('users', {
|
|
10
|
+
email: v.string(),
|
|
11
|
+
verified: v.boolean(), // stored 0/1 → returned as boolean
|
|
12
|
+
prefs: v.object({ theme: v.string() }), // stored as JSON → returned as object
|
|
13
|
+
});
|
|
14
|
+
|
|
10
15
|
export const posts = defineTable('posts', {
|
|
11
|
-
title:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
categoryId: v.optional(v.pipe(v.number(), v.integer())),
|
|
15
|
-
meta: v.object({ og: v.string() }), // stored as JSON
|
|
16
|
+
title: v.string(),
|
|
17
|
+
views: v.pipe(v.number(), v.integer()),
|
|
18
|
+
authorId: v.pipe(v.number(), v.integer()),
|
|
16
19
|
}, {
|
|
17
|
-
foreignKeys: [{ columns: ['
|
|
18
|
-
indexes:
|
|
20
|
+
foreignKeys: [{ columns: ['authorId'], references: users }],
|
|
21
|
+
indexes: [{ columns: ['title'], unique: true }],
|
|
19
22
|
});
|
|
20
23
|
|
|
21
|
-
export type DB = InferDB<{ posts: typeof posts }>;
|
|
24
|
+
export type DB = InferDB<{ users: typeof users; posts: typeof posts }>;
|
|
22
25
|
export const db = createQueryBuilder<DB>();
|
|
23
26
|
|
|
24
|
-
//
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
// prefs is { theme: string }, verified is boolean — deserialized automatically
|
|
28
|
+
const verified = await queryAll(
|
|
29
|
+
env.DB,
|
|
30
|
+
db.selectFrom('users').selectAll().where('verified', '=', true).compile(),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// full Kysely — joins, subqueries, window functions, all type-checked
|
|
34
|
+
const popular = await queryFirst(
|
|
35
|
+
env.DB,
|
|
36
|
+
db.selectFrom('posts')
|
|
37
|
+
.innerJoin('users', 'users.id', 'posts.authorId')
|
|
38
|
+
.select(['posts.title', 'posts.views', 'users.email'])
|
|
39
|
+
.where('posts.views', '>', 1000)
|
|
40
|
+
.orderBy('posts.views', 'desc')
|
|
41
|
+
.compile(),
|
|
42
|
+
);
|
|
28
43
|
```
|
|
29
44
|
|
|
30
45
|
## Install
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
|
-
const VERSION = '0.9.
|
|
4
|
+
const VERSION = '0.9.4';
|
|
5
5
|
const HELP = `
|
|
6
6
|
d1-kyt v${VERSION} - Opinionated Cloudflare D1 + Kysely toolkit
|
|
7
7
|
|