nextjs-drizzle-gen 0.1.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/LICENSE +21 -0
- package/README.md +173 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1437 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# nextjs-drizzle-gen
|
|
2
|
+
|
|
3
|
+
Rails-like generators for Next.js + Drizzle ORM projects. Generate models, server actions, CRUD pages, and API routes with a single command.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g nextjs-drizzle-gen
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or use with npx:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx nextjs-drizzle-gen scaffold post title:string body:text
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Generate a full CRUD scaffold (model + actions + pages)
|
|
21
|
+
drizzle-gen scaffold post title:string body:text published:boolean
|
|
22
|
+
|
|
23
|
+
# Generate just model and actions (no views)
|
|
24
|
+
drizzle-gen resource user name:string email:string:unique
|
|
25
|
+
|
|
26
|
+
# Generate model and REST API routes
|
|
27
|
+
drizzle-gen api product name:string price:float
|
|
28
|
+
|
|
29
|
+
# Generate only a model
|
|
30
|
+
drizzle-gen model comment content:text authorId:references:user
|
|
31
|
+
|
|
32
|
+
# Generate only actions for an existing model
|
|
33
|
+
drizzle-gen actions post
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Commands
|
|
37
|
+
|
|
38
|
+
### `drizzle-gen model <name> [fields...]`
|
|
39
|
+
|
|
40
|
+
Creates a Drizzle schema model in `db/schema.ts`.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
drizzle-gen model user name:string email:string:unique
|
|
44
|
+
drizzle-gen model post title:string body:text published:boolean
|
|
45
|
+
drizzle-gen model order total:decimal status:enum:pending,paid,shipped
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `drizzle-gen actions <name>`
|
|
49
|
+
|
|
50
|
+
Creates server actions file with CRUD operations.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
drizzle-gen actions user
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### `drizzle-gen resource <name> [fields...]`
|
|
57
|
+
|
|
58
|
+
Creates model + actions (no UI pages).
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
drizzle-gen resource session token:uuid userId:references:user --uuid
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### `drizzle-gen scaffold <name> [fields...]`
|
|
65
|
+
|
|
66
|
+
Creates model + actions + full CRUD pages (list, show, new, edit).
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
drizzle-gen scaffold product name:string price:float description:text?
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### `drizzle-gen api <name> [fields...]`
|
|
73
|
+
|
|
74
|
+
Creates model + REST API route handlers.
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
drizzle-gen api webhook url:string secret:string:unique
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### `drizzle-gen destroy <type> <name>`
|
|
81
|
+
|
|
82
|
+
Removes drizzle-gend files (does not modify schema).
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
drizzle-gen destroy scaffold post
|
|
86
|
+
drizzle-gen destroy api product --dry-run
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `drizzle-gen config`
|
|
90
|
+
|
|
91
|
+
Shows detected project configuration.
|
|
92
|
+
|
|
93
|
+
## Field Types
|
|
94
|
+
|
|
95
|
+
| Type | SQLite | PostgreSQL | MySQL |
|
|
96
|
+
|------|--------|------------|-------|
|
|
97
|
+
| `string` | text | text | varchar(255) |
|
|
98
|
+
| `text` | text | text | text |
|
|
99
|
+
| `integer` / `int` | integer | integer | int |
|
|
100
|
+
| `bigint` | integer | bigint | bigint |
|
|
101
|
+
| `boolean` / `bool` | integer (mode: boolean) | boolean | boolean |
|
|
102
|
+
| `float` | real | doublePrecision | double |
|
|
103
|
+
| `decimal` | text | numeric | decimal |
|
|
104
|
+
| `datetime` / `timestamp` | integer (mode: timestamp) | timestamp | datetime |
|
|
105
|
+
| `date` | integer (mode: timestamp) | date | date |
|
|
106
|
+
| `json` | text | jsonb | json |
|
|
107
|
+
| `uuid` | text | uuid | varchar(36) |
|
|
108
|
+
|
|
109
|
+
### Special Types
|
|
110
|
+
|
|
111
|
+
- **`enum`**: `status:enum:draft,published,archived`
|
|
112
|
+
- **`references`**: `authorId:references:user`
|
|
113
|
+
|
|
114
|
+
## Field Modifiers
|
|
115
|
+
|
|
116
|
+
- **Nullable**: Add `?` to make field optional
|
|
117
|
+
```bash
|
|
118
|
+
drizzle-gen model user bio:text? nickname?
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
- **Unique**: Add `:unique` modifier
|
|
122
|
+
```bash
|
|
123
|
+
drizzle-gen model user email:string:unique
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Options
|
|
127
|
+
|
|
128
|
+
| Option | Description |
|
|
129
|
+
|--------|-------------|
|
|
130
|
+
| `-f, --force` | Overwrite existing files |
|
|
131
|
+
| `-n, --dry-run` | Preview changes without writing |
|
|
132
|
+
| `-u, --uuid` | Use UUID for primary key |
|
|
133
|
+
| `--no-timestamps` | Skip createdAt/updatedAt fields |
|
|
134
|
+
|
|
135
|
+
## Auto-Detection
|
|
136
|
+
|
|
137
|
+
The generator automatically detects your project configuration:
|
|
138
|
+
|
|
139
|
+
- **Project structure**: `src/app/` vs `app/`
|
|
140
|
+
- **Path aliases**: Reads from `tsconfig.json` (`@/`, `~/`, etc.)
|
|
141
|
+
- **Database dialect**: Reads from `drizzle.config.ts`
|
|
142
|
+
- **DB location**: Checks `db/`, `lib/db/`, `server/db/`
|
|
143
|
+
|
|
144
|
+
Run `drizzle-gen config` to see detected settings.
|
|
145
|
+
|
|
146
|
+
## Example Output
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
$ drizzle-gen scaffold post title:string body:text published:boolean
|
|
150
|
+
|
|
151
|
+
Scaffolding Post...
|
|
152
|
+
|
|
153
|
+
create db/schema.ts
|
|
154
|
+
create app/posts/actions.ts
|
|
155
|
+
create app/posts/page.tsx
|
|
156
|
+
create app/posts/new/page.tsx
|
|
157
|
+
create app/posts/[id]/page.tsx
|
|
158
|
+
create app/posts/[id]/edit/page.tsx
|
|
159
|
+
|
|
160
|
+
Next steps:
|
|
161
|
+
1. Run 'pnpm db:push' to update the database
|
|
162
|
+
2. Run 'pnpm dev' and visit /posts
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Requirements
|
|
166
|
+
|
|
167
|
+
- Node.js >= 18
|
|
168
|
+
- Next.js project with App Router
|
|
169
|
+
- Drizzle ORM configured
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT
|
package/dist/index.d.ts
ADDED