@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/src/lib/sqlite.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { and, eq } from 'drizzle-orm'
|
|
1
|
+
import type { AdapterAccount } from '@auth/core/adapters'
|
|
2
|
+
import { and, eq, sql } from 'drizzle-orm'
|
|
3
3
|
import {
|
|
4
4
|
BaseSQLiteDatabase,
|
|
5
5
|
sqliteTable as defaultSqliteTableFn,
|
|
@@ -9,12 +9,15 @@ import {
|
|
|
9
9
|
text,
|
|
10
10
|
} from 'drizzle-orm/sqlite-core'
|
|
11
11
|
|
|
12
|
+
import { type CourseBuilderAdapter } from '@coursebuilder/core/adapters'
|
|
13
|
+
|
|
12
14
|
import { stripUndefined } from './utils.js'
|
|
13
15
|
|
|
14
16
|
export function createTables(sqliteTable: SQLiteTableFn) {
|
|
15
17
|
const users = sqliteTable('user', {
|
|
16
18
|
id: text('id').notNull().primaryKey(),
|
|
17
19
|
name: text('name'),
|
|
20
|
+
role: text('role', { enum: ['user', 'admin'] }).default('user'),
|
|
18
21
|
email: text('email').notNull(),
|
|
19
22
|
emailVerified: integer('emailVerified', { mode: 'timestamp_ms' }),
|
|
20
23
|
image: text('image'),
|
|
@@ -38,7 +41,7 @@ export function createTables(sqliteTable: SQLiteTableFn) {
|
|
|
38
41
|
session_state: text('session_state'),
|
|
39
42
|
},
|
|
40
43
|
(account) => ({
|
|
41
|
-
|
|
44
|
+
pk: primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
42
45
|
}),
|
|
43
46
|
)
|
|
44
47
|
|
|
@@ -58,11 +61,49 @@ export function createTables(sqliteTable: SQLiteTableFn) {
|
|
|
58
61
|
expires: integer('expires', { mode: 'timestamp_ms' }).notNull(),
|
|
59
62
|
},
|
|
60
63
|
(vt) => ({
|
|
61
|
-
|
|
64
|
+
pk: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
65
|
+
}),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const contentResource = sqliteTable('contentResource', {
|
|
69
|
+
id: text('id', { length: 255 }).notNull().primaryKey(),
|
|
70
|
+
type: text('type', { length: 255 }).notNull(),
|
|
71
|
+
createdById: text('createdById', { length: 255 }).notNull(),
|
|
72
|
+
fields: text('metadata', { mode: 'json' }).$type<Record<string, any>>().default({}),
|
|
73
|
+
createdAt: integer('createdAt', {
|
|
74
|
+
mode: 'timestamp_ms',
|
|
75
|
+
}).default(sql`CURRENT_TIME`),
|
|
76
|
+
updatedAt: integer('updatedAt', {
|
|
77
|
+
mode: 'timestamp_ms',
|
|
78
|
+
}).default(sql`CURRENT_TIME`),
|
|
79
|
+
deletedAt: integer('deletedAt', {
|
|
80
|
+
mode: 'timestamp_ms',
|
|
81
|
+
}),
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const contentResourceResource = sqliteTable(
|
|
85
|
+
'contentResourceResource',
|
|
86
|
+
{
|
|
87
|
+
resourceOfId: text('resourceOfId', { length: 255 }).notNull(),
|
|
88
|
+
resourceId: text('resourceId', { length: 255 }).notNull(),
|
|
89
|
+
position: integer('position').notNull().default(0),
|
|
90
|
+
metadata: text('metadata', { mode: 'json' }).$type<Record<string, any>>().default({}),
|
|
91
|
+
createdAt: integer('createdAt', {
|
|
92
|
+
mode: 'timestamp_ms',
|
|
93
|
+
}).default(sql`CURRENT_TIME`),
|
|
94
|
+
updatedAt: integer('updatedAt', {
|
|
95
|
+
mode: 'timestamp_ms',
|
|
96
|
+
}).default(sql`CURRENT_TIME`),
|
|
97
|
+
deletedAt: integer('deletedAt', {
|
|
98
|
+
mode: 'timestamp_ms',
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
(crr) => ({
|
|
102
|
+
pk: primaryKey({ columns: [crr.resourceOfId, crr.resourceId] }),
|
|
62
103
|
}),
|
|
63
104
|
)
|
|
64
105
|
|
|
65
|
-
return { users, accounts, sessions, verificationTokens }
|
|
106
|
+
return { users, accounts, sessions, verificationTokens, contentResource, contentResourceResource }
|
|
66
107
|
}
|
|
67
108
|
|
|
68
109
|
export type DefaultSchema = ReturnType<typeof createTables>
|
|
@@ -70,10 +111,28 @@ export type DefaultSchema = ReturnType<typeof createTables>
|
|
|
70
111
|
export function SQLiteDrizzleAdapter(
|
|
71
112
|
client: InstanceType<typeof BaseSQLiteDatabase>,
|
|
72
113
|
tableFn = defaultSqliteTableFn,
|
|
73
|
-
):
|
|
74
|
-
const { users, accounts, sessions, verificationTokens } = createTables(tableFn)
|
|
114
|
+
): CourseBuilderAdapter {
|
|
115
|
+
const { users, accounts, sessions, verificationTokens, contentResource } = createTables(tableFn)
|
|
75
116
|
|
|
76
117
|
return {
|
|
118
|
+
async updateContentResourceFields(options) {
|
|
119
|
+
return null
|
|
120
|
+
},
|
|
121
|
+
async getVideoResource(id) {
|
|
122
|
+
// TODO Implement
|
|
123
|
+
return null
|
|
124
|
+
},
|
|
125
|
+
async createContentResource(resource) {
|
|
126
|
+
return client
|
|
127
|
+
.insert(contentResource)
|
|
128
|
+
.values({ ...resource, id: crypto.randomUUID() })
|
|
129
|
+
.returning()
|
|
130
|
+
.get()
|
|
131
|
+
},
|
|
132
|
+
async getContentResource(data) {
|
|
133
|
+
const result = await client.select().from(contentResource).where(eq(contentResource.id, data)).get()
|
|
134
|
+
return result ?? null
|
|
135
|
+
},
|
|
77
136
|
async createUser(data) {
|
|
78
137
|
return client
|
|
79
138
|
.insert(users)
|
package/src/lib/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MySqlDatabase } from 'drizzle-orm/mysql-core'
|
|
1
|
+
import { type MySqlDatabase } from 'drizzle-orm/mysql-core'
|
|
2
2
|
import type { AnyMySqlTable, MySqlTableFn } from 'drizzle-orm/mysql-core'
|
|
3
|
-
import { PgDatabase } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { type PgDatabase } from 'drizzle-orm/pg-core'
|
|
4
4
|
import type { AnyPgTable, PgTableFn } from 'drizzle-orm/pg-core'
|
|
5
|
-
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core'
|
|
5
|
+
import { type BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core'
|
|
6
6
|
import type { AnySQLiteTable, SQLiteTableFn } from 'drizzle-orm/sqlite-core'
|
|
7
7
|
|
|
8
8
|
import type { DefaultSchema as MySqlSchema } from './mysql.js'
|