@xata.io/drizzle 0.0.0-alpha.ve2d648b → 0.0.0-alpha.ve304656137a7c41a3f10b52dcfd4784695e12cb2
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/.turbo/turbo-build.log +16 -5
- package/CHANGELOG.md +133 -2
- package/README.md +3 -0
- package/dist/index.cjs +98 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +47 -65
- package/dist/index.mjs +96 -123
- package/dist/index.mjs.map +1 -1
- package/dist/pg.cjs +215 -0
- package/dist/pg.cjs.map +1 -0
- package/dist/pg.d.ts +61 -0
- package/dist/pg.mjs +209 -0
- package/dist/pg.mjs.map +1 -0
- package/package.json +12 -4
- package/test/core.schema.ts +93 -0
- package/test/core.test.ts +3768 -0
- package/test/drizzle.test.ts +6293 -0
- package/test/migrate/0000_puzzling_flatman.sql +37 -0
- package/test/migrate/0001_test.sql +5 -0
- package/test/migrate/meta/0000_snapshot.json +275 -0
- package/test/migrate/meta/_journal.json +20 -0
- package/test/relational.schema.ts +85 -0
- package/test/relational.test.ts +6294 -0
- package/test/schema.ts +85 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "all_columns" (
|
2
|
+
"smallint" smallint,
|
3
|
+
"smallint_def" smallint DEFAULT 10,
|
4
|
+
"integer" integer,
|
5
|
+
"integer_def" integer DEFAULT 10,
|
6
|
+
"numeric" numeric,
|
7
|
+
"numeric3" numeric,
|
8
|
+
"numeric4" numeric(7, 7),
|
9
|
+
"numeridef" numeric DEFAULT '100',
|
10
|
+
"bigint" bigint,
|
11
|
+
"bigintdef" bigint DEFAULT 100,
|
12
|
+
"boolean" boolean,
|
13
|
+
"boolean_def" boolean DEFAULT true,
|
14
|
+
"text" text,
|
15
|
+
"textdef" text DEFAULT 'text',
|
16
|
+
"varchar" varchar,
|
17
|
+
"varchardef" varchar DEFAULT 'text',
|
18
|
+
"serial" serial NOT NULL,
|
19
|
+
"bigserial" bigserial NOT NULL,
|
20
|
+
"decimal" numeric(100, 2),
|
21
|
+
"decimaldef" numeric(100, 2) DEFAULT '100.0',
|
22
|
+
"doublePrecision" double precision,
|
23
|
+
"doublePrecisiondef" double precision DEFAULT 100,
|
24
|
+
"real" real,
|
25
|
+
"realdef" real DEFAULT 100,
|
26
|
+
"time2" time(6) with time zone,
|
27
|
+
"timedefnow" time DEFAULT now(),
|
28
|
+
"timestamp" timestamp,
|
29
|
+
"timestamp2" timestamp (6) with time zone,
|
30
|
+
"timestamp3" timestamp with time zone,
|
31
|
+
"timestamp4" timestamp (4),
|
32
|
+
"timestampdef" timestamp DEFAULT now(),
|
33
|
+
"date" date,
|
34
|
+
"datedef" date DEFAULT now(),
|
35
|
+
"interval" interval,
|
36
|
+
"intervaldef" interval DEFAULT '10 days'
|
37
|
+
);
|
@@ -0,0 +1,275 @@
|
|
1
|
+
{
|
2
|
+
"version": "5",
|
3
|
+
"dialect": "pg",
|
4
|
+
"id": "cb1644bb-c5da-465a-8d70-f63d81e34514",
|
5
|
+
"prevId": "00000000-0000-0000-0000-000000000000",
|
6
|
+
"tables": {
|
7
|
+
"all_columns": {
|
8
|
+
"name": "all_columns",
|
9
|
+
"schema": "",
|
10
|
+
"columns": {
|
11
|
+
"smallint": {
|
12
|
+
"name": "smallint",
|
13
|
+
"type": "smallint",
|
14
|
+
"primaryKey": false,
|
15
|
+
"notNull": false
|
16
|
+
},
|
17
|
+
"smallint_def": {
|
18
|
+
"name": "smallint_def",
|
19
|
+
"type": "smallint",
|
20
|
+
"primaryKey": false,
|
21
|
+
"notNull": false,
|
22
|
+
"default": 10
|
23
|
+
},
|
24
|
+
"integer": {
|
25
|
+
"name": "integer",
|
26
|
+
"type": "integer",
|
27
|
+
"primaryKey": false,
|
28
|
+
"notNull": false
|
29
|
+
},
|
30
|
+
"integer_def": {
|
31
|
+
"name": "integer_def",
|
32
|
+
"type": "integer",
|
33
|
+
"primaryKey": false,
|
34
|
+
"notNull": false,
|
35
|
+
"default": 10
|
36
|
+
},
|
37
|
+
"numeric": {
|
38
|
+
"name": "numeric",
|
39
|
+
"type": "numeric",
|
40
|
+
"primaryKey": false,
|
41
|
+
"notNull": false
|
42
|
+
},
|
43
|
+
"numeric3": {
|
44
|
+
"name": "numeric3",
|
45
|
+
"type": "numeric",
|
46
|
+
"primaryKey": false,
|
47
|
+
"notNull": false
|
48
|
+
},
|
49
|
+
"numeric4": {
|
50
|
+
"name": "numeric4",
|
51
|
+
"type": "numeric(7, 7)",
|
52
|
+
"primaryKey": false,
|
53
|
+
"notNull": false
|
54
|
+
},
|
55
|
+
"numeridef": {
|
56
|
+
"name": "numeridef",
|
57
|
+
"type": "numeric",
|
58
|
+
"primaryKey": false,
|
59
|
+
"notNull": false,
|
60
|
+
"default": "'100'"
|
61
|
+
},
|
62
|
+
"bigint": {
|
63
|
+
"name": "bigint",
|
64
|
+
"type": "bigint",
|
65
|
+
"primaryKey": false,
|
66
|
+
"notNull": false
|
67
|
+
},
|
68
|
+
"bigintdef": {
|
69
|
+
"name": "bigintdef",
|
70
|
+
"type": "bigint",
|
71
|
+
"primaryKey": false,
|
72
|
+
"notNull": false,
|
73
|
+
"default": 100
|
74
|
+
},
|
75
|
+
"boolean": {
|
76
|
+
"name": "boolean",
|
77
|
+
"type": "boolean",
|
78
|
+
"primaryKey": false,
|
79
|
+
"notNull": false
|
80
|
+
},
|
81
|
+
"boolean_def": {
|
82
|
+
"name": "boolean_def",
|
83
|
+
"type": "boolean",
|
84
|
+
"primaryKey": false,
|
85
|
+
"notNull": false,
|
86
|
+
"default": true
|
87
|
+
},
|
88
|
+
"text": {
|
89
|
+
"name": "text",
|
90
|
+
"type": "text",
|
91
|
+
"primaryKey": false,
|
92
|
+
"notNull": false
|
93
|
+
},
|
94
|
+
"textdef": {
|
95
|
+
"name": "textdef",
|
96
|
+
"type": "text",
|
97
|
+
"primaryKey": false,
|
98
|
+
"notNull": false,
|
99
|
+
"default": "'text'"
|
100
|
+
},
|
101
|
+
"varchar": {
|
102
|
+
"name": "varchar",
|
103
|
+
"type": "varchar",
|
104
|
+
"primaryKey": false,
|
105
|
+
"notNull": false
|
106
|
+
},
|
107
|
+
"varchardef": {
|
108
|
+
"name": "varchardef",
|
109
|
+
"type": "varchar",
|
110
|
+
"primaryKey": false,
|
111
|
+
"notNull": false,
|
112
|
+
"default": "'text'"
|
113
|
+
},
|
114
|
+
"serial": {
|
115
|
+
"name": "serial",
|
116
|
+
"type": "serial",
|
117
|
+
"primaryKey": false,
|
118
|
+
"notNull": true
|
119
|
+
},
|
120
|
+
"bigserial": {
|
121
|
+
"name": "bigserial",
|
122
|
+
"type": "bigserial",
|
123
|
+
"primaryKey": false,
|
124
|
+
"notNull": true
|
125
|
+
},
|
126
|
+
"decimal": {
|
127
|
+
"name": "decimal",
|
128
|
+
"type": "numeric(100, 2)",
|
129
|
+
"primaryKey": false,
|
130
|
+
"notNull": false
|
131
|
+
},
|
132
|
+
"decimaldef": {
|
133
|
+
"name": "decimaldef",
|
134
|
+
"type": "numeric(100, 2)",
|
135
|
+
"primaryKey": false,
|
136
|
+
"notNull": false,
|
137
|
+
"default": "'100.0'"
|
138
|
+
},
|
139
|
+
"doublePrecision": {
|
140
|
+
"name": "doublePrecision",
|
141
|
+
"type": "double precision",
|
142
|
+
"primaryKey": false,
|
143
|
+
"notNull": false
|
144
|
+
},
|
145
|
+
"doublePrecisiondef": {
|
146
|
+
"name": "doublePrecisiondef",
|
147
|
+
"type": "double precision",
|
148
|
+
"primaryKey": false,
|
149
|
+
"notNull": false,
|
150
|
+
"default": 100
|
151
|
+
},
|
152
|
+
"real": {
|
153
|
+
"name": "real",
|
154
|
+
"type": "real",
|
155
|
+
"primaryKey": false,
|
156
|
+
"notNull": false
|
157
|
+
},
|
158
|
+
"realdef": {
|
159
|
+
"name": "realdef",
|
160
|
+
"type": "real",
|
161
|
+
"primaryKey": false,
|
162
|
+
"notNull": false,
|
163
|
+
"default": 100
|
164
|
+
},
|
165
|
+
"time2": {
|
166
|
+
"name": "time2",
|
167
|
+
"type": "time(6) with time zone",
|
168
|
+
"primaryKey": false,
|
169
|
+
"notNull": false
|
170
|
+
},
|
171
|
+
"timedefnow": {
|
172
|
+
"name": "timedefnow",
|
173
|
+
"type": "time",
|
174
|
+
"primaryKey": false,
|
175
|
+
"notNull": false,
|
176
|
+
"default": "now()"
|
177
|
+
},
|
178
|
+
"timestamp": {
|
179
|
+
"name": "timestamp",
|
180
|
+
"type": "timestamp",
|
181
|
+
"primaryKey": false,
|
182
|
+
"notNull": false
|
183
|
+
},
|
184
|
+
"timestamp2": {
|
185
|
+
"name": "timestamp2",
|
186
|
+
"type": "timestamp (6) with time zone",
|
187
|
+
"primaryKey": false,
|
188
|
+
"notNull": false
|
189
|
+
},
|
190
|
+
"timestamp3": {
|
191
|
+
"name": "timestamp3",
|
192
|
+
"type": "timestamp with time zone",
|
193
|
+
"primaryKey": false,
|
194
|
+
"notNull": false
|
195
|
+
},
|
196
|
+
"timestamp4": {
|
197
|
+
"name": "timestamp4",
|
198
|
+
"type": "timestamp (4)",
|
199
|
+
"primaryKey": false,
|
200
|
+
"notNull": false
|
201
|
+
},
|
202
|
+
"timestampdef": {
|
203
|
+
"name": "timestampdef",
|
204
|
+
"type": "timestamp",
|
205
|
+
"primaryKey": false,
|
206
|
+
"notNull": false,
|
207
|
+
"default": "now()"
|
208
|
+
},
|
209
|
+
"date": {
|
210
|
+
"name": "date",
|
211
|
+
"type": "date",
|
212
|
+
"primaryKey": false,
|
213
|
+
"notNull": false
|
214
|
+
},
|
215
|
+
"datedef": {
|
216
|
+
"name": "datedef",
|
217
|
+
"type": "date",
|
218
|
+
"primaryKey": false,
|
219
|
+
"notNull": false,
|
220
|
+
"default": "now()"
|
221
|
+
},
|
222
|
+
"interval": {
|
223
|
+
"name": "interval",
|
224
|
+
"type": "interval",
|
225
|
+
"primaryKey": false,
|
226
|
+
"notNull": false
|
227
|
+
},
|
228
|
+
"intervaldef": {
|
229
|
+
"name": "intervaldef",
|
230
|
+
"type": "interval",
|
231
|
+
"primaryKey": false,
|
232
|
+
"notNull": false,
|
233
|
+
"default": "'10 days'"
|
234
|
+
}
|
235
|
+
},
|
236
|
+
"indexes": {},
|
237
|
+
"foreignKeys": {},
|
238
|
+
"compositePrimaryKeys": {}
|
239
|
+
},
|
240
|
+
"users12": {
|
241
|
+
"name": "users12",
|
242
|
+
"schema": "",
|
243
|
+
"columns": {
|
244
|
+
"id": {
|
245
|
+
"name": "id",
|
246
|
+
"type": "serial",
|
247
|
+
"primaryKey": true,
|
248
|
+
"notNull": true
|
249
|
+
},
|
250
|
+
"name": {
|
251
|
+
"name": "name",
|
252
|
+
"type": "text",
|
253
|
+
"primaryKey": false,
|
254
|
+
"notNull": true
|
255
|
+
},
|
256
|
+
"email": {
|
257
|
+
"name": "email",
|
258
|
+
"type": "text",
|
259
|
+
"primaryKey": false,
|
260
|
+
"notNull": true
|
261
|
+
}
|
262
|
+
},
|
263
|
+
"indexes": {},
|
264
|
+
"foreignKeys": {},
|
265
|
+
"compositePrimaryKeys": {}
|
266
|
+
}
|
267
|
+
},
|
268
|
+
"enums": {},
|
269
|
+
"schemas": {},
|
270
|
+
"_meta": {
|
271
|
+
"schemas": {},
|
272
|
+
"tables": {},
|
273
|
+
"columns": {}
|
274
|
+
}
|
275
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"version": "5",
|
3
|
+
"dialect": "pg",
|
4
|
+
"entries": [
|
5
|
+
{
|
6
|
+
"idx": 0,
|
7
|
+
"version": "5",
|
8
|
+
"when": 1680271923328,
|
9
|
+
"tag": "0000_puzzling_flatman",
|
10
|
+
"breakpoints": true
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"idx": 1,
|
14
|
+
"version": "5",
|
15
|
+
"when": 1680271923329,
|
16
|
+
"tag": "0001_test",
|
17
|
+
"breakpoints": true
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
import { boolean, integer, type PgColumn, pgTable, primaryKey, serial, text, timestamp } from 'drizzle-orm/pg-core';
|
2
|
+
|
3
|
+
import { relations } from 'drizzle-orm';
|
4
|
+
|
5
|
+
export const usersTable = pgTable('users', {
|
6
|
+
id: serial('id').primaryKey(),
|
7
|
+
name: text('name').notNull(),
|
8
|
+
verified: boolean('verified').notNull().default(false),
|
9
|
+
invitedBy: integer('invited_by').references((): PgColumn => usersTable.id)
|
10
|
+
});
|
11
|
+
|
12
|
+
export const usersConfig = relations(usersTable, ({ one, many }) => ({
|
13
|
+
invitee: one(usersTable, { fields: [usersTable.invitedBy], references: [usersTable.id] }),
|
14
|
+
usersToGroups: many(usersToGroupsTable),
|
15
|
+
posts: many(postsTable)
|
16
|
+
}));
|
17
|
+
|
18
|
+
export const groupsTable = pgTable('groups', {
|
19
|
+
id: serial('id').primaryKey(),
|
20
|
+
name: text('name').notNull(),
|
21
|
+
description: text('description')
|
22
|
+
});
|
23
|
+
|
24
|
+
export const groupsConfig = relations(groupsTable, ({ many }) => ({
|
25
|
+
usersToGroups: many(usersToGroupsTable)
|
26
|
+
}));
|
27
|
+
|
28
|
+
export const usersToGroupsTable = pgTable(
|
29
|
+
'users_to_groups',
|
30
|
+
{
|
31
|
+
id: serial('id').primaryKey(),
|
32
|
+
userId: integer('user_id')
|
33
|
+
.notNull()
|
34
|
+
.references(() => usersTable.id),
|
35
|
+
groupId: integer('group_id')
|
36
|
+
.notNull()
|
37
|
+
.references(() => groupsTable.id)
|
38
|
+
},
|
39
|
+
(t) => ({
|
40
|
+
pk: primaryKey(t.groupId, t.userId)
|
41
|
+
})
|
42
|
+
);
|
43
|
+
|
44
|
+
export const usersToGroupsConfig = relations(usersToGroupsTable, ({ one }) => ({
|
45
|
+
group: one(groupsTable, { fields: [usersToGroupsTable.groupId], references: [groupsTable.id] }),
|
46
|
+
user: one(usersTable, { fields: [usersToGroupsTable.userId], references: [usersTable.id] })
|
47
|
+
}));
|
48
|
+
|
49
|
+
export const postsTable = pgTable('posts', {
|
50
|
+
id: serial('id').primaryKey(),
|
51
|
+
content: text('content').notNull(),
|
52
|
+
ownerId: integer('owner_id').references(() => usersTable.id),
|
53
|
+
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow()
|
54
|
+
});
|
55
|
+
|
56
|
+
export const postsConfig = relations(postsTable, ({ one, many }) => ({
|
57
|
+
author: one(usersTable, { fields: [postsTable.ownerId], references: [usersTable.id] }),
|
58
|
+
comments: many(commentsTable)
|
59
|
+
}));
|
60
|
+
|
61
|
+
export const commentsTable = pgTable('comments', {
|
62
|
+
id: serial('id').primaryKey(),
|
63
|
+
content: text('content').notNull(),
|
64
|
+
creator: integer('creator').references(() => usersTable.id),
|
65
|
+
postId: integer('post_id').references(() => postsTable.id),
|
66
|
+
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow()
|
67
|
+
});
|
68
|
+
|
69
|
+
export const commentsConfig = relations(commentsTable, ({ one, many }) => ({
|
70
|
+
post: one(postsTable, { fields: [commentsTable.postId], references: [postsTable.id] }),
|
71
|
+
author: one(usersTable, { fields: [commentsTable.creator], references: [usersTable.id] }),
|
72
|
+
likes: many(commentLikesTable)
|
73
|
+
}));
|
74
|
+
|
75
|
+
export const commentLikesTable = pgTable('comment_likes', {
|
76
|
+
id: serial('id').primaryKey(),
|
77
|
+
creator: integer('creator').references(() => usersTable.id),
|
78
|
+
commentId: integer('comment_id').references(() => commentsTable.id),
|
79
|
+
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow()
|
80
|
+
});
|
81
|
+
|
82
|
+
export const commentLikesConfig = relations(commentLikesTable, ({ one }) => ({
|
83
|
+
comment: one(commentsTable, { fields: [commentLikesTable.commentId], references: [commentsTable.id] }),
|
84
|
+
author: one(usersTable, { fields: [commentLikesTable.creator], references: [usersTable.id] })
|
85
|
+
}));
|