@@ -4,12 +4,7 @@ import IsSupportedChipGroup from '@components/markdown/IsSupportedChipGroup.astr
4
4
import Callout from ' @components/markdown/Callout.astro' ;
5
5
import Section from ' @components/markdown/Section.astro' ;
6
6
7
- # Views (WIP)
8
- <Callout type = " warning" emoji = " ⚠️" >
9
- Views are currently only implemented in the ` drizzle-orm ` , ` drizzle-kit ` does not support views yet.
10
- You can query the views that already exist in the database, but they won't be added to ` drizzle-kit ` migrations or ` db push ` as of now.
11
- </Callout >
12
-
7
+ # Views
13
8
## Views declaration
14
9
There're several ways you can declare views with Drizzle ORM.
15
10
@@ -28,11 +23,11 @@ yet when you use `sql` you have to explicitly declare view columns schema.
28
23
import { pgTable , pgView , serial , text , timestamp } from " drizzle-orm/pg-core" ;
29
24
30
25
export const user = pgTable (" user" , {
31
- id: serial (" id " ),
32
- name: text (" name " ),
33
- email: text (" email " ),
34
- password: text (" password " ),
35
- role: text (" role " ).$type <" admin" | " customer" >(),
26
+ id: serial (),
27
+ name: text (),
28
+ email: text (),
29
+ password: text (),
30
+ role: text ().$type <" admin" | " customer" >(),
36
31
createdAt: timestamp (" created_at" ),
37
32
updatedAt: timestamp (" updated_at" ),
38
33
});
@@ -52,11 +47,11 @@ yet when you use `sql` you have to explicitly declare view columns schema.
52
47
import { text , mysqlTable , mysqlView , int , timestamp } from " drizzle-orm/mysql-core" ;
53
48
54
49
export const user = mysqlTable (" user" , {
55
- id: int (" id " ).primaryKey ().autoincrement (),
56
- name: text (" name " ),
57
- email: text (" email " ),
58
- password: text (" password " ),
59
- role: text (" role " ).$type <" admin" | " customer" >(),
50
+ id: int ().primaryKey ().autoincrement (),
51
+ name: text (),
52
+ email: text (),
53
+ password: text (),
54
+ role: text ().$type <" admin" | " customer" >(),
60
55
createdAt: timestamp (" created_at" ),
61
56
updatedAt: timestamp (" updated_at" ),
62
57
});
@@ -76,11 +71,11 @@ yet when you use `sql` you have to explicitly declare view columns schema.
76
71
import { integer , text , sqliteView , sqliteTable } from " drizzle-orm/sqlite-core" ;
77
72
78
73
export const user = sqliteTable (" user" , {
79
- id: integer (" id " ).primaryKey ({ autoIncrement: true }),
80
- name: text (" name " ),
81
- email: text (" email " ),
82
- password: text (" password " ),
83
- role: text (" role " ).$type <" admin" | " customer" >(),
74
+ id: integer ().primaryKey ({ autoIncrement: true }),
75
+ name: text (),
76
+ email: text (),
77
+ password: text (),
78
+ role: text ().$type <" admin" | " customer" >(),
84
79
createdAt: integer (" created_at" ),
85
80
updatedAt: integer (" updated_at" ),
86
81
});
@@ -124,11 +119,11 @@ You can also declare views using `standalone query builder`, it works exactly th
124
119
const qb = new QueryBuilder ();
125
120
126
121
export const user = pgTable (" user" , {
127
- id: serial (" id " ),
128
- name: text (" name " ),
129
- email: text (" email " ),
130
- password: text (" password " ),
131
- role: text (" role " ).$type <" admin" | " customer" >(),
122
+ id: serial (),
123
+ name: text (),
124
+ email: text (),
125
+ password: text (),
126
+ role: text ().$type <" admin" | " customer" >(),
132
127
createdAt: timestamp (" created_at" ),
133
128
updatedAt: timestamp (" updated_at" ),
134
129
});
@@ -150,11 +145,11 @@ You can also declare views using `standalone query builder`, it works exactly th
150
145
const qb = new QueryBuilder ();
151
146
152
147
export const user = mysqlTable (" user" , {
153
- id: int (" id " ).primaryKey ().autoincrement (),
154
- name: text (" name " ),
155
- email: text (" email " ),
156
- password: text (" password " ),
157
- role: text (" role " ).$type <" admin" | " customer" >(),
148
+ id: int ().primaryKey ().autoincrement (),
149
+ name: text (),
150
+ email: text (),
151
+ password: text (),
152
+ role: text ().$type <" admin" | " customer" >(),
158
153
createdAt: timestamp (" created_at" ),
159
154
updatedAt: timestamp (" updated_at" ),
160
155
});
@@ -176,11 +171,11 @@ You can also declare views using `standalone query builder`, it works exactly th
176
171
const qb = new QueryBuilder ();
177
172
178
173
export const user = sqliteTable (" user" , {
179
- id: integer (" id " ).primaryKey ({ autoIncrement: true }),
180
- name: text (" name " ),
181
- email: text (" email " ),
182
- password: text (" password " ),
183
- role: text (" role " ).$type <" admin" | " customer" >(),
174
+ id: integer ().primaryKey ({ autoIncrement: true }),
175
+ name: text (),
176
+ email: text (),
177
+ password: text (),
178
+ role: text ().$type <" admin" | " customer" >(),
184
179
createdAt: integer (" created_at" ),
185
180
updatedAt: integer (" updated_at" ),
186
181
});
@@ -221,11 +216,11 @@ When you're provided with a read only access to an existing view in the database
221
216
` drizzle-kit ` will ignore and will not generate a ` create view ` statement in the generated migration.
222
217
``` ts
223
218
export const user = pgTable (" user" , {
224
- id: serial (" id " ),
225
- name: text (" name " ),
226
- email: text (" email " ),
227
- password: text (" password " ),
228
- role: text (" role " ).$type <" admin" | " customer" >(),
219
+ id: serial (),
220
+ name: text (),
221
+ email: text (),
222
+ password: text (),
223
+ role: text ().$type <" admin" | " customer" >(),
229
224
createdAt: timestamp (" created_at" ),
230
225
updatedAt: timestamp (" updated_at" ),
231
226
});
0 commit comments