@kood/claude-code 0.3.7 → 0.3.9
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/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/.claude/agents/code-reviewer.md +138 -123
- package/templates/.claude/agents/dependency-manager.md +99 -84
- package/templates/.claude/agents/deployment-validator.md +70 -55
- package/templates/.claude/agents/git-operator.md +78 -63
- package/templates/.claude/agents/implementation-executor.md +109 -94
- package/templates/.claude/agents/ko-to-en-translator.md +74 -0
- package/templates/.claude/agents/lint-fixer.md +93 -78
- package/templates/.claude/agents/refactor-advisor.md +136 -121
- package/templates/.claude/commands/agent-creator.md +199 -184
- package/templates/.claude/commands/bug-fix.md +207 -192
- package/templates/.claude/commands/command-creator.md +69 -53
- package/templates/.claude/commands/docs-creator.md +72 -56
- package/templates/.claude/commands/docs-refactor.md +41 -25
- package/templates/.claude/commands/execute.md +27 -11
- package/templates/.claude/commands/git-all.md +46 -31
- package/templates/.claude/commands/git-session.md +57 -41
- package/templates/.claude/commands/git.md +49 -33
- package/templates/.claude/commands/lint-fix.md +153 -137
- package/templates/.claude/commands/lint-init.md +76 -60
- package/templates/.claude/commands/plan.md +275 -259
- package/templates/.claude/commands/prd.md +39 -23
- package/templates/.claude/commands/pre-deploy.md +124 -108
- package/templates/.claude/commands/refactor.md +162 -146
- package/templates/.claude/commands/version-update.md +32 -16
- package/templates/hono/CLAUDE.md +28 -27
- package/templates/hono/docs/architecture.md +24 -24
- package/templates/hono/docs/deployment/cloudflare.md +18 -18
- package/templates/hono/docs/deployment/docker.md +13 -13
- package/templates/hono/docs/deployment/index.md +19 -19
- package/templates/hono/docs/deployment/railway.md +32 -32
- package/templates/hono/docs/deployment/vercel.md +29 -29
- package/templates/hono/docs/guides/conventions.md +57 -57
- package/templates/hono/docs/guides/env-setup.md +47 -47
- package/templates/hono/docs/guides/getting-started.md +27 -27
- package/templates/hono/docs/library/hono/error-handling.md +11 -11
- package/templates/hono/docs/library/hono/index.md +4 -4
- package/templates/hono/docs/library/hono/middleware.md +18 -18
- package/templates/hono/docs/library/hono/rpc.md +7 -7
- package/templates/hono/docs/library/hono/validation.md +6 -6
- package/templates/hono/docs/library/prisma/cloudflare-d1.md +29 -29
- package/templates/hono/docs/library/prisma/config.md +16 -16
- package/templates/hono/docs/library/prisma/index.md +32 -32
- package/templates/hono/docs/library/t3-env/index.md +22 -22
- package/templates/hono/docs/library/zod/index.md +31 -31
- package/templates/nextjs/CLAUDE.md +54 -51
- package/templates/nextjs/docs/architecture.md +812 -0
- package/templates/nextjs/docs/design.md +183 -183
- package/templates/nextjs/docs/guides/conventions.md +86 -86
- package/templates/nextjs/docs/guides/getting-started.md +28 -28
- package/templates/nextjs/docs/guides/routes.md +32 -32
- package/templates/nextjs/docs/library/better-auth/index.md +70 -70
- package/templates/nextjs/docs/library/nextjs/app-router.md +43 -43
- package/templates/nextjs/docs/library/nextjs/caching.md +73 -73
- package/templates/nextjs/docs/library/nextjs/index.md +51 -51
- package/templates/nextjs/docs/library/nextjs/middleware.md +41 -41
- package/templates/nextjs/docs/library/nextjs/route-handlers.md +31 -31
- package/templates/nextjs/docs/library/nextjs/server-actions.md +34 -34
- package/templates/nextjs/docs/library/prisma/cloudflare-d1.md +20 -20
- package/templates/nextjs/docs/library/prisma/config.md +18 -18
- package/templates/nextjs/docs/library/prisma/crud.md +17 -17
- package/templates/nextjs/docs/library/prisma/index.md +18 -18
- package/templates/nextjs/docs/library/prisma/relations.md +16 -16
- package/templates/nextjs/docs/library/prisma/schema.md +23 -23
- package/templates/nextjs/docs/library/prisma/setup.md +6 -6
- package/templates/nextjs/docs/library/prisma/transactions.md +10 -10
- package/templates/nextjs/docs/library/tanstack-query/index.md +6 -6
- package/templates/nextjs/docs/library/tanstack-query/invalidation.md +20 -20
- package/templates/nextjs/docs/library/tanstack-query/optimistic-updates.md +4 -4
- package/templates/nextjs/docs/library/tanstack-query/use-mutation.md +15 -15
- package/templates/nextjs/docs/library/tanstack-query/use-query.md +22 -22
- package/templates/nextjs/docs/library/zod/complex-types.md +11 -11
- package/templates/nextjs/docs/library/zod/index.md +8 -8
- package/templates/nextjs/docs/library/zod/transforms.md +11 -11
- package/templates/nextjs/docs/library/zod/validation.md +9 -9
- package/templates/npx/CLAUDE.md +38 -37
- package/templates/npx/docs/library/commander/index.md +12 -12
- package/templates/npx/docs/library/fs-extra/index.md +9 -9
- package/templates/npx/docs/library/prompts/index.md +3 -3
- package/templates/npx/docs/references/patterns.md +12 -12
- package/templates/tanstack-start/CLAUDE.md +54 -53
- package/templates/tanstack-start/docs/architecture.md +128 -128
- package/templates/tanstack-start/docs/design.md +169 -169
- package/templates/tanstack-start/docs/guides/conventions.md +43 -43
- package/templates/tanstack-start/docs/guides/env-setup.md +35 -35
- package/templates/tanstack-start/docs/guides/getting-started.md +19 -19
- package/templates/tanstack-start/docs/guides/hooks.md +45 -45
- package/templates/tanstack-start/docs/guides/routes.md +54 -54
- package/templates/tanstack-start/docs/guides/services.md +45 -45
- package/templates/tanstack-start/docs/library/better-auth/index.md +68 -68
- package/templates/tanstack-start/docs/library/prisma/cloudflare-d1.md +19 -19
- package/templates/tanstack-start/docs/library/prisma/config.md +16 -16
- package/templates/tanstack-start/docs/library/prisma/crud.md +17 -17
- package/templates/tanstack-start/docs/library/prisma/index.md +17 -17
- package/templates/tanstack-start/docs/library/prisma/relations.md +16 -16
- package/templates/tanstack-start/docs/library/prisma/schema.md +23 -23
- package/templates/tanstack-start/docs/library/prisma/setup.md +6 -6
- package/templates/tanstack-start/docs/library/prisma/transactions.md +10 -10
- package/templates/tanstack-start/docs/library/t3-env/index.md +21 -160
- package/templates/tanstack-start/docs/library/tanstack-query/index.md +6 -6
- package/templates/tanstack-start/docs/library/tanstack-query/invalidation.md +19 -19
- package/templates/tanstack-start/docs/library/tanstack-query/optimistic-updates.md +4 -4
- package/templates/tanstack-start/docs/library/tanstack-query/use-mutation.md +14 -14
- package/templates/tanstack-start/docs/library/tanstack-query/use-query.md +21 -21
- package/templates/tanstack-start/docs/library/tanstack-router/error-handling.md +9 -9
- package/templates/tanstack-start/docs/library/tanstack-router/hooks.md +11 -11
- package/templates/tanstack-start/docs/library/tanstack-router/index.md +18 -18
- package/templates/tanstack-start/docs/library/tanstack-router/navigation.md +17 -17
- package/templates/tanstack-start/docs/library/tanstack-router/route-context.md +5 -5
- package/templates/tanstack-start/docs/library/tanstack-router/search-params.md +10 -10
- package/templates/tanstack-start/docs/library/tanstack-start/auth-patterns.md +8 -8
- package/templates/tanstack-start/docs/library/tanstack-start/index.md +15 -15
- package/templates/tanstack-start/docs/library/tanstack-start/middleware.md +9 -9
- package/templates/tanstack-start/docs/library/tanstack-start/routing.md +6 -6
- package/templates/tanstack-start/docs/library/tanstack-start/server-functions.md +18 -18
- package/templates/tanstack-start/docs/library/tanstack-start/setup.md +4 -4
- package/templates/tanstack-start/docs/library/zod/complex-types.md +11 -11
- package/templates/tanstack-start/docs/library/zod/index.md +8 -8
- package/templates/tanstack-start/docs/library/zod/transforms.md +11 -11
- package/templates/tanstack-start/docs/library/zod/validation.md +9 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Hono
|
|
1
|
+
# Hono Error Handling
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Systematic error management with HTTPException and onError
|
|
4
4
|
|
|
5
5
|
<patterns>
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ app.get('/users/:id', async (c) => {
|
|
|
20
20
|
})
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Global Handler
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { Hono } from 'hono'
|
|
@@ -43,7 +43,7 @@ app.notFound((c) => {
|
|
|
43
43
|
})
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
##
|
|
46
|
+
## Detailed Response
|
|
47
47
|
|
|
48
48
|
```typescript
|
|
49
49
|
app.onError((err, c) => {
|
|
@@ -69,7 +69,7 @@ app.onError((err, c) => {
|
|
|
69
69
|
})
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
##
|
|
72
|
+
## Custom Error Classes
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
75
|
// lib/errors.ts
|
|
@@ -95,7 +95,7 @@ export class ConflictError extends HTTPException {
|
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
```typescript
|
|
98
|
-
//
|
|
98
|
+
// Usage
|
|
99
99
|
import { NotFoundError, ConflictError } from '@/lib/errors'
|
|
100
100
|
|
|
101
101
|
app.get('/users/:id', async (c) => {
|
|
@@ -117,13 +117,13 @@ app.post('/users', async (c) => {
|
|
|
117
117
|
|
|
118
118
|
<status_codes>
|
|
119
119
|
|
|
120
|
-
|
|
|
121
|
-
|
|
120
|
+
| Code | Usage |
|
|
121
|
+
|------|-------|
|
|
122
122
|
| 400 | Invalid input |
|
|
123
|
-
| 401 | Unauthorized (
|
|
124
|
-
| 403 | Access denied (
|
|
123
|
+
| 401 | Unauthorized (authentication required) |
|
|
124
|
+
| 403 | Access denied (insufficient permissions) |
|
|
125
125
|
| 404 | Not found |
|
|
126
|
-
| 409 | Already exists (
|
|
126
|
+
| 409 | Already exists (conflict) |
|
|
127
127
|
| 422 | Validation failed |
|
|
128
128
|
| 429 | Rate limit exceeded |
|
|
129
129
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Hono
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Ultra-lightweight framework based on Web Standards
|
|
4
4
|
|
|
5
5
|
<references>
|
|
6
6
|
@middleware.md
|
|
@@ -21,7 +21,7 @@ npm install hono
|
|
|
21
21
|
|
|
22
22
|
<quick_patterns>
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## Routes
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
27
|
import { Hono } from 'hono'
|
|
@@ -39,7 +39,7 @@ app.get('/posts/:postId/comments/:commentId', (c) => {
|
|
|
39
39
|
export default app
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
##
|
|
42
|
+
## Route Groups
|
|
43
43
|
|
|
44
44
|
```typescript
|
|
45
45
|
const users = new Hono()
|
|
@@ -99,7 +99,7 @@ type Variables = {
|
|
|
99
99
|
|
|
100
100
|
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>()
|
|
101
101
|
|
|
102
|
-
//
|
|
102
|
+
// Environment variables
|
|
103
103
|
app.get('/', (c) => {
|
|
104
104
|
const dbUrl = c.env.DATABASE_URL
|
|
105
105
|
return c.json({ connected: true })
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# Hono
|
|
1
|
+
# Hono Middleware
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Request/Response processing pipeline
|
|
4
4
|
|
|
5
5
|
<patterns>
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Basic Usage
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
10
|
import { Hono } from 'hono'
|
|
@@ -13,25 +13,25 @@ import { cors } from 'hono/cors'
|
|
|
13
13
|
|
|
14
14
|
const app = new Hono()
|
|
15
15
|
|
|
16
|
-
app.use(logger()) //
|
|
17
|
-
app.use('/api/*', cors()) //
|
|
16
|
+
app.use(logger()) // All routes
|
|
17
|
+
app.use('/api/*', cors()) // Specific path
|
|
18
18
|
|
|
19
|
-
//
|
|
19
|
+
// Execution order
|
|
20
20
|
app.use(async (c, next) => {
|
|
21
|
-
console.log('1.
|
|
21
|
+
console.log('1. Before request')
|
|
22
22
|
await next()
|
|
23
|
-
console.log('4.
|
|
23
|
+
console.log('4. After response')
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
app.use(async (c, next) => {
|
|
27
|
-
console.log('2.
|
|
27
|
+
console.log('2. Before request')
|
|
28
28
|
await next()
|
|
29
|
-
console.log('3.
|
|
29
|
+
console.log('3. After response')
|
|
30
30
|
})
|
|
31
|
-
//
|
|
31
|
+
// Output: 1 → 2 → handler → 3 → 4
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## Custom Middleware
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { createMiddleware } from 'hono/factory'
|
|
@@ -51,13 +51,13 @@ export const authMiddleware = createMiddleware<Env>(async (c, next) => {
|
|
|
51
51
|
await next()
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
//
|
|
54
|
+
// Usage
|
|
55
55
|
app.get('/me', authMiddleware, (c) => {
|
|
56
56
|
return c.json({ userId: c.get('userId') })
|
|
57
57
|
})
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
##
|
|
60
|
+
## Type-safe Middleware
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
63
|
import { Hono } from 'hono'
|
|
@@ -84,8 +84,8 @@ app.use(dbMiddleware)
|
|
|
84
84
|
app.use(authMiddleware)
|
|
85
85
|
|
|
86
86
|
app.get('/users', (c) => {
|
|
87
|
-
const db = c.get('db') // Database
|
|
88
|
-
const user = c.get('user') // User | null
|
|
87
|
+
const db = c.get('db') // Database type
|
|
88
|
+
const user = c.get('user') // User | null type
|
|
89
89
|
return c.json({ users: [] })
|
|
90
90
|
})
|
|
91
91
|
```
|
|
@@ -96,8 +96,8 @@ app.get('/users', (c) => {
|
|
|
96
96
|
|
|
97
97
|
<builtin>
|
|
98
98
|
|
|
99
|
-
|
|
|
100
|
-
|
|
99
|
+
| Middleware | Usage |
|
|
100
|
+
|------------|-------|
|
|
101
101
|
| **logger** | `app.use(logger())` |
|
|
102
102
|
| **cors** | `app.use('/api/*', cors({ origin: ['https://example.com'] }))` |
|
|
103
103
|
| **bearerAuth** | `app.use('/api/*', bearerAuth({ verifyToken: async (t) => t === 'valid' }))` |
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Hono RPC Client
|
|
2
2
|
|
|
3
|
-
> Type-safe API
|
|
3
|
+
> Type-safe API calls
|
|
4
4
|
|
|
5
5
|
<patterns>
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Server Setup
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
10
|
// server.ts
|
|
@@ -26,11 +26,11 @@ const app = new Hono()
|
|
|
26
26
|
}
|
|
27
27
|
)
|
|
28
28
|
|
|
29
|
-
export type AppType = typeof app // ✅
|
|
29
|
+
export type AppType = typeof app // ✅ Required
|
|
30
30
|
export default app
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Client
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
36
|
// client.ts
|
|
@@ -75,7 +75,7 @@ const client = hc<AppType>('http://localhost:8787/', {
|
|
|
75
75
|
})
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
##
|
|
78
|
+
## Type Inference
|
|
79
79
|
|
|
80
80
|
```typescript
|
|
81
81
|
import type { InferRequestType, InferResponseType } from 'hono/client'
|
|
@@ -87,7 +87,7 @@ type UserResponse = InferResponseType<typeof client.users[':id'].$get>
|
|
|
87
87
|
// { id: string; name: string }
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
## CRUD
|
|
90
|
+
## CRUD Wrapper
|
|
91
91
|
|
|
92
92
|
```typescript
|
|
93
93
|
const userApi = {
|
|
@@ -117,7 +117,7 @@ const userApi = {
|
|
|
117
117
|
},
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
// URL
|
|
120
|
+
// URL generation
|
|
121
121
|
const url = client.posts[':id'].$url({ param: { id: '123' } })
|
|
122
122
|
console.log(url.pathname) // /posts/123
|
|
123
123
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Hono + Zod
|
|
1
|
+
# Hono + Zod Validation
|
|
2
2
|
|
|
3
|
-
> @hono/zod-validator
|
|
3
|
+
> Type-safe request validation with @hono/zod-validator
|
|
4
4
|
|
|
5
5
|
<setup>
|
|
6
6
|
```bash
|
|
@@ -54,7 +54,7 @@ app.get('/users/:id',
|
|
|
54
54
|
}
|
|
55
55
|
)
|
|
56
56
|
|
|
57
|
-
// Header (
|
|
57
|
+
// Header (lowercase!)
|
|
58
58
|
app.get('/api/protected',
|
|
59
59
|
zValidator('header', z.object({ 'x-api-key': z.string().uuid() })),
|
|
60
60
|
(c) => {
|
|
@@ -63,7 +63,7 @@ app.get('/api/protected',
|
|
|
63
63
|
)
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
##
|
|
66
|
+
## Multiple Validators
|
|
67
67
|
|
|
68
68
|
```typescript
|
|
69
69
|
app.post(
|
|
@@ -80,7 +80,7 @@ app.post(
|
|
|
80
80
|
)
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
##
|
|
83
|
+
## Custom Errors
|
|
84
84
|
|
|
85
85
|
```typescript
|
|
86
86
|
app.post(
|
|
@@ -100,7 +100,7 @@ app.post(
|
|
|
100
100
|
)
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
##
|
|
103
|
+
## Reusable Schemas
|
|
104
104
|
|
|
105
105
|
```typescript
|
|
106
106
|
// validators/user.ts
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Prisma - Cloudflare D1
|
|
2
2
|
|
|
3
|
-
> SQLite
|
|
3
|
+
> SQLite-based serverless database
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Caveats
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
D1
|
|
11
|
-
prisma migrate dev
|
|
12
|
-
Prisma ORM D1
|
|
10
|
+
D1 does not support transactions (no ACID guarantees)
|
|
11
|
+
prisma migrate dev not available → use wrangler CLI
|
|
12
|
+
Prisma ORM D1 support is in Preview
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
---
|
|
@@ -22,11 +22,11 @@ Prisma ORM D1 지원은 Preview 상태
|
|
|
22
22
|
generator client {
|
|
23
23
|
provider = "prisma-client"
|
|
24
24
|
output = "../src/generated/prisma"
|
|
25
|
-
runtime = "cloudflare" // D1
|
|
25
|
+
runtime = "cloudflare" // Required for D1
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
datasource db {
|
|
29
|
-
provider = "sqlite" // D1
|
|
29
|
+
provider = "sqlite" // D1 is SQLite-based
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
model User {
|
|
@@ -59,7 +59,7 @@ export default app
|
|
|
59
59
|
|
|
60
60
|
---
|
|
61
61
|
|
|
62
|
-
##
|
|
62
|
+
## Installation
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
65
|
npm install hono @prisma/client @prisma/adapter-d1
|
|
@@ -69,7 +69,7 @@ npx prisma init --datasource-provider sqlite
|
|
|
69
69
|
|
|
70
70
|
---
|
|
71
71
|
|
|
72
|
-
## D1
|
|
72
|
+
## Create D1 Database
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
75
|
npx wrangler d1 create my-database
|
|
@@ -93,29 +93,29 @@ npx wrangler d1 create my-database
|
|
|
93
93
|
|
|
94
94
|
---
|
|
95
95
|
|
|
96
|
-
##
|
|
96
|
+
## Migration Workflow
|
|
97
97
|
|
|
98
98
|
```bash
|
|
99
|
-
# 1.
|
|
99
|
+
# 1. Create migration file
|
|
100
100
|
npx wrangler d1 migrations create my-database create_user_table
|
|
101
101
|
|
|
102
|
-
# 2. SQL
|
|
102
|
+
# 2. Generate SQL (initial)
|
|
103
103
|
npx prisma migrate diff \
|
|
104
104
|
--from-empty \
|
|
105
105
|
--to-schema-datamodel prisma/schema.prisma \
|
|
106
106
|
--script \
|
|
107
107
|
--output prisma/migrations/0001_create_user_table.sql
|
|
108
108
|
|
|
109
|
-
# 3.
|
|
109
|
+
# 3. Apply locally
|
|
110
110
|
npx wrangler d1 migrations apply my-database --local
|
|
111
111
|
|
|
112
|
-
# 4.
|
|
112
|
+
# 4. Apply remotely
|
|
113
113
|
npx wrangler d1 migrations apply my-database --remote
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
---
|
|
117
117
|
|
|
118
|
-
##
|
|
118
|
+
## Complete CRUD API
|
|
119
119
|
|
|
120
120
|
```typescript
|
|
121
121
|
import { Hono } from 'hono'
|
|
@@ -130,7 +130,7 @@ type Variables = { prisma: PrismaClient }
|
|
|
130
130
|
|
|
131
131
|
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>()
|
|
132
132
|
|
|
133
|
-
// Prisma
|
|
133
|
+
// Prisma middleware
|
|
134
134
|
app.use('*', async (c, next) => {
|
|
135
135
|
const adapter = new PrismaD1(c.env.DB)
|
|
136
136
|
c.set('prisma', new PrismaClient({ adapter }))
|
|
@@ -161,20 +161,20 @@ export default app
|
|
|
161
161
|
|
|
162
162
|
---
|
|
163
163
|
|
|
164
|
-
##
|
|
164
|
+
## Local Development
|
|
165
165
|
|
|
166
166
|
```bash
|
|
167
|
-
#
|
|
167
|
+
# Run worker
|
|
168
168
|
npx wrangler dev
|
|
169
169
|
|
|
170
|
-
# D1
|
|
170
|
+
# Query D1
|
|
171
171
|
npx wrangler d1 execute my-database --local \
|
|
172
172
|
--command "SELECT * FROM User;"
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
---
|
|
176
176
|
|
|
177
|
-
##
|
|
177
|
+
## Deployment
|
|
178
178
|
|
|
179
179
|
```bash
|
|
180
180
|
npx prisma generate
|
|
@@ -184,17 +184,17 @@ npx wrangler deploy
|
|
|
184
184
|
|
|
185
185
|
---
|
|
186
186
|
|
|
187
|
-
##
|
|
187
|
+
## Limitations
|
|
188
188
|
|
|
189
|
-
|
|
|
190
|
-
|
|
191
|
-
|
|
|
192
|
-
|
|
|
193
|
-
|
|
|
189
|
+
| Feature | D1 |
|
|
190
|
+
|---------|-----|
|
|
191
|
+
| Transactions | ❌ Not supported |
|
|
192
|
+
| Migrations | Use wrangler |
|
|
193
|
+
| Connection | HTTP (adapter) |
|
|
194
194
|
|
|
195
195
|
---
|
|
196
196
|
|
|
197
|
-
##
|
|
197
|
+
## Related Documentation
|
|
198
198
|
|
|
199
|
-
- [Prisma
|
|
200
|
-
- [Cloudflare
|
|
199
|
+
- [Prisma Overview](./index.md)
|
|
200
|
+
- [Cloudflare Deployment](../../deployment/cloudflare.md)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# Prisma - Config
|
|
1
|
+
# Prisma - Config File
|
|
2
2
|
|
|
3
|
-
> prisma.config.ts
|
|
3
|
+
> prisma.config.ts configuration (v7)
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
## Multi-File
|
|
7
|
+
## Multi-File Schema Required Configuration
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
10
|
// prisma.config.ts
|
|
@@ -12,7 +12,7 @@ import path from 'node:path'
|
|
|
12
12
|
import { defineConfig, env } from 'prisma/config'
|
|
13
13
|
|
|
14
14
|
export default defineConfig({
|
|
15
|
-
schema: path.join('prisma', 'schema'), //
|
|
15
|
+
schema: path.join('prisma', 'schema'), // Folder path
|
|
16
16
|
datasource: {
|
|
17
17
|
url: env('DATABASE_URL'),
|
|
18
18
|
},
|
|
@@ -21,13 +21,13 @@ export default defineConfig({
|
|
|
21
21
|
|
|
22
22
|
---
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## File Location
|
|
25
25
|
|
|
26
26
|
```
|
|
27
|
-
|
|
28
|
-
├── prisma.config.ts #
|
|
27
|
+
project/
|
|
28
|
+
├── prisma.config.ts # Project root
|
|
29
29
|
├── prisma/
|
|
30
|
-
│ ├── schema/ # Multi-File
|
|
30
|
+
│ ├── schema/ # Multi-File schema
|
|
31
31
|
│ │ ├── +base.prisma
|
|
32
32
|
│ │ ├── +enum.prisma
|
|
33
33
|
│ │ └── user.prisma
|
|
@@ -37,7 +37,7 @@ export default defineConfig({
|
|
|
37
37
|
|
|
38
38
|
---
|
|
39
39
|
|
|
40
|
-
##
|
|
40
|
+
## Full Configuration Example
|
|
41
41
|
|
|
42
42
|
```typescript
|
|
43
43
|
// prisma.config.ts
|
|
@@ -69,14 +69,14 @@ datasource db {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
generator client {
|
|
72
|
-
provider = "prisma-client" // v7
|
|
72
|
+
provider = "prisma-client" // v7 required
|
|
73
73
|
output = "../../generated/prisma"
|
|
74
74
|
}
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
---
|
|
78
78
|
|
|
79
|
-
##
|
|
79
|
+
## Seed Script
|
|
80
80
|
|
|
81
81
|
```typescript
|
|
82
82
|
// prisma/seed.ts
|
|
@@ -86,7 +86,7 @@ const prisma = new PrismaClient()
|
|
|
86
86
|
|
|
87
87
|
async function main() {
|
|
88
88
|
await prisma.user.create({
|
|
89
|
-
data: { email: 'admin@example.com', name: '
|
|
89
|
+
data: { email: 'admin@example.com', name: 'Administrator' },
|
|
90
90
|
})
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -104,18 +104,18 @@ main()
|
|
|
104
104
|
generator client {
|
|
105
105
|
provider = "prisma-client"
|
|
106
106
|
output = "../../generated/prisma"
|
|
107
|
-
runtime = "workerd" // Workers
|
|
107
|
+
runtime = "workerd" // Workers runtime
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
datasource db {
|
|
111
|
-
provider = "sqlite" // D1
|
|
111
|
+
provider = "sqlite" // D1 is SQLite
|
|
112
112
|
url = env("DATABASE_URL")
|
|
113
113
|
}
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
---
|
|
117
117
|
|
|
118
|
-
##
|
|
118
|
+
## Related Documentation
|
|
119
119
|
|
|
120
|
-
- [Prisma
|
|
120
|
+
- [Prisma Overview](./index.md)
|
|
121
121
|
- [Cloudflare D1](./cloudflare-d1.md)
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
# Prisma v7 - Database ORM
|
|
2
2
|
|
|
3
|
-
> Type-safe
|
|
3
|
+
> Type-safe database ORM
|
|
4
4
|
|
|
5
5
|
@config.md
|
|
6
6
|
@cloudflare-d1.md
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Version Notice
|
|
11
11
|
|
|
12
12
|
```prisma
|
|
13
13
|
generator client {
|
|
14
|
-
provider = "prisma-client" // ✅ v7 (prisma-client-js
|
|
15
|
-
output = "./generated/client" // ✅ output
|
|
14
|
+
provider = "prisma-client" // ✅ v7 (not prisma-client-js!)
|
|
15
|
+
output = "./generated/client" // ✅ output required
|
|
16
16
|
}
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Prohibited Actions
|
|
22
22
|
|
|
23
|
-
|
|
|
24
|
-
|
|
25
|
-
| `prisma db push` |
|
|
26
|
-
| `prisma migrate` |
|
|
27
|
-
| `prisma generate` |
|
|
28
|
-
|
|
|
23
|
+
| Command | Description |
|
|
24
|
+
|---------|-------------|
|
|
25
|
+
| `prisma db push` | Do not auto-run |
|
|
26
|
+
| `prisma migrate` | Do not auto-run |
|
|
27
|
+
| `prisma generate` | Do not auto-run |
|
|
28
|
+
| Schema changes | Only as requested |
|
|
29
29
|
|
|
30
30
|
---
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## Installation
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
npm install prisma-client
|
|
@@ -38,20 +38,20 @@ npm install -D prisma
|
|
|
38
38
|
|
|
39
39
|
---
|
|
40
40
|
|
|
41
|
-
## Multi-File
|
|
41
|
+
## Multi-File Structure (Required)
|
|
42
42
|
|
|
43
43
|
```
|
|
44
44
|
prisma/schema/
|
|
45
45
|
├── +base.prisma # datasource, generator
|
|
46
|
-
├── +enum.prisma # enum
|
|
47
|
-
├── user.prisma # User
|
|
48
|
-
└── post.prisma # Post
|
|
46
|
+
├── +enum.prisma # enum definitions
|
|
47
|
+
├── user.prisma # User model (Korean comments required)
|
|
48
|
+
└── post.prisma # Post model
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
### +base.prisma
|
|
52
52
|
|
|
53
53
|
```prisma
|
|
54
|
-
// datasource, generator
|
|
54
|
+
// datasource, generator configuration
|
|
55
55
|
datasource db {
|
|
56
56
|
provider = "postgresql"
|
|
57
57
|
url = env("DATABASE_URL")
|
|
@@ -66,12 +66,12 @@ generator client {
|
|
|
66
66
|
### user.prisma
|
|
67
67
|
|
|
68
68
|
```prisma
|
|
69
|
-
//
|
|
69
|
+
// User model
|
|
70
70
|
model User {
|
|
71
71
|
id String @id @default(cuid())
|
|
72
|
-
email String @unique //
|
|
73
|
-
name String? //
|
|
74
|
-
posts Post[] //
|
|
72
|
+
email String @unique // Login email
|
|
73
|
+
name String? // Display name
|
|
74
|
+
posts Post[] // Authored posts
|
|
75
75
|
createdAt DateTime @default(now())
|
|
76
76
|
updatedAt DateTime @updatedAt
|
|
77
77
|
}
|
|
@@ -110,7 +110,7 @@ const user = await prisma.user.create({
|
|
|
110
110
|
data: { email: 'user@example.com', name: 'John' },
|
|
111
111
|
})
|
|
112
112
|
|
|
113
|
-
//
|
|
113
|
+
// With relations
|
|
114
114
|
const userWithPosts = await prisma.user.create({
|
|
115
115
|
data: {
|
|
116
116
|
email: 'user@example.com',
|
|
@@ -131,7 +131,7 @@ const users = await prisma.user.findMany({
|
|
|
131
131
|
take: 10,
|
|
132
132
|
})
|
|
133
133
|
|
|
134
|
-
//
|
|
134
|
+
// Include relations
|
|
135
135
|
const userWithPosts = await prisma.user.findUnique({
|
|
136
136
|
where: { id },
|
|
137
137
|
include: { posts: { where: { published: true } } },
|
|
@@ -163,24 +163,24 @@ await prisma.user.deleteMany({ where: { email: { contains: '@test.com' } } })
|
|
|
163
163
|
|
|
164
164
|
---
|
|
165
165
|
|
|
166
|
-
##
|
|
166
|
+
## Filtering
|
|
167
167
|
|
|
168
168
|
```typescript
|
|
169
169
|
await prisma.user.findMany({
|
|
170
170
|
where: {
|
|
171
|
-
age: { gt: 18, lte: 65 }, //
|
|
172
|
-
email: { contains: '@gmail.com' }, //
|
|
171
|
+
age: { gt: 18, lte: 65 }, // Comparison
|
|
172
|
+
email: { contains: '@gmail.com' }, // String
|
|
173
173
|
AND: [{ email: { contains: '@' } }, { name: { not: null } }],
|
|
174
174
|
OR: [{ role: 'admin' }, { role: 'moderator' }],
|
|
175
|
-
id: { in: ['id1', 'id2'] }, //
|
|
176
|
-
posts: { some: { published: true } }, //
|
|
175
|
+
id: { in: ['id1', 'id2'] }, // Array
|
|
176
|
+
posts: { some: { published: true } }, // Relations
|
|
177
177
|
},
|
|
178
178
|
})
|
|
179
179
|
```
|
|
180
180
|
|
|
181
181
|
---
|
|
182
182
|
|
|
183
|
-
##
|
|
183
|
+
## Transactions
|
|
184
184
|
|
|
185
185
|
```typescript
|
|
186
186
|
// Sequential
|
|
@@ -199,7 +199,7 @@ const result = await prisma.$transaction(async (tx) => {
|
|
|
199
199
|
|
|
200
200
|
---
|
|
201
201
|
|
|
202
|
-
##
|
|
202
|
+
## Usage with Hono
|
|
203
203
|
|
|
204
204
|
```typescript
|
|
205
205
|
import { Hono } from 'hono'
|
|
@@ -241,7 +241,7 @@ app.get('/users/:id', async (c) => {
|
|
|
241
241
|
|
|
242
242
|
---
|
|
243
243
|
|
|
244
|
-
##
|
|
244
|
+
## Related Documentation
|
|
245
245
|
|
|
246
|
-
- [Config
|
|
246
|
+
- [Config Files](./config.md) - prisma.config.ts configuration
|
|
247
247
|
- [Cloudflare D1](./cloudflare-d1.md)
|