@coursebuilder/adapter-drizzle 0.0.1 → 0.0.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/index.d.ts +3 -3
- package/index.d.ts.map +1 -1
- package/lib/mysql.d.ts +1 -1
- package/lib/mysql.d.ts.map +1 -1
- package/lib/mysql.js +56 -0
- package/lib/pg.d.ts +131 -28
- package/lib/pg.d.ts.map +1 -1
- package/lib/pg.js +72 -5
- package/lib/sqlite.d.ts +196 -2
- package/lib/sqlite.d.ts.map +1 -1
- package/lib/sqlite.js +56 -5
- package/lib/utils.d.ts +3 -3
- package/lib/utils.d.ts.map +1 -1
- package/package.json +6 -7
- package/src/index.ts +7 -7
- package/src/lib/mysql.ts +59 -1
- package/src/lib/pg.ts +86 -7
- package/src/lib/sqlite.ts +66 -7
- package/src/lib/utils.ts +3 -3
- package/schema.d.ts +0 -1023
- package/schema.d.ts.map +0 -1
- package/schema.js +0 -318
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type CourseBuilderAdapter } from '@coursebuilder/core/adapters';
|
|
1
2
|
import { createTables as createMySqlTables } from './lib/mysql.js';
|
|
2
|
-
import { SqlFlavorOptions, TableFn } from './lib/utils.js';
|
|
3
|
-
|
|
4
|
-
export declare function DrizzleAdapter<SqlFlavor extends SqlFlavorOptions>(db: SqlFlavor, table?: TableFn<SqlFlavor>): NO_IT_AINT;
|
|
3
|
+
import { type SqlFlavorOptions, type TableFn } from './lib/utils.js';
|
|
4
|
+
export declare function DrizzleAdapter<SqlFlavor extends SqlFlavorOptions>(db: SqlFlavor, table?: TableFn<SqlFlavor>): CourseBuilderAdapter;
|
|
5
5
|
export { createMySqlTables };
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAuB,MAAM,gBAAgB,CAAA;AAGvF,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAExE,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAuB,MAAM,gBAAgB,CAAA;AAGvF,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAEpE,wBAAgB,cAAc,CAAC,SAAS,SAAS,gBAAgB,EAC/D,EAAE,EAAE,SAAS,EACb,KAAK,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GACzB,oBAAoB,CAUtB;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
package/lib/mysql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MySqlDatabase, MySqlTableFn } from 'drizzle-orm/mysql-core';
|
|
2
|
-
import { CourseBuilderAdapter } from '@coursebuilder/core/adapters';
|
|
2
|
+
import { type CourseBuilderAdapter } from '@coursebuilder/core/adapters';
|
|
3
3
|
export declare function createTables(mySqlTable: MySqlTableFn): {
|
|
4
4
|
users: import("drizzle-orm/mysql-core").MySqlTableWithColumns<{
|
|
5
5
|
name: "user";
|
package/lib/mysql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../src/lib/mysql.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,aAAa,EAEb,YAAY,EAIb,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../src/lib/mysql.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,aAAa,EAEb,YAAY,EAIb,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAGxE,wBAAgB,YAAY,CAAC,UAAU,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2HpD;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAA;AAE3D,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,CAAC,OAAO,aAAa,CAAC,EAC1C,OAAO,0BAAsB,GAC5B,oBAAoB,CA2PtB"}
|
package/lib/mysql.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addSeconds, isAfter } from 'date-fns';
|
|
2
2
|
import { and, eq, sql } from 'drizzle-orm';
|
|
3
3
|
import { mysqlTable as defaultMySqlTableFn, double, index, int, json, mysqlEnum, primaryKey, timestamp, varchar, } from 'drizzle-orm/mysql-core';
|
|
4
|
+
import { VideoResourceSchema } from '@coursebuilder/core/schemas/video-resource';
|
|
4
5
|
export function createTables(mySqlTable) {
|
|
5
6
|
const users = mySqlTable('user', {
|
|
6
7
|
id: varchar('id', { length: 255 }).notNull().primaryKey(),
|
|
@@ -102,6 +103,61 @@ export function createTables(mySqlTable) {
|
|
|
102
103
|
export function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
103
104
|
const { users, accounts, sessions, verificationTokens, contentResource } = createTables(tableFn);
|
|
104
105
|
return {
|
|
106
|
+
async updateContentResourceFields(options) {
|
|
107
|
+
const setFields = Object.entries(options.fields)
|
|
108
|
+
.map(([fieldName, fieldValue], index, array) => {
|
|
109
|
+
const comma = index < array.length - 1 ? ',' : '';
|
|
110
|
+
return sql `${fieldName} = ${fieldValue}${comma}`;
|
|
111
|
+
})
|
|
112
|
+
.join(' ');
|
|
113
|
+
const query = sql `
|
|
114
|
+
UPDATE ${contentResource}
|
|
115
|
+
SET ${setFields}
|
|
116
|
+
WHERE
|
|
117
|
+
id = ${options.id};
|
|
118
|
+
`;
|
|
119
|
+
return client
|
|
120
|
+
.execute(query)
|
|
121
|
+
.then((_) => {
|
|
122
|
+
return this.getContentResource(options.id);
|
|
123
|
+
})
|
|
124
|
+
.catch((error) => {
|
|
125
|
+
console.error(error);
|
|
126
|
+
throw error;
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
async getVideoResource(id) {
|
|
130
|
+
if (!id) {
|
|
131
|
+
throw new Error('videoResourceId is required');
|
|
132
|
+
}
|
|
133
|
+
const query = sql `
|
|
134
|
+
SELECT
|
|
135
|
+
id as _id,
|
|
136
|
+
CAST(updatedAt AS DATETIME) as _updatedAt,
|
|
137
|
+
CAST(createdAt AS DATETIME) as _createdAt,
|
|
138
|
+
JSON_EXTRACT (${contentResource.fields}, "$.state") AS state,
|
|
139
|
+
JSON_EXTRACT (${contentResource.fields}, "$.duration") AS duration,
|
|
140
|
+
JSON_EXTRACT (${contentResource.fields}, "$.muxPlaybackId") AS muxPlaybackId,
|
|
141
|
+
JSON_EXTRACT (${contentResource.fields}, "$.muxAssetId") AS muxAssetId,
|
|
142
|
+
JSON_EXTRACT (${contentResource.fields}, "$.transcript") AS transcript
|
|
143
|
+
FROM
|
|
144
|
+
${contentResource}
|
|
145
|
+
WHERE
|
|
146
|
+
type = 'videoResource'
|
|
147
|
+
AND (id = ${id});
|
|
148
|
+
|
|
149
|
+
`;
|
|
150
|
+
return client
|
|
151
|
+
.execute(query)
|
|
152
|
+
.then((result) => {
|
|
153
|
+
const parsedResource = VideoResourceSchema.safeParse(result.rows[0]);
|
|
154
|
+
return parsedResource.success ? parsedResource.data : null;
|
|
155
|
+
})
|
|
156
|
+
.catch((error) => {
|
|
157
|
+
console.error(error);
|
|
158
|
+
return error;
|
|
159
|
+
});
|
|
160
|
+
},
|
|
105
161
|
async createContentResource(data) {
|
|
106
162
|
const id = crypto.randomUUID();
|
|
107
163
|
await client.insert(contentResource).values({ ...data, id });
|
package/lib/pg.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Adapter } from '@auth/core/adapters';
|
|
2
1
|
import { PgDatabase, PgTableFn } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { type CourseBuilderAdapter } from '@coursebuilder/core/adapters';
|
|
3
3
|
export declare function createTables(pgTable: PgTableFn): {
|
|
4
|
-
users: import("drizzle-orm/pg-core
|
|
4
|
+
users: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
5
5
|
name: "user";
|
|
6
6
|
schema: undefined;
|
|
7
7
|
columns: {
|
|
8
|
-
id: import("drizzle-orm/pg-core
|
|
8
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
9
9
|
name: "id";
|
|
10
10
|
tableName: "user";
|
|
11
11
|
dataType: "string";
|
|
@@ -17,7 +17,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
17
17
|
enumValues: [string, ...string[]];
|
|
18
18
|
baseColumn: never;
|
|
19
19
|
}, {}, {}>;
|
|
20
|
-
name: import("drizzle-orm/pg-core
|
|
20
|
+
name: import("drizzle-orm/pg-core").PgColumn<{
|
|
21
21
|
name: "name";
|
|
22
22
|
tableName: "user";
|
|
23
23
|
dataType: "string";
|
|
@@ -29,7 +29,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
29
29
|
enumValues: [string, ...string[]];
|
|
30
30
|
baseColumn: never;
|
|
31
31
|
}, {}, {}>;
|
|
32
|
-
email: import("drizzle-orm/pg-core
|
|
32
|
+
email: import("drizzle-orm/pg-core").PgColumn<{
|
|
33
33
|
name: "email";
|
|
34
34
|
tableName: "user";
|
|
35
35
|
dataType: "string";
|
|
@@ -41,7 +41,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
41
41
|
enumValues: [string, ...string[]];
|
|
42
42
|
baseColumn: never;
|
|
43
43
|
}, {}, {}>;
|
|
44
|
-
emailVerified: import("drizzle-orm/pg-core
|
|
44
|
+
emailVerified: import("drizzle-orm/pg-core").PgColumn<{
|
|
45
45
|
name: "emailVerified";
|
|
46
46
|
tableName: "user";
|
|
47
47
|
dataType: "date";
|
|
@@ -53,7 +53,19 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
53
53
|
enumValues: undefined;
|
|
54
54
|
baseColumn: never;
|
|
55
55
|
}, {}, {}>;
|
|
56
|
-
|
|
56
|
+
role: import("drizzle-orm/pg-core").PgColumn<{
|
|
57
|
+
name: "role";
|
|
58
|
+
tableName: "user";
|
|
59
|
+
dataType: "string";
|
|
60
|
+
columnType: "PgEnumColumn";
|
|
61
|
+
data: "user" | "admin";
|
|
62
|
+
driverParam: string;
|
|
63
|
+
notNull: false;
|
|
64
|
+
hasDefault: true;
|
|
65
|
+
enumValues: ["user", "admin"];
|
|
66
|
+
baseColumn: never;
|
|
67
|
+
}, {}, {}>;
|
|
68
|
+
image: import("drizzle-orm/pg-core").PgColumn<{
|
|
57
69
|
name: "image";
|
|
58
70
|
tableName: "user";
|
|
59
71
|
dataType: "string";
|
|
@@ -68,11 +80,11 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
68
80
|
};
|
|
69
81
|
dialect: "pg";
|
|
70
82
|
}>;
|
|
71
|
-
accounts: import("drizzle-orm/pg-core
|
|
83
|
+
accounts: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
72
84
|
name: "account";
|
|
73
85
|
schema: undefined;
|
|
74
86
|
columns: {
|
|
75
|
-
userId: import("drizzle-orm/pg-core
|
|
87
|
+
userId: import("drizzle-orm/pg-core").PgColumn<{
|
|
76
88
|
name: "userId";
|
|
77
89
|
tableName: "account";
|
|
78
90
|
dataType: "string";
|
|
@@ -84,7 +96,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
84
96
|
enumValues: [string, ...string[]];
|
|
85
97
|
baseColumn: never;
|
|
86
98
|
}, {}, {}>;
|
|
87
|
-
type: import("drizzle-orm/pg-core
|
|
99
|
+
type: import("drizzle-orm/pg-core").PgColumn<{
|
|
88
100
|
name: "type";
|
|
89
101
|
tableName: "account";
|
|
90
102
|
dataType: "string";
|
|
@@ -96,7 +108,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
96
108
|
enumValues: [string, ...string[]];
|
|
97
109
|
baseColumn: never;
|
|
98
110
|
}, {}, {}>;
|
|
99
|
-
provider: import("drizzle-orm/pg-core
|
|
111
|
+
provider: import("drizzle-orm/pg-core").PgColumn<{
|
|
100
112
|
name: "provider";
|
|
101
113
|
tableName: "account";
|
|
102
114
|
dataType: "string";
|
|
@@ -108,7 +120,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
108
120
|
enumValues: [string, ...string[]];
|
|
109
121
|
baseColumn: never;
|
|
110
122
|
}, {}, {}>;
|
|
111
|
-
providerAccountId: import("drizzle-orm/pg-core
|
|
123
|
+
providerAccountId: import("drizzle-orm/pg-core").PgColumn<{
|
|
112
124
|
name: "providerAccountId";
|
|
113
125
|
tableName: "account";
|
|
114
126
|
dataType: "string";
|
|
@@ -120,7 +132,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
120
132
|
enumValues: [string, ...string[]];
|
|
121
133
|
baseColumn: never;
|
|
122
134
|
}, {}, {}>;
|
|
123
|
-
refresh_token: import("drizzle-orm/pg-core
|
|
135
|
+
refresh_token: import("drizzle-orm/pg-core").PgColumn<{
|
|
124
136
|
name: "refresh_token";
|
|
125
137
|
tableName: "account";
|
|
126
138
|
dataType: "string";
|
|
@@ -132,7 +144,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
132
144
|
enumValues: [string, ...string[]];
|
|
133
145
|
baseColumn: never;
|
|
134
146
|
}, {}, {}>;
|
|
135
|
-
access_token: import("drizzle-orm/pg-core
|
|
147
|
+
access_token: import("drizzle-orm/pg-core").PgColumn<{
|
|
136
148
|
name: "access_token";
|
|
137
149
|
tableName: "account";
|
|
138
150
|
dataType: "string";
|
|
@@ -144,7 +156,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
144
156
|
enumValues: [string, ...string[]];
|
|
145
157
|
baseColumn: never;
|
|
146
158
|
}, {}, {}>;
|
|
147
|
-
expires_at: import("drizzle-orm/pg-core
|
|
159
|
+
expires_at: import("drizzle-orm/pg-core").PgColumn<{
|
|
148
160
|
name: "expires_at";
|
|
149
161
|
tableName: "account";
|
|
150
162
|
dataType: "number";
|
|
@@ -156,7 +168,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
156
168
|
enumValues: undefined;
|
|
157
169
|
baseColumn: never;
|
|
158
170
|
}, {}, {}>;
|
|
159
|
-
token_type: import("drizzle-orm/pg-core
|
|
171
|
+
token_type: import("drizzle-orm/pg-core").PgColumn<{
|
|
160
172
|
name: "token_type";
|
|
161
173
|
tableName: "account";
|
|
162
174
|
dataType: "string";
|
|
@@ -168,7 +180,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
168
180
|
enumValues: [string, ...string[]];
|
|
169
181
|
baseColumn: never;
|
|
170
182
|
}, {}, {}>;
|
|
171
|
-
scope: import("drizzle-orm/pg-core
|
|
183
|
+
scope: import("drizzle-orm/pg-core").PgColumn<{
|
|
172
184
|
name: "scope";
|
|
173
185
|
tableName: "account";
|
|
174
186
|
dataType: "string";
|
|
@@ -180,7 +192,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
180
192
|
enumValues: [string, ...string[]];
|
|
181
193
|
baseColumn: never;
|
|
182
194
|
}, {}, {}>;
|
|
183
|
-
id_token: import("drizzle-orm/pg-core
|
|
195
|
+
id_token: import("drizzle-orm/pg-core").PgColumn<{
|
|
184
196
|
name: "id_token";
|
|
185
197
|
tableName: "account";
|
|
186
198
|
dataType: "string";
|
|
@@ -192,7 +204,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
192
204
|
enumValues: [string, ...string[]];
|
|
193
205
|
baseColumn: never;
|
|
194
206
|
}, {}, {}>;
|
|
195
|
-
session_state: import("drizzle-orm/pg-core
|
|
207
|
+
session_state: import("drizzle-orm/pg-core").PgColumn<{
|
|
196
208
|
name: "session_state";
|
|
197
209
|
tableName: "account";
|
|
198
210
|
dataType: "string";
|
|
@@ -207,11 +219,11 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
207
219
|
};
|
|
208
220
|
dialect: "pg";
|
|
209
221
|
}>;
|
|
210
|
-
sessions: import("drizzle-orm/pg-core
|
|
222
|
+
sessions: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
211
223
|
name: "session";
|
|
212
224
|
schema: undefined;
|
|
213
225
|
columns: {
|
|
214
|
-
sessionToken: import("drizzle-orm/pg-core
|
|
226
|
+
sessionToken: import("drizzle-orm/pg-core").PgColumn<{
|
|
215
227
|
name: "sessionToken";
|
|
216
228
|
tableName: "session";
|
|
217
229
|
dataType: "string";
|
|
@@ -223,7 +235,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
223
235
|
enumValues: [string, ...string[]];
|
|
224
236
|
baseColumn: never;
|
|
225
237
|
}, {}, {}>;
|
|
226
|
-
userId: import("drizzle-orm/pg-core
|
|
238
|
+
userId: import("drizzle-orm/pg-core").PgColumn<{
|
|
227
239
|
name: "userId";
|
|
228
240
|
tableName: "session";
|
|
229
241
|
dataType: "string";
|
|
@@ -235,7 +247,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
235
247
|
enumValues: [string, ...string[]];
|
|
236
248
|
baseColumn: never;
|
|
237
249
|
}, {}, {}>;
|
|
238
|
-
expires: import("drizzle-orm/pg-core
|
|
250
|
+
expires: import("drizzle-orm/pg-core").PgColumn<{
|
|
239
251
|
name: "expires";
|
|
240
252
|
tableName: "session";
|
|
241
253
|
dataType: "date";
|
|
@@ -250,11 +262,11 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
250
262
|
};
|
|
251
263
|
dialect: "pg";
|
|
252
264
|
}>;
|
|
253
|
-
verificationTokens: import("drizzle-orm/pg-core
|
|
265
|
+
verificationTokens: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
254
266
|
name: "verificationToken";
|
|
255
267
|
schema: undefined;
|
|
256
268
|
columns: {
|
|
257
|
-
identifier: import("drizzle-orm/pg-core
|
|
269
|
+
identifier: import("drizzle-orm/pg-core").PgColumn<{
|
|
258
270
|
name: "identifier";
|
|
259
271
|
tableName: "verificationToken";
|
|
260
272
|
dataType: "string";
|
|
@@ -266,7 +278,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
266
278
|
enumValues: [string, ...string[]];
|
|
267
279
|
baseColumn: never;
|
|
268
280
|
}, {}, {}>;
|
|
269
|
-
token: import("drizzle-orm/pg-core
|
|
281
|
+
token: import("drizzle-orm/pg-core").PgColumn<{
|
|
270
282
|
name: "token";
|
|
271
283
|
tableName: "verificationToken";
|
|
272
284
|
dataType: "string";
|
|
@@ -278,7 +290,7 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
278
290
|
enumValues: [string, ...string[]];
|
|
279
291
|
baseColumn: never;
|
|
280
292
|
}, {}, {}>;
|
|
281
|
-
expires: import("drizzle-orm/pg-core
|
|
293
|
+
expires: import("drizzle-orm/pg-core").PgColumn<{
|
|
282
294
|
name: "expires";
|
|
283
295
|
tableName: "verificationToken";
|
|
284
296
|
dataType: "date";
|
|
@@ -293,7 +305,98 @@ export declare function createTables(pgTable: PgTableFn): {
|
|
|
293
305
|
};
|
|
294
306
|
dialect: "pg";
|
|
295
307
|
}>;
|
|
308
|
+
contentResource: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
309
|
+
name: "contentResource";
|
|
310
|
+
schema: undefined;
|
|
311
|
+
columns: {
|
|
312
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
313
|
+
name: "id";
|
|
314
|
+
tableName: "contentResource";
|
|
315
|
+
dataType: "string";
|
|
316
|
+
columnType: "PgVarchar";
|
|
317
|
+
data: string;
|
|
318
|
+
driverParam: string;
|
|
319
|
+
notNull: true;
|
|
320
|
+
hasDefault: false;
|
|
321
|
+
enumValues: [string, ...string[]];
|
|
322
|
+
baseColumn: never;
|
|
323
|
+
}, {}, {}>;
|
|
324
|
+
type: import("drizzle-orm/pg-core").PgColumn<{
|
|
325
|
+
name: "type";
|
|
326
|
+
tableName: "contentResource";
|
|
327
|
+
dataType: "string";
|
|
328
|
+
columnType: "PgVarchar";
|
|
329
|
+
data: string;
|
|
330
|
+
driverParam: string;
|
|
331
|
+
notNull: true;
|
|
332
|
+
hasDefault: false;
|
|
333
|
+
enumValues: [string, ...string[]];
|
|
334
|
+
baseColumn: never;
|
|
335
|
+
}, {}, {}>;
|
|
336
|
+
createdById: import("drizzle-orm/pg-core").PgColumn<{
|
|
337
|
+
name: "createdById";
|
|
338
|
+
tableName: "contentResource";
|
|
339
|
+
dataType: "string";
|
|
340
|
+
columnType: "PgVarchar";
|
|
341
|
+
data: string;
|
|
342
|
+
driverParam: string;
|
|
343
|
+
notNull: true;
|
|
344
|
+
hasDefault: false;
|
|
345
|
+
enumValues: [string, ...string[]];
|
|
346
|
+
baseColumn: never;
|
|
347
|
+
}, {}, {}>;
|
|
348
|
+
fields: import("drizzle-orm/pg-core").PgColumn<{
|
|
349
|
+
name: "fields";
|
|
350
|
+
tableName: "contentResource";
|
|
351
|
+
dataType: "json";
|
|
352
|
+
columnType: "PgJson";
|
|
353
|
+
data: Record<string, any>;
|
|
354
|
+
driverParam: unknown;
|
|
355
|
+
notNull: false;
|
|
356
|
+
hasDefault: true;
|
|
357
|
+
enumValues: undefined;
|
|
358
|
+
baseColumn: never;
|
|
359
|
+
}, {}, {}>;
|
|
360
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
361
|
+
name: "createdAt";
|
|
362
|
+
tableName: "contentResource";
|
|
363
|
+
dataType: "date";
|
|
364
|
+
columnType: "PgTimestamp";
|
|
365
|
+
data: Date;
|
|
366
|
+
driverParam: string;
|
|
367
|
+
notNull: false;
|
|
368
|
+
hasDefault: true;
|
|
369
|
+
enumValues: undefined;
|
|
370
|
+
baseColumn: never;
|
|
371
|
+
}, {}, {}>;
|
|
372
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
373
|
+
name: "updatedAt";
|
|
374
|
+
tableName: "contentResource";
|
|
375
|
+
dataType: "date";
|
|
376
|
+
columnType: "PgTimestamp";
|
|
377
|
+
data: Date;
|
|
378
|
+
driverParam: string;
|
|
379
|
+
notNull: false;
|
|
380
|
+
hasDefault: true;
|
|
381
|
+
enumValues: undefined;
|
|
382
|
+
baseColumn: never;
|
|
383
|
+
}, {}, {}>;
|
|
384
|
+
deletedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
385
|
+
name: "deletedAt";
|
|
386
|
+
tableName: "contentResource";
|
|
387
|
+
dataType: "date";
|
|
388
|
+
columnType: "PgTimestamp";
|
|
389
|
+
data: Date;
|
|
390
|
+
driverParam: string;
|
|
391
|
+
notNull: false;
|
|
392
|
+
hasDefault: false;
|
|
393
|
+
enumValues: undefined;
|
|
394
|
+
baseColumn: never;
|
|
395
|
+
}, {}, {}>;
|
|
396
|
+
};
|
|
397
|
+
dialect: "pg";
|
|
398
|
+
}>;
|
|
296
399
|
};
|
|
297
400
|
export type DefaultSchema = ReturnType<typeof createTables>;
|
|
298
|
-
export declare function pgDrizzleAdapter(client: InstanceType<typeof PgDatabase>, tableFn?: PgTableFn<undefined>):
|
|
401
|
+
export declare function pgDrizzleAdapter(client: InstanceType<typeof PgDatabase>, tableFn?: PgTableFn<undefined>): CourseBuilderAdapter;
|
|
299
402
|
//# sourceMappingURL=pg.d.ts.map
|
package/lib/pg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../src/lib/pg.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../src/lib/pg.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,UAAU,EAEV,SAAS,EAKV,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAExE,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuG9C;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAA;AAE3D,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,YAAY,CAAC,OAAO,UAAU,CAAC,EACvC,OAAO,uBAAmB,GACzB,oBAAoB,CAqJtB"}
|
package/lib/pg.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { and, eq } from 'drizzle-orm';
|
|
2
|
-
import { pgTable as defaultPgTableFn, integer, primaryKey, text, timestamp, } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { pgTable as defaultPgTableFn, integer, json, pgEnum, primaryKey, text, timestamp, varchar, } from 'drizzle-orm/pg-core';
|
|
3
3
|
export function createTables(pgTable) {
|
|
4
4
|
const users = pgTable('user', {
|
|
5
5
|
id: text('id').notNull().primaryKey(),
|
|
6
6
|
name: text('name'),
|
|
7
7
|
email: text('email').notNull(),
|
|
8
8
|
emailVerified: timestamp('emailVerified', { mode: 'date' }),
|
|
9
|
+
role: pgEnum('role', ['user', 'admin'])('role').default('user'),
|
|
9
10
|
image: text('image'),
|
|
10
11
|
});
|
|
11
12
|
const accounts = pgTable('account', {
|
|
@@ -23,7 +24,7 @@ export function createTables(pgTable) {
|
|
|
23
24
|
id_token: text('id_token'),
|
|
24
25
|
session_state: text('session_state'),
|
|
25
26
|
}, (account) => ({
|
|
26
|
-
|
|
27
|
+
pk: primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
27
28
|
}));
|
|
28
29
|
const sessions = pgTable('session', {
|
|
29
30
|
sessionToken: text('sessionToken').notNull().primaryKey(),
|
|
@@ -37,13 +38,79 @@ export function createTables(pgTable) {
|
|
|
37
38
|
token: text('token').notNull(),
|
|
38
39
|
expires: timestamp('expires', { mode: 'date' }).notNull(),
|
|
39
40
|
}, (vt) => ({
|
|
40
|
-
|
|
41
|
+
pk: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
41
42
|
}));
|
|
42
|
-
|
|
43
|
+
const contentResource = pgTable('contentResource', {
|
|
44
|
+
id: varchar('id', { length: 255 }).notNull().primaryKey(),
|
|
45
|
+
type: varchar('type', { length: 255 }).notNull(),
|
|
46
|
+
createdById: varchar('createdById', { length: 255 }).notNull(),
|
|
47
|
+
fields: json('fields').$type().default({}),
|
|
48
|
+
createdAt: timestamp('createdAt', {
|
|
49
|
+
mode: 'date',
|
|
50
|
+
precision: 6,
|
|
51
|
+
withTimezone: true,
|
|
52
|
+
}).defaultNow(),
|
|
53
|
+
updatedAt: timestamp('updatedAt', {
|
|
54
|
+
mode: 'date',
|
|
55
|
+
precision: 6,
|
|
56
|
+
withTimezone: true,
|
|
57
|
+
}).defaultNow(),
|
|
58
|
+
deletedAt: timestamp('deletedAt', {
|
|
59
|
+
mode: 'date',
|
|
60
|
+
precision: 6,
|
|
61
|
+
withTimezone: true,
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
const contentResourceResource = pgTable('contentResourceResource', {
|
|
65
|
+
resourceOfId: varchar('resourceOfId', { length: 255 }).notNull(),
|
|
66
|
+
resourceId: varchar('resourceId', { length: 255 }).notNull(),
|
|
67
|
+
position: integer('position').notNull().default(0),
|
|
68
|
+
metadata: json('fields').$type().default({}),
|
|
69
|
+
createdAt: timestamp('createdAt', {
|
|
70
|
+
mode: 'date',
|
|
71
|
+
precision: 6,
|
|
72
|
+
withTimezone: true,
|
|
73
|
+
}).defaultNow(),
|
|
74
|
+
updatedAt: timestamp('updatedAt', {
|
|
75
|
+
mode: 'date',
|
|
76
|
+
precision: 6,
|
|
77
|
+
withTimezone: true,
|
|
78
|
+
}).defaultNow(),
|
|
79
|
+
deletedAt: timestamp('deletedAt', {
|
|
80
|
+
mode: 'date',
|
|
81
|
+
precision: 6,
|
|
82
|
+
withTimezone: true,
|
|
83
|
+
}),
|
|
84
|
+
}, (crr) => ({
|
|
85
|
+
pk: primaryKey({ columns: [crr.resourceOfId, crr.resourceId] }),
|
|
86
|
+
}));
|
|
87
|
+
return { users, accounts, sessions, verificationTokens, contentResource };
|
|
43
88
|
}
|
|
44
89
|
export function pgDrizzleAdapter(client, tableFn = defaultPgTableFn) {
|
|
45
|
-
const { users, accounts, sessions, verificationTokens } = createTables(tableFn);
|
|
90
|
+
const { users, accounts, sessions, verificationTokens, contentResource } = createTables(tableFn);
|
|
46
91
|
return {
|
|
92
|
+
async updateContentResourceFields(options) {
|
|
93
|
+
return null;
|
|
94
|
+
},
|
|
95
|
+
async getVideoResource(id) {
|
|
96
|
+
// TODO Implement
|
|
97
|
+
return null;
|
|
98
|
+
},
|
|
99
|
+
async createContentResource(resource) {
|
|
100
|
+
return client
|
|
101
|
+
.insert(contentResource)
|
|
102
|
+
.values({ ...resource, id: crypto.randomUUID() })
|
|
103
|
+
.returning()
|
|
104
|
+
.then((res) => res[0] ?? null);
|
|
105
|
+
},
|
|
106
|
+
async getContentResource(data) {
|
|
107
|
+
const result = await client
|
|
108
|
+
.select()
|
|
109
|
+
.from(contentResource)
|
|
110
|
+
.where(eq(contentResource.id, data))
|
|
111
|
+
.then((res) => res[0] ?? null);
|
|
112
|
+
return result ?? null;
|
|
113
|
+
},
|
|
47
114
|
async createUser(data) {
|
|
48
115
|
return await client
|
|
49
116
|
.insert(users)
|