d1-kyt 0.3.2 → 0.3.3
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 +37 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,42 +26,6 @@ export const migration = () => [
|
|
|
26
26
|
];
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
### Customizing Auto Columns
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
// Disable all auto columns
|
|
33
|
-
const Event = defineTable('Event', (col) => ({
|
|
34
|
-
uuid: col.text().notNull(),
|
|
35
|
-
name: col.text().notNull(),
|
|
36
|
-
}), { primaryKey: false, createdAt: false, updatedAt: false });
|
|
37
|
-
|
|
38
|
-
// Custom column names (snake_case)
|
|
39
|
-
const User = defineTable('user', (col) => ({
|
|
40
|
-
email: col.text().notNull(),
|
|
41
|
-
}), {
|
|
42
|
-
primaryKeyColumn: 'user_id',
|
|
43
|
-
createdAtColumn: 'created_at',
|
|
44
|
-
updatedAtColumn: 'updated_at',
|
|
45
|
-
});
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Later Migrations
|
|
49
|
-
|
|
50
|
-
Use `createUseTable` for type-safe references to existing tables:
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
import type { DB } from '../../db/generated';
|
|
54
|
-
import { createUseTable, addColumn, createIndex } from 'd1-kyt/migrate';
|
|
55
|
-
|
|
56
|
-
const useTable = createUseTable<DB>();
|
|
57
|
-
const User = useTable('User');
|
|
58
|
-
|
|
59
|
-
export const migration = () => [
|
|
60
|
-
addColumn(User, 'age', (col) => col.integer()),
|
|
61
|
-
createIndex(User, ['age']),
|
|
62
|
-
];
|
|
63
|
-
```
|
|
64
|
-
|
|
65
29
|
## Query Builder
|
|
66
30
|
|
|
67
31
|
```typescript
|
|
@@ -81,7 +45,7 @@ export const insertUser = (email: string, name: string) =>
|
|
|
81
45
|
db.insertInto('User').values({ email, name }).returning(['id']).compile();
|
|
82
46
|
```
|
|
83
47
|
|
|
84
|
-
|
|
48
|
+
## Execute Queries
|
|
85
49
|
|
|
86
50
|
```typescript
|
|
87
51
|
// src/app.ts
|
|
@@ -109,6 +73,42 @@ app.post('/users', async (c) => {
|
|
|
109
73
|
});
|
|
110
74
|
```
|
|
111
75
|
|
|
76
|
+
## Customizing Auto Columns
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// Disable all auto columns
|
|
80
|
+
const Event = defineTable('Event', (col) => ({
|
|
81
|
+
uuid: col.text().notNull(),
|
|
82
|
+
name: col.text().notNull(),
|
|
83
|
+
}), { primaryKey: false, createdAt: false, updatedAt: false });
|
|
84
|
+
|
|
85
|
+
// Custom column names (snake_case)
|
|
86
|
+
const User = defineTable('user', (col) => ({
|
|
87
|
+
email: col.text().notNull(),
|
|
88
|
+
}), {
|
|
89
|
+
primaryKeyColumn: 'user_id',
|
|
90
|
+
createdAtColumn: 'created_at',
|
|
91
|
+
updatedAtColumn: 'updated_at',
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Later Migrations
|
|
96
|
+
|
|
97
|
+
Use `createUseTable` for type-safe references to existing tables:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import type { DB } from '../../db/generated';
|
|
101
|
+
import { createUseTable, addColumn, createIndex } from 'd1-kyt/migrate';
|
|
102
|
+
|
|
103
|
+
const useTable = createUseTable<DB>();
|
|
104
|
+
const User = useTable('User');
|
|
105
|
+
|
|
106
|
+
export const migration = () => [
|
|
107
|
+
addColumn(User, 'age', (col) => col.integer()),
|
|
108
|
+
createIndex(User, ['age']),
|
|
109
|
+
];
|
|
110
|
+
```
|
|
111
|
+
|
|
112
112
|
## Install
|
|
113
113
|
|
|
114
114
|
```bash
|