@auth/drizzle-adapter 0.3.0 → 0.3.1
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/lib/mysql.d.ts +226 -0
- package/lib/mysql.d.ts.map +1 -0
- package/lib/mysql.js +192 -0
- package/lib/pg.d.ts +226 -0
- package/lib/pg.d.ts.map +1 -0
- package/lib/pg.js +180 -0
- package/lib/sqlite.d.ts +225 -0
- package/lib/sqlite.d.ts.map +1 -0
- package/lib/sqlite.js +154 -0
- package/lib/utils.d.ts +24 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +12 -0
- package/package.json +3 -3
package/lib/mysql.d.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { MySqlTableFn } from "drizzle-orm/mysql-core";
|
|
2
|
+
import type { Adapter } from "@auth/core/adapters";
|
|
3
|
+
import type { MySql2Database } from "drizzle-orm/mysql2";
|
|
4
|
+
export declare function createTables(mySqlTable: MySqlTableFn): {
|
|
5
|
+
users: import("drizzle-orm/select.types.d-b947a018").aw<{
|
|
6
|
+
name: "user";
|
|
7
|
+
schema: undefined;
|
|
8
|
+
columns: {
|
|
9
|
+
id: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
10
|
+
tableName: "user";
|
|
11
|
+
enumValues: [string, ...string[]];
|
|
12
|
+
name: "id";
|
|
13
|
+
data: string;
|
|
14
|
+
driverParam: string | number;
|
|
15
|
+
hasDefault: false;
|
|
16
|
+
notNull: true;
|
|
17
|
+
}>;
|
|
18
|
+
name: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
19
|
+
tableName: "user";
|
|
20
|
+
name: "name";
|
|
21
|
+
data: string;
|
|
22
|
+
driverParam: string | number;
|
|
23
|
+
enumValues: [string, ...string[]];
|
|
24
|
+
notNull: false;
|
|
25
|
+
hasDefault: false;
|
|
26
|
+
}>;
|
|
27
|
+
email: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
28
|
+
tableName: "user";
|
|
29
|
+
enumValues: [string, ...string[]];
|
|
30
|
+
name: "email";
|
|
31
|
+
data: string;
|
|
32
|
+
driverParam: string | number;
|
|
33
|
+
hasDefault: false;
|
|
34
|
+
notNull: true;
|
|
35
|
+
}>;
|
|
36
|
+
emailVerified: import("drizzle-orm/mysql-core").MySqlTimestamp<{
|
|
37
|
+
tableName: "user";
|
|
38
|
+
name: "emailVerified";
|
|
39
|
+
data: Date;
|
|
40
|
+
driverParam: string | number;
|
|
41
|
+
notNull: false;
|
|
42
|
+
hasDefault: true;
|
|
43
|
+
}>;
|
|
44
|
+
image: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
45
|
+
tableName: "user";
|
|
46
|
+
name: "image";
|
|
47
|
+
data: string;
|
|
48
|
+
driverParam: string | number;
|
|
49
|
+
enumValues: [string, ...string[]];
|
|
50
|
+
notNull: false;
|
|
51
|
+
hasDefault: false;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
}>;
|
|
55
|
+
accounts: import("drizzle-orm/select.types.d-b947a018").aw<{
|
|
56
|
+
name: "account";
|
|
57
|
+
schema: undefined;
|
|
58
|
+
columns: {
|
|
59
|
+
userId: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
60
|
+
tableName: "account";
|
|
61
|
+
enumValues: [string, ...string[]];
|
|
62
|
+
name: "userId";
|
|
63
|
+
data: string;
|
|
64
|
+
driverParam: string | number;
|
|
65
|
+
hasDefault: false;
|
|
66
|
+
notNull: true;
|
|
67
|
+
}>;
|
|
68
|
+
type: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
69
|
+
tableName: "account";
|
|
70
|
+
enumValues: [string, ...string[]];
|
|
71
|
+
name: "type";
|
|
72
|
+
data: "email" | "oidc" | "oauth";
|
|
73
|
+
driverParam: string | number;
|
|
74
|
+
hasDefault: false;
|
|
75
|
+
notNull: true;
|
|
76
|
+
}>;
|
|
77
|
+
provider: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
78
|
+
tableName: "account";
|
|
79
|
+
enumValues: [string, ...string[]];
|
|
80
|
+
name: "provider";
|
|
81
|
+
data: string;
|
|
82
|
+
driverParam: string | number;
|
|
83
|
+
hasDefault: false;
|
|
84
|
+
notNull: true;
|
|
85
|
+
}>;
|
|
86
|
+
providerAccountId: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
87
|
+
tableName: "account";
|
|
88
|
+
enumValues: [string, ...string[]];
|
|
89
|
+
name: "providerAccountId";
|
|
90
|
+
data: string;
|
|
91
|
+
driverParam: string | number;
|
|
92
|
+
hasDefault: false;
|
|
93
|
+
notNull: true;
|
|
94
|
+
}>;
|
|
95
|
+
refresh_token: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
96
|
+
tableName: "account";
|
|
97
|
+
name: "refresh_token";
|
|
98
|
+
data: string;
|
|
99
|
+
driverParam: string | number;
|
|
100
|
+
enumValues: [string, ...string[]];
|
|
101
|
+
notNull: false;
|
|
102
|
+
hasDefault: false;
|
|
103
|
+
}>;
|
|
104
|
+
access_token: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
105
|
+
tableName: "account";
|
|
106
|
+
name: "access_token";
|
|
107
|
+
data: string;
|
|
108
|
+
driverParam: string | number;
|
|
109
|
+
enumValues: [string, ...string[]];
|
|
110
|
+
notNull: false;
|
|
111
|
+
hasDefault: false;
|
|
112
|
+
}>;
|
|
113
|
+
expires_at: import("drizzle-orm/mysql-core").MySqlInt<{
|
|
114
|
+
tableName: "account";
|
|
115
|
+
name: "expires_at";
|
|
116
|
+
data: number;
|
|
117
|
+
driverParam: string | number;
|
|
118
|
+
notNull: false;
|
|
119
|
+
hasDefault: false;
|
|
120
|
+
}>;
|
|
121
|
+
token_type: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
122
|
+
tableName: "account";
|
|
123
|
+
name: "token_type";
|
|
124
|
+
data: string;
|
|
125
|
+
driverParam: string | number;
|
|
126
|
+
enumValues: [string, ...string[]];
|
|
127
|
+
notNull: false;
|
|
128
|
+
hasDefault: false;
|
|
129
|
+
}>;
|
|
130
|
+
scope: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
131
|
+
tableName: "account";
|
|
132
|
+
name: "scope";
|
|
133
|
+
data: string;
|
|
134
|
+
driverParam: string | number;
|
|
135
|
+
enumValues: [string, ...string[]];
|
|
136
|
+
notNull: false;
|
|
137
|
+
hasDefault: false;
|
|
138
|
+
}>;
|
|
139
|
+
id_token: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
140
|
+
tableName: "account";
|
|
141
|
+
name: "id_token";
|
|
142
|
+
data: string;
|
|
143
|
+
driverParam: string | number;
|
|
144
|
+
enumValues: [string, ...string[]];
|
|
145
|
+
notNull: false;
|
|
146
|
+
hasDefault: false;
|
|
147
|
+
}>;
|
|
148
|
+
session_state: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
149
|
+
tableName: "account";
|
|
150
|
+
name: "session_state";
|
|
151
|
+
data: string;
|
|
152
|
+
driverParam: string | number;
|
|
153
|
+
enumValues: [string, ...string[]];
|
|
154
|
+
notNull: false;
|
|
155
|
+
hasDefault: false;
|
|
156
|
+
}>;
|
|
157
|
+
};
|
|
158
|
+
}>;
|
|
159
|
+
sessions: import("drizzle-orm/select.types.d-b947a018").aw<{
|
|
160
|
+
name: "session";
|
|
161
|
+
schema: undefined;
|
|
162
|
+
columns: {
|
|
163
|
+
sessionToken: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
164
|
+
tableName: "session";
|
|
165
|
+
enumValues: [string, ...string[]];
|
|
166
|
+
name: "sessionToken";
|
|
167
|
+
data: string;
|
|
168
|
+
driverParam: string | number;
|
|
169
|
+
hasDefault: false;
|
|
170
|
+
notNull: true;
|
|
171
|
+
}>;
|
|
172
|
+
userId: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
173
|
+
tableName: "session";
|
|
174
|
+
enumValues: [string, ...string[]];
|
|
175
|
+
name: "userId";
|
|
176
|
+
data: string;
|
|
177
|
+
driverParam: string | number;
|
|
178
|
+
hasDefault: false;
|
|
179
|
+
notNull: true;
|
|
180
|
+
}>;
|
|
181
|
+
expires: import("drizzle-orm/mysql-core").MySqlTimestamp<{
|
|
182
|
+
tableName: "session";
|
|
183
|
+
name: "expires";
|
|
184
|
+
data: Date;
|
|
185
|
+
driverParam: string | number;
|
|
186
|
+
hasDefault: false;
|
|
187
|
+
notNull: true;
|
|
188
|
+
}>;
|
|
189
|
+
};
|
|
190
|
+
}>;
|
|
191
|
+
verificationTokens: import("drizzle-orm/select.types.d-b947a018").aw<{
|
|
192
|
+
name: "verificationToken";
|
|
193
|
+
schema: undefined;
|
|
194
|
+
columns: {
|
|
195
|
+
identifier: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
196
|
+
tableName: "verificationToken";
|
|
197
|
+
enumValues: [string, ...string[]];
|
|
198
|
+
name: "identifier";
|
|
199
|
+
data: string;
|
|
200
|
+
driverParam: string | number;
|
|
201
|
+
hasDefault: false;
|
|
202
|
+
notNull: true;
|
|
203
|
+
}>;
|
|
204
|
+
token: import("drizzle-orm/mysql-core").MySqlVarChar<{
|
|
205
|
+
tableName: "verificationToken";
|
|
206
|
+
enumValues: [string, ...string[]];
|
|
207
|
+
name: "token";
|
|
208
|
+
data: string;
|
|
209
|
+
driverParam: string | number;
|
|
210
|
+
hasDefault: false;
|
|
211
|
+
notNull: true;
|
|
212
|
+
}>;
|
|
213
|
+
expires: import("drizzle-orm/mysql-core").MySqlTimestamp<{
|
|
214
|
+
tableName: "verificationToken";
|
|
215
|
+
name: "expires";
|
|
216
|
+
data: Date;
|
|
217
|
+
driverParam: string | number;
|
|
218
|
+
hasDefault: false;
|
|
219
|
+
notNull: true;
|
|
220
|
+
}>;
|
|
221
|
+
};
|
|
222
|
+
}>;
|
|
223
|
+
};
|
|
224
|
+
export type DefaultSchema = ReturnType<typeof createTables>;
|
|
225
|
+
export declare function mySqlDrizzleAdapter(client: MySql2Database<Record<string, never>>, tableFn?: MySqlTableFn<undefined>): Adapter;
|
|
226
|
+
//# sourceMappingURL=mysql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../src/lib/mysql.ts"],"names":[],"mappings":"AACA,OAAO,EAML,YAAY,EACb,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,qBAAqB,CAAA;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,wBAAgB,YAAY,CAAC,UAAU,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6DpD;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAA;AAE3D,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAC7C,OAAO,0BAAsB,GAC5B,OAAO,CAyLT"}
|
package/lib/mysql.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { and, eq } from "drizzle-orm";
|
|
2
|
+
import { int, timestamp, mysqlTable as defaultMySqlTableFn, primaryKey, varchar, } from "drizzle-orm/mysql-core";
|
|
3
|
+
export function createTables(mySqlTable) {
|
|
4
|
+
const users = mySqlTable("user", {
|
|
5
|
+
id: varchar("id", { length: 255 }).notNull().primaryKey(),
|
|
6
|
+
name: varchar("name", { length: 255 }),
|
|
7
|
+
email: varchar("email", { length: 255 }).notNull(),
|
|
8
|
+
emailVerified: timestamp("emailVerified", {
|
|
9
|
+
mode: "date",
|
|
10
|
+
fsp: 3,
|
|
11
|
+
}).defaultNow(),
|
|
12
|
+
image: varchar("image", { length: 255 }),
|
|
13
|
+
});
|
|
14
|
+
const accounts = mySqlTable("account", {
|
|
15
|
+
userId: varchar("userId", { length: 255 })
|
|
16
|
+
.notNull()
|
|
17
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
18
|
+
type: varchar("type", { length: 255 })
|
|
19
|
+
.$type()
|
|
20
|
+
.notNull(),
|
|
21
|
+
provider: varchar("provider", { length: 255 }).notNull(),
|
|
22
|
+
providerAccountId: varchar("providerAccountId", {
|
|
23
|
+
length: 255,
|
|
24
|
+
}).notNull(),
|
|
25
|
+
refresh_token: varchar("refresh_token", { length: 255 }),
|
|
26
|
+
access_token: varchar("access_token", { length: 255 }),
|
|
27
|
+
expires_at: int("expires_at"),
|
|
28
|
+
token_type: varchar("token_type", { length: 255 }),
|
|
29
|
+
scope: varchar("scope", { length: 255 }),
|
|
30
|
+
id_token: varchar("id_token", { length: 255 }),
|
|
31
|
+
session_state: varchar("session_state", { length: 255 }),
|
|
32
|
+
}, (account) => ({
|
|
33
|
+
compoundKey: primaryKey(account.provider, account.providerAccountId),
|
|
34
|
+
}));
|
|
35
|
+
const sessions = mySqlTable("session", {
|
|
36
|
+
sessionToken: varchar("sessionToken", { length: 255 })
|
|
37
|
+
.notNull()
|
|
38
|
+
.primaryKey(),
|
|
39
|
+
userId: varchar("userId", { length: 255 })
|
|
40
|
+
.notNull()
|
|
41
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
42
|
+
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
43
|
+
});
|
|
44
|
+
const verificationTokens = mySqlTable("verificationToken", {
|
|
45
|
+
identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
46
|
+
token: varchar("token", { length: 255 }).notNull(),
|
|
47
|
+
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
48
|
+
}, (vt) => ({
|
|
49
|
+
compoundKey: primaryKey(vt.identifier, vt.token),
|
|
50
|
+
}));
|
|
51
|
+
return { users, accounts, sessions, verificationTokens };
|
|
52
|
+
}
|
|
53
|
+
export function mySqlDrizzleAdapter(client, tableFn = defaultMySqlTableFn) {
|
|
54
|
+
const { users, accounts, sessions, verificationTokens } = createTables(tableFn);
|
|
55
|
+
return {
|
|
56
|
+
async createUser(data) {
|
|
57
|
+
const id = crypto.randomUUID();
|
|
58
|
+
await client.insert(users).values({ ...data, id });
|
|
59
|
+
return await client
|
|
60
|
+
.select()
|
|
61
|
+
.from(users)
|
|
62
|
+
.where(eq(users.id, id))
|
|
63
|
+
.then((res) => res[0]);
|
|
64
|
+
},
|
|
65
|
+
async getUser(data) {
|
|
66
|
+
const thing = (await client
|
|
67
|
+
.select()
|
|
68
|
+
.from(users)
|
|
69
|
+
.where(eq(users.id, data))
|
|
70
|
+
.then((res) => res[0])) ?? null;
|
|
71
|
+
return thing;
|
|
72
|
+
},
|
|
73
|
+
async getUserByEmail(data) {
|
|
74
|
+
const user = (await client
|
|
75
|
+
.select()
|
|
76
|
+
.from(users)
|
|
77
|
+
.where(eq(users.email, data))
|
|
78
|
+
.then((res) => res[0])) ?? null;
|
|
79
|
+
return user;
|
|
80
|
+
},
|
|
81
|
+
async createSession(data) {
|
|
82
|
+
await client.insert(sessions).values(data);
|
|
83
|
+
return await client
|
|
84
|
+
.select()
|
|
85
|
+
.from(sessions)
|
|
86
|
+
.where(eq(sessions.sessionToken, data.sessionToken))
|
|
87
|
+
.then((res) => res[0]);
|
|
88
|
+
},
|
|
89
|
+
async getSessionAndUser(data) {
|
|
90
|
+
const sessionAndUser = (await client
|
|
91
|
+
.select({
|
|
92
|
+
session: sessions,
|
|
93
|
+
user: users,
|
|
94
|
+
})
|
|
95
|
+
.from(sessions)
|
|
96
|
+
.where(eq(sessions.sessionToken, data))
|
|
97
|
+
.innerJoin(users, eq(users.id, sessions.userId))
|
|
98
|
+
.then((res) => res[0])) ?? null;
|
|
99
|
+
return sessionAndUser;
|
|
100
|
+
},
|
|
101
|
+
async updateUser(data) {
|
|
102
|
+
if (!data.id) {
|
|
103
|
+
throw new Error("No user id.");
|
|
104
|
+
}
|
|
105
|
+
await client.update(users).set(data).where(eq(users.id, data.id));
|
|
106
|
+
return await client
|
|
107
|
+
.select()
|
|
108
|
+
.from(users)
|
|
109
|
+
.where(eq(users.id, data.id))
|
|
110
|
+
.then((res) => res[0]);
|
|
111
|
+
},
|
|
112
|
+
async updateSession(data) {
|
|
113
|
+
await client
|
|
114
|
+
.update(sessions)
|
|
115
|
+
.set(data)
|
|
116
|
+
.where(eq(sessions.sessionToken, data.sessionToken));
|
|
117
|
+
return await client
|
|
118
|
+
.select()
|
|
119
|
+
.from(sessions)
|
|
120
|
+
.where(eq(sessions.sessionToken, data.sessionToken))
|
|
121
|
+
.then((res) => res[0]);
|
|
122
|
+
},
|
|
123
|
+
async linkAccount(rawAccount) {
|
|
124
|
+
await client
|
|
125
|
+
.insert(accounts)
|
|
126
|
+
.values(rawAccount)
|
|
127
|
+
.then((res) => res[0]);
|
|
128
|
+
},
|
|
129
|
+
async getUserByAccount(account) {
|
|
130
|
+
const dbAccount = (await client
|
|
131
|
+
.select()
|
|
132
|
+
.from(accounts)
|
|
133
|
+
.where(and(eq(accounts.providerAccountId, account.providerAccountId), eq(accounts.provider, account.provider)))
|
|
134
|
+
.leftJoin(users, eq(accounts.userId, users.id))
|
|
135
|
+
.then((res) => res[0])) ?? null;
|
|
136
|
+
if (!dbAccount) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return dbAccount.user;
|
|
140
|
+
},
|
|
141
|
+
async deleteSession(sessionToken) {
|
|
142
|
+
const session = (await client
|
|
143
|
+
.select()
|
|
144
|
+
.from(sessions)
|
|
145
|
+
.where(eq(sessions.sessionToken, sessionToken))
|
|
146
|
+
.then((res) => res[0])) ?? null;
|
|
147
|
+
await client
|
|
148
|
+
.delete(sessions)
|
|
149
|
+
.where(eq(sessions.sessionToken, sessionToken));
|
|
150
|
+
return session;
|
|
151
|
+
},
|
|
152
|
+
async createVerificationToken(token) {
|
|
153
|
+
await client.insert(verificationTokens).values(token);
|
|
154
|
+
return await client
|
|
155
|
+
.select()
|
|
156
|
+
.from(verificationTokens)
|
|
157
|
+
.where(eq(verificationTokens.identifier, token.identifier))
|
|
158
|
+
.then((res) => res[0]);
|
|
159
|
+
},
|
|
160
|
+
async useVerificationToken(token) {
|
|
161
|
+
try {
|
|
162
|
+
const deletedToken = (await client
|
|
163
|
+
.select()
|
|
164
|
+
.from(verificationTokens)
|
|
165
|
+
.where(and(eq(verificationTokens.identifier, token.identifier), eq(verificationTokens.token, token.token)))
|
|
166
|
+
.then((res) => res[0])) ?? null;
|
|
167
|
+
await client
|
|
168
|
+
.delete(verificationTokens)
|
|
169
|
+
.where(and(eq(verificationTokens.identifier, token.identifier), eq(verificationTokens.token, token.token)));
|
|
170
|
+
return deletedToken;
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
throw new Error("No verification token found.");
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
async deleteUser(id) {
|
|
177
|
+
const user = await client
|
|
178
|
+
.select()
|
|
179
|
+
.from(users)
|
|
180
|
+
.where(eq(users.id, id))
|
|
181
|
+
.then((res) => res[0] ?? null);
|
|
182
|
+
await client.delete(users).where(eq(users.id, id));
|
|
183
|
+
return user;
|
|
184
|
+
},
|
|
185
|
+
async unlinkAccount(account) {
|
|
186
|
+
await client
|
|
187
|
+
.delete(accounts)
|
|
188
|
+
.where(and(eq(accounts.providerAccountId, account.providerAccountId), eq(accounts.provider, account.provider)));
|
|
189
|
+
return undefined;
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
package/lib/pg.d.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { PgTableFn } from "drizzle-orm/pg-core";
|
|
2
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
3
|
+
import type { Adapter } from "@auth/core/adapters";
|
|
4
|
+
export declare function createTables(pgTable: PgTableFn): {
|
|
5
|
+
users: import("drizzle-orm/db.d-b9835153").az<{
|
|
6
|
+
name: "user";
|
|
7
|
+
schema: undefined;
|
|
8
|
+
columns: {
|
|
9
|
+
id: import("drizzle-orm/pg-core").PgText<{
|
|
10
|
+
tableName: "user";
|
|
11
|
+
enumValues: [string, ...string[]];
|
|
12
|
+
name: "id";
|
|
13
|
+
data: string;
|
|
14
|
+
driverParam: string;
|
|
15
|
+
hasDefault: false;
|
|
16
|
+
notNull: true;
|
|
17
|
+
}>;
|
|
18
|
+
name: import("drizzle-orm/pg-core").PgText<{
|
|
19
|
+
tableName: "user";
|
|
20
|
+
name: "name";
|
|
21
|
+
data: string;
|
|
22
|
+
enumValues: [string, ...string[]];
|
|
23
|
+
driverParam: string;
|
|
24
|
+
notNull: false;
|
|
25
|
+
hasDefault: false;
|
|
26
|
+
}>;
|
|
27
|
+
email: import("drizzle-orm/pg-core").PgText<{
|
|
28
|
+
tableName: "user";
|
|
29
|
+
enumValues: [string, ...string[]];
|
|
30
|
+
name: "email";
|
|
31
|
+
data: string;
|
|
32
|
+
driverParam: string;
|
|
33
|
+
hasDefault: false;
|
|
34
|
+
notNull: true;
|
|
35
|
+
}>;
|
|
36
|
+
emailVerified: import("drizzle-orm/pg-core").PgTimestamp<{
|
|
37
|
+
tableName: "user";
|
|
38
|
+
name: "emailVerified";
|
|
39
|
+
data: Date;
|
|
40
|
+
driverParam: string;
|
|
41
|
+
notNull: false;
|
|
42
|
+
hasDefault: false;
|
|
43
|
+
}>;
|
|
44
|
+
image: import("drizzle-orm/pg-core").PgText<{
|
|
45
|
+
tableName: "user";
|
|
46
|
+
name: "image";
|
|
47
|
+
data: string;
|
|
48
|
+
enumValues: [string, ...string[]];
|
|
49
|
+
driverParam: string;
|
|
50
|
+
notNull: false;
|
|
51
|
+
hasDefault: false;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
}>;
|
|
55
|
+
accounts: import("drizzle-orm/db.d-b9835153").az<{
|
|
56
|
+
name: "account";
|
|
57
|
+
schema: undefined;
|
|
58
|
+
columns: {
|
|
59
|
+
userId: import("drizzle-orm/pg-core").PgText<{
|
|
60
|
+
tableName: "account";
|
|
61
|
+
enumValues: [string, ...string[]];
|
|
62
|
+
name: "userId";
|
|
63
|
+
data: string;
|
|
64
|
+
driverParam: string;
|
|
65
|
+
hasDefault: false;
|
|
66
|
+
notNull: true;
|
|
67
|
+
}>;
|
|
68
|
+
type: import("drizzle-orm/pg-core").PgText<{
|
|
69
|
+
tableName: "account";
|
|
70
|
+
enumValues: [string, ...string[]];
|
|
71
|
+
name: "type";
|
|
72
|
+
data: "email" | "oidc" | "oauth";
|
|
73
|
+
driverParam: string;
|
|
74
|
+
hasDefault: false;
|
|
75
|
+
notNull: true;
|
|
76
|
+
}>;
|
|
77
|
+
provider: import("drizzle-orm/pg-core").PgText<{
|
|
78
|
+
tableName: "account";
|
|
79
|
+
enumValues: [string, ...string[]];
|
|
80
|
+
name: "provider";
|
|
81
|
+
data: string;
|
|
82
|
+
driverParam: string;
|
|
83
|
+
hasDefault: false;
|
|
84
|
+
notNull: true;
|
|
85
|
+
}>;
|
|
86
|
+
providerAccountId: import("drizzle-orm/pg-core").PgText<{
|
|
87
|
+
tableName: "account";
|
|
88
|
+
enumValues: [string, ...string[]];
|
|
89
|
+
name: "providerAccountId";
|
|
90
|
+
data: string;
|
|
91
|
+
driverParam: string;
|
|
92
|
+
hasDefault: false;
|
|
93
|
+
notNull: true;
|
|
94
|
+
}>;
|
|
95
|
+
refresh_token: import("drizzle-orm/pg-core").PgText<{
|
|
96
|
+
tableName: "account";
|
|
97
|
+
name: "refresh_token";
|
|
98
|
+
data: string;
|
|
99
|
+
enumValues: [string, ...string[]];
|
|
100
|
+
driverParam: string;
|
|
101
|
+
notNull: false;
|
|
102
|
+
hasDefault: false;
|
|
103
|
+
}>;
|
|
104
|
+
access_token: import("drizzle-orm/pg-core").PgText<{
|
|
105
|
+
tableName: "account";
|
|
106
|
+
name: "access_token";
|
|
107
|
+
data: string;
|
|
108
|
+
enumValues: [string, ...string[]];
|
|
109
|
+
driverParam: string;
|
|
110
|
+
notNull: false;
|
|
111
|
+
hasDefault: false;
|
|
112
|
+
}>;
|
|
113
|
+
expires_at: import("drizzle-orm/pg-core").PgInteger<{
|
|
114
|
+
tableName: "account";
|
|
115
|
+
name: "expires_at";
|
|
116
|
+
data: number;
|
|
117
|
+
driverParam: string | number;
|
|
118
|
+
hasDefault: false;
|
|
119
|
+
notNull: false;
|
|
120
|
+
}>;
|
|
121
|
+
token_type: import("drizzle-orm/pg-core").PgText<{
|
|
122
|
+
tableName: "account";
|
|
123
|
+
name: "token_type";
|
|
124
|
+
data: string;
|
|
125
|
+
enumValues: [string, ...string[]];
|
|
126
|
+
driverParam: string;
|
|
127
|
+
notNull: false;
|
|
128
|
+
hasDefault: false;
|
|
129
|
+
}>;
|
|
130
|
+
scope: import("drizzle-orm/pg-core").PgText<{
|
|
131
|
+
tableName: "account";
|
|
132
|
+
name: "scope";
|
|
133
|
+
data: string;
|
|
134
|
+
enumValues: [string, ...string[]];
|
|
135
|
+
driverParam: string;
|
|
136
|
+
notNull: false;
|
|
137
|
+
hasDefault: false;
|
|
138
|
+
}>;
|
|
139
|
+
id_token: import("drizzle-orm/pg-core").PgText<{
|
|
140
|
+
tableName: "account";
|
|
141
|
+
name: "id_token";
|
|
142
|
+
data: string;
|
|
143
|
+
enumValues: [string, ...string[]];
|
|
144
|
+
driverParam: string;
|
|
145
|
+
notNull: false;
|
|
146
|
+
hasDefault: false;
|
|
147
|
+
}>;
|
|
148
|
+
session_state: import("drizzle-orm/pg-core").PgText<{
|
|
149
|
+
tableName: "account";
|
|
150
|
+
name: "session_state";
|
|
151
|
+
data: string;
|
|
152
|
+
enumValues: [string, ...string[]];
|
|
153
|
+
driverParam: string;
|
|
154
|
+
notNull: false;
|
|
155
|
+
hasDefault: false;
|
|
156
|
+
}>;
|
|
157
|
+
};
|
|
158
|
+
}>;
|
|
159
|
+
sessions: import("drizzle-orm/db.d-b9835153").az<{
|
|
160
|
+
name: "session";
|
|
161
|
+
schema: undefined;
|
|
162
|
+
columns: {
|
|
163
|
+
sessionToken: import("drizzle-orm/pg-core").PgText<{
|
|
164
|
+
tableName: "session";
|
|
165
|
+
enumValues: [string, ...string[]];
|
|
166
|
+
name: "sessionToken";
|
|
167
|
+
data: string;
|
|
168
|
+
driverParam: string;
|
|
169
|
+
hasDefault: false;
|
|
170
|
+
notNull: true;
|
|
171
|
+
}>;
|
|
172
|
+
userId: import("drizzle-orm/pg-core").PgText<{
|
|
173
|
+
tableName: "session";
|
|
174
|
+
enumValues: [string, ...string[]];
|
|
175
|
+
name: "userId";
|
|
176
|
+
data: string;
|
|
177
|
+
driverParam: string;
|
|
178
|
+
hasDefault: false;
|
|
179
|
+
notNull: true;
|
|
180
|
+
}>;
|
|
181
|
+
expires: import("drizzle-orm/pg-core").PgTimestamp<{
|
|
182
|
+
tableName: "session";
|
|
183
|
+
name: "expires";
|
|
184
|
+
data: Date;
|
|
185
|
+
driverParam: string;
|
|
186
|
+
hasDefault: false;
|
|
187
|
+
notNull: true;
|
|
188
|
+
}>;
|
|
189
|
+
};
|
|
190
|
+
}>;
|
|
191
|
+
verificationTokens: import("drizzle-orm/db.d-b9835153").az<{
|
|
192
|
+
name: "verificationToken";
|
|
193
|
+
schema: undefined;
|
|
194
|
+
columns: {
|
|
195
|
+
identifier: import("drizzle-orm/pg-core").PgText<{
|
|
196
|
+
tableName: "verificationToken";
|
|
197
|
+
enumValues: [string, ...string[]];
|
|
198
|
+
name: "identifier";
|
|
199
|
+
data: string;
|
|
200
|
+
driverParam: string;
|
|
201
|
+
hasDefault: false;
|
|
202
|
+
notNull: true;
|
|
203
|
+
}>;
|
|
204
|
+
token: import("drizzle-orm/pg-core").PgText<{
|
|
205
|
+
tableName: "verificationToken";
|
|
206
|
+
enumValues: [string, ...string[]];
|
|
207
|
+
name: "token";
|
|
208
|
+
data: string;
|
|
209
|
+
driverParam: string;
|
|
210
|
+
hasDefault: false;
|
|
211
|
+
notNull: true;
|
|
212
|
+
}>;
|
|
213
|
+
expires: import("drizzle-orm/pg-core").PgTimestamp<{
|
|
214
|
+
tableName: "verificationToken";
|
|
215
|
+
name: "expires";
|
|
216
|
+
data: Date;
|
|
217
|
+
driverParam: string;
|
|
218
|
+
hasDefault: false;
|
|
219
|
+
notNull: true;
|
|
220
|
+
}>;
|
|
221
|
+
};
|
|
222
|
+
}>;
|
|
223
|
+
};
|
|
224
|
+
export type DefaultSchema = ReturnType<typeof createTables>;
|
|
225
|
+
export declare function pgDrizzleAdapter(client: PostgresJsDatabase<Record<string, never>>, tableFn?: PgTableFn<undefined>): Adapter;
|
|
226
|
+
//# sourceMappingURL=pg.d.ts.map
|
package/lib/pg.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../src/lib/pg.ts"],"names":[],"mappings":"AACA,OAAO,EAML,SAAS,EACV,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,qBAAqB,CAAA;AAElE,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoD9C;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAA;AAE3D,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EACjD,OAAO,uBAAmB,GACzB,OAAO,CAgKT"}
|
package/lib/pg.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { and, eq } from "drizzle-orm";
|
|
2
|
+
import { timestamp, pgTable as defaultPgTableFn, text, primaryKey, integer, } from "drizzle-orm/pg-core";
|
|
3
|
+
export function createTables(pgTable) {
|
|
4
|
+
const users = pgTable("user", {
|
|
5
|
+
id: text("id").notNull().primaryKey(),
|
|
6
|
+
name: text("name"),
|
|
7
|
+
email: text("email").notNull(),
|
|
8
|
+
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
9
|
+
image: text("image"),
|
|
10
|
+
});
|
|
11
|
+
const accounts = pgTable("account", {
|
|
12
|
+
userId: text("userId")
|
|
13
|
+
.notNull()
|
|
14
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
15
|
+
type: text("type").$type().notNull(),
|
|
16
|
+
provider: text("provider").notNull(),
|
|
17
|
+
providerAccountId: text("providerAccountId").notNull(),
|
|
18
|
+
refresh_token: text("refresh_token"),
|
|
19
|
+
access_token: text("access_token"),
|
|
20
|
+
expires_at: integer("expires_at"),
|
|
21
|
+
token_type: text("token_type"),
|
|
22
|
+
scope: text("scope"),
|
|
23
|
+
id_token: text("id_token"),
|
|
24
|
+
session_state: text("session_state"),
|
|
25
|
+
}, (account) => ({
|
|
26
|
+
compoundKey: primaryKey(account.provider, account.providerAccountId),
|
|
27
|
+
}));
|
|
28
|
+
const sessions = pgTable("session", {
|
|
29
|
+
sessionToken: text("sessionToken").notNull().primaryKey(),
|
|
30
|
+
userId: text("userId")
|
|
31
|
+
.notNull()
|
|
32
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
33
|
+
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
34
|
+
});
|
|
35
|
+
const verificationTokens = pgTable("verificationToken", {
|
|
36
|
+
identifier: text("identifier").notNull(),
|
|
37
|
+
token: text("token").notNull(),
|
|
38
|
+
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
39
|
+
}, (vt) => ({
|
|
40
|
+
compoundKey: primaryKey(vt.identifier, vt.token),
|
|
41
|
+
}));
|
|
42
|
+
return { users, accounts, sessions, verificationTokens };
|
|
43
|
+
}
|
|
44
|
+
export function pgDrizzleAdapter(client, tableFn = defaultPgTableFn) {
|
|
45
|
+
const { users, accounts, sessions, verificationTokens } = createTables(tableFn);
|
|
46
|
+
return {
|
|
47
|
+
async createUser(data) {
|
|
48
|
+
return await client
|
|
49
|
+
.insert(users)
|
|
50
|
+
.values({ ...data, id: crypto.randomUUID() })
|
|
51
|
+
.returning()
|
|
52
|
+
.then((res) => res[0] ?? null);
|
|
53
|
+
},
|
|
54
|
+
async getUser(data) {
|
|
55
|
+
return await client
|
|
56
|
+
.select()
|
|
57
|
+
.from(users)
|
|
58
|
+
.where(eq(users.id, data))
|
|
59
|
+
.then((res) => res[0] ?? null);
|
|
60
|
+
},
|
|
61
|
+
async getUserByEmail(data) {
|
|
62
|
+
return await client
|
|
63
|
+
.select()
|
|
64
|
+
.from(users)
|
|
65
|
+
.where(eq(users.email, data))
|
|
66
|
+
.then((res) => res[0] ?? null);
|
|
67
|
+
},
|
|
68
|
+
async createSession(data) {
|
|
69
|
+
return await client
|
|
70
|
+
.insert(sessions)
|
|
71
|
+
.values(data)
|
|
72
|
+
.returning()
|
|
73
|
+
.then((res) => res[0]);
|
|
74
|
+
},
|
|
75
|
+
async getSessionAndUser(data) {
|
|
76
|
+
return await client
|
|
77
|
+
.select({
|
|
78
|
+
session: sessions,
|
|
79
|
+
user: users,
|
|
80
|
+
})
|
|
81
|
+
.from(sessions)
|
|
82
|
+
.where(eq(sessions.sessionToken, data))
|
|
83
|
+
.innerJoin(users, eq(users.id, sessions.userId))
|
|
84
|
+
.then((res) => res[0] ?? null);
|
|
85
|
+
},
|
|
86
|
+
async updateUser(data) {
|
|
87
|
+
if (!data.id) {
|
|
88
|
+
throw new Error("No user id.");
|
|
89
|
+
}
|
|
90
|
+
return await client
|
|
91
|
+
.update(users)
|
|
92
|
+
.set(data)
|
|
93
|
+
.where(eq(users.id, data.id))
|
|
94
|
+
.returning()
|
|
95
|
+
.then((res) => res[0]);
|
|
96
|
+
},
|
|
97
|
+
async updateSession(data) {
|
|
98
|
+
return await client
|
|
99
|
+
.update(sessions)
|
|
100
|
+
.set(data)
|
|
101
|
+
.where(eq(sessions.sessionToken, data.sessionToken))
|
|
102
|
+
.returning()
|
|
103
|
+
.then((res) => res[0]);
|
|
104
|
+
},
|
|
105
|
+
async linkAccount(rawAccount) {
|
|
106
|
+
const updatedAccount = await client
|
|
107
|
+
.insert(accounts)
|
|
108
|
+
.values(rawAccount)
|
|
109
|
+
.returning()
|
|
110
|
+
.then((res) => res[0]);
|
|
111
|
+
// Drizzle will return `null` for fields that are not defined.
|
|
112
|
+
// However, the return type is expecting `undefined`.
|
|
113
|
+
const account = {
|
|
114
|
+
...updatedAccount,
|
|
115
|
+
access_token: updatedAccount.access_token ?? undefined,
|
|
116
|
+
token_type: updatedAccount.token_type ?? undefined,
|
|
117
|
+
id_token: updatedAccount.id_token ?? undefined,
|
|
118
|
+
refresh_token: updatedAccount.refresh_token ?? undefined,
|
|
119
|
+
scope: updatedAccount.scope ?? undefined,
|
|
120
|
+
expires_at: updatedAccount.expires_at ?? undefined,
|
|
121
|
+
session_state: updatedAccount.session_state ?? undefined,
|
|
122
|
+
};
|
|
123
|
+
return account;
|
|
124
|
+
},
|
|
125
|
+
async getUserByAccount(account) {
|
|
126
|
+
const dbAccount = (await client
|
|
127
|
+
.select()
|
|
128
|
+
.from(accounts)
|
|
129
|
+
.where(and(eq(accounts.providerAccountId, account.providerAccountId), eq(accounts.provider, account.provider)))
|
|
130
|
+
.leftJoin(users, eq(accounts.userId, users.id))
|
|
131
|
+
.then((res) => res[0])) ?? null;
|
|
132
|
+
if (!dbAccount) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return dbAccount.user;
|
|
136
|
+
},
|
|
137
|
+
async deleteSession(sessionToken) {
|
|
138
|
+
const session = await client
|
|
139
|
+
.delete(sessions)
|
|
140
|
+
.where(eq(sessions.sessionToken, sessionToken))
|
|
141
|
+
.returning()
|
|
142
|
+
.then((res) => res[0] ?? null);
|
|
143
|
+
return session;
|
|
144
|
+
},
|
|
145
|
+
async createVerificationToken(token) {
|
|
146
|
+
return await client
|
|
147
|
+
.insert(verificationTokens)
|
|
148
|
+
.values(token)
|
|
149
|
+
.returning()
|
|
150
|
+
.then((res) => res[0]);
|
|
151
|
+
},
|
|
152
|
+
async useVerificationToken(token) {
|
|
153
|
+
try {
|
|
154
|
+
return await client
|
|
155
|
+
.delete(verificationTokens)
|
|
156
|
+
.where(and(eq(verificationTokens.identifier, token.identifier), eq(verificationTokens.token, token.token)))
|
|
157
|
+
.returning()
|
|
158
|
+
.then((res) => res[0] ?? null);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
throw new Error("No verification token found.");
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
async deleteUser(id) {
|
|
165
|
+
await client
|
|
166
|
+
.delete(users)
|
|
167
|
+
.where(eq(users.id, id))
|
|
168
|
+
.returning()
|
|
169
|
+
.then((res) => res[0] ?? null);
|
|
170
|
+
},
|
|
171
|
+
async unlinkAccount(account) {
|
|
172
|
+
const { type, provider, providerAccountId, userId } = await client
|
|
173
|
+
.delete(accounts)
|
|
174
|
+
.where(and(eq(accounts.providerAccountId, account.providerAccountId), eq(accounts.provider, account.provider)))
|
|
175
|
+
.returning()
|
|
176
|
+
.then((res) => res[0] ?? null);
|
|
177
|
+
return { provider, type, providerAccountId, userId };
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
package/lib/sqlite.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { BaseSQLiteDatabase, SQLiteTableFn } from "drizzle-orm/sqlite-core";
|
|
2
|
+
import type { Adapter } from "@auth/core/adapters";
|
|
3
|
+
export declare function createTables(sqliteTable: SQLiteTableFn): {
|
|
4
|
+
users: import("drizzle-orm/db.d-b5fdf746").ag<{
|
|
5
|
+
name: "user";
|
|
6
|
+
schema: undefined;
|
|
7
|
+
columns: {
|
|
8
|
+
id: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
9
|
+
tableName: "user";
|
|
10
|
+
enumValues: [string, ...string[]];
|
|
11
|
+
name: "id";
|
|
12
|
+
data: string;
|
|
13
|
+
driverParam: string;
|
|
14
|
+
hasDefault: false;
|
|
15
|
+
notNull: true;
|
|
16
|
+
}>;
|
|
17
|
+
name: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
18
|
+
tableName: "user";
|
|
19
|
+
name: "name";
|
|
20
|
+
data: string;
|
|
21
|
+
driverParam: string;
|
|
22
|
+
enumValues: [string, ...string[]];
|
|
23
|
+
notNull: false;
|
|
24
|
+
hasDefault: false;
|
|
25
|
+
}>;
|
|
26
|
+
email: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
27
|
+
tableName: "user";
|
|
28
|
+
enumValues: [string, ...string[]];
|
|
29
|
+
name: "email";
|
|
30
|
+
data: string;
|
|
31
|
+
driverParam: string;
|
|
32
|
+
hasDefault: false;
|
|
33
|
+
notNull: true;
|
|
34
|
+
}>;
|
|
35
|
+
emailVerified: import("drizzle-orm/sqlite-core").SQLiteTimestamp<{
|
|
36
|
+
tableName: "user";
|
|
37
|
+
name: "emailVerified";
|
|
38
|
+
data: Date;
|
|
39
|
+
driverParam: number;
|
|
40
|
+
notNull: false;
|
|
41
|
+
hasDefault: false;
|
|
42
|
+
}>;
|
|
43
|
+
image: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
44
|
+
tableName: "user";
|
|
45
|
+
name: "image";
|
|
46
|
+
data: string;
|
|
47
|
+
driverParam: string;
|
|
48
|
+
enumValues: [string, ...string[]];
|
|
49
|
+
notNull: false;
|
|
50
|
+
hasDefault: false;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
accounts: import("drizzle-orm/db.d-b5fdf746").ag<{
|
|
55
|
+
name: "account";
|
|
56
|
+
schema: undefined;
|
|
57
|
+
columns: {
|
|
58
|
+
userId: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
59
|
+
tableName: "account";
|
|
60
|
+
enumValues: [string, ...string[]];
|
|
61
|
+
name: "userId";
|
|
62
|
+
data: string;
|
|
63
|
+
driverParam: string;
|
|
64
|
+
hasDefault: false;
|
|
65
|
+
notNull: true;
|
|
66
|
+
}>;
|
|
67
|
+
type: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
68
|
+
tableName: "account";
|
|
69
|
+
enumValues: [string, ...string[]];
|
|
70
|
+
name: "type";
|
|
71
|
+
data: "email" | "oidc" | "oauth";
|
|
72
|
+
driverParam: string;
|
|
73
|
+
hasDefault: false;
|
|
74
|
+
notNull: true;
|
|
75
|
+
}>;
|
|
76
|
+
provider: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
77
|
+
tableName: "account";
|
|
78
|
+
enumValues: [string, ...string[]];
|
|
79
|
+
name: "provider";
|
|
80
|
+
data: string;
|
|
81
|
+
driverParam: string;
|
|
82
|
+
hasDefault: false;
|
|
83
|
+
notNull: true;
|
|
84
|
+
}>;
|
|
85
|
+
providerAccountId: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
86
|
+
tableName: "account";
|
|
87
|
+
enumValues: [string, ...string[]];
|
|
88
|
+
name: "providerAccountId";
|
|
89
|
+
data: string;
|
|
90
|
+
driverParam: string;
|
|
91
|
+
hasDefault: false;
|
|
92
|
+
notNull: true;
|
|
93
|
+
}>;
|
|
94
|
+
refresh_token: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
95
|
+
tableName: "account";
|
|
96
|
+
name: "refresh_token";
|
|
97
|
+
data: string;
|
|
98
|
+
driverParam: string;
|
|
99
|
+
enumValues: [string, ...string[]];
|
|
100
|
+
notNull: false;
|
|
101
|
+
hasDefault: false;
|
|
102
|
+
}>;
|
|
103
|
+
access_token: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
104
|
+
tableName: "account";
|
|
105
|
+
name: "access_token";
|
|
106
|
+
data: string;
|
|
107
|
+
driverParam: string;
|
|
108
|
+
enumValues: [string, ...string[]];
|
|
109
|
+
notNull: false;
|
|
110
|
+
hasDefault: false;
|
|
111
|
+
}>;
|
|
112
|
+
expires_at: import("drizzle-orm/sqlite-core").SQLiteInteger<{
|
|
113
|
+
tableName: "account";
|
|
114
|
+
name: "expires_at";
|
|
115
|
+
data: number;
|
|
116
|
+
driverParam: number;
|
|
117
|
+
notNull: false;
|
|
118
|
+
hasDefault: false;
|
|
119
|
+
}>;
|
|
120
|
+
token_type: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
121
|
+
tableName: "account";
|
|
122
|
+
name: "token_type";
|
|
123
|
+
data: string;
|
|
124
|
+
driverParam: string;
|
|
125
|
+
enumValues: [string, ...string[]];
|
|
126
|
+
notNull: false;
|
|
127
|
+
hasDefault: false;
|
|
128
|
+
}>;
|
|
129
|
+
scope: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
130
|
+
tableName: "account";
|
|
131
|
+
name: "scope";
|
|
132
|
+
data: string;
|
|
133
|
+
driverParam: string;
|
|
134
|
+
enumValues: [string, ...string[]];
|
|
135
|
+
notNull: false;
|
|
136
|
+
hasDefault: false;
|
|
137
|
+
}>;
|
|
138
|
+
id_token: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
139
|
+
tableName: "account";
|
|
140
|
+
name: "id_token";
|
|
141
|
+
data: string;
|
|
142
|
+
driverParam: string;
|
|
143
|
+
enumValues: [string, ...string[]];
|
|
144
|
+
notNull: false;
|
|
145
|
+
hasDefault: false;
|
|
146
|
+
}>;
|
|
147
|
+
session_state: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
148
|
+
tableName: "account";
|
|
149
|
+
name: "session_state";
|
|
150
|
+
data: string;
|
|
151
|
+
driverParam: string;
|
|
152
|
+
enumValues: [string, ...string[]];
|
|
153
|
+
notNull: false;
|
|
154
|
+
hasDefault: false;
|
|
155
|
+
}>;
|
|
156
|
+
};
|
|
157
|
+
}>;
|
|
158
|
+
sessions: import("drizzle-orm/db.d-b5fdf746").ag<{
|
|
159
|
+
name: "session";
|
|
160
|
+
schema: undefined;
|
|
161
|
+
columns: {
|
|
162
|
+
sessionToken: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
163
|
+
tableName: "session";
|
|
164
|
+
enumValues: [string, ...string[]];
|
|
165
|
+
name: "sessionToken";
|
|
166
|
+
data: string;
|
|
167
|
+
driverParam: string;
|
|
168
|
+
hasDefault: false;
|
|
169
|
+
notNull: true;
|
|
170
|
+
}>;
|
|
171
|
+
userId: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
172
|
+
tableName: "session";
|
|
173
|
+
enumValues: [string, ...string[]];
|
|
174
|
+
name: "userId";
|
|
175
|
+
data: string;
|
|
176
|
+
driverParam: string;
|
|
177
|
+
hasDefault: false;
|
|
178
|
+
notNull: true;
|
|
179
|
+
}>;
|
|
180
|
+
expires: import("drizzle-orm/sqlite-core").SQLiteTimestamp<{
|
|
181
|
+
tableName: "session";
|
|
182
|
+
name: "expires";
|
|
183
|
+
data: Date;
|
|
184
|
+
driverParam: number;
|
|
185
|
+
hasDefault: false;
|
|
186
|
+
notNull: true;
|
|
187
|
+
}>;
|
|
188
|
+
};
|
|
189
|
+
}>;
|
|
190
|
+
verificationTokens: import("drizzle-orm/db.d-b5fdf746").ag<{
|
|
191
|
+
name: "verificationToken";
|
|
192
|
+
schema: undefined;
|
|
193
|
+
columns: {
|
|
194
|
+
identifier: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
195
|
+
tableName: "verificationToken";
|
|
196
|
+
enumValues: [string, ...string[]];
|
|
197
|
+
name: "identifier";
|
|
198
|
+
data: string;
|
|
199
|
+
driverParam: string;
|
|
200
|
+
hasDefault: false;
|
|
201
|
+
notNull: true;
|
|
202
|
+
}>;
|
|
203
|
+
token: import("drizzle-orm/sqlite-core").SQLiteText<{
|
|
204
|
+
tableName: "verificationToken";
|
|
205
|
+
enumValues: [string, ...string[]];
|
|
206
|
+
name: "token";
|
|
207
|
+
data: string;
|
|
208
|
+
driverParam: string;
|
|
209
|
+
hasDefault: false;
|
|
210
|
+
notNull: true;
|
|
211
|
+
}>;
|
|
212
|
+
expires: import("drizzle-orm/sqlite-core").SQLiteTimestamp<{
|
|
213
|
+
tableName: "verificationToken";
|
|
214
|
+
name: "expires";
|
|
215
|
+
data: Date;
|
|
216
|
+
driverParam: number;
|
|
217
|
+
hasDefault: false;
|
|
218
|
+
notNull: true;
|
|
219
|
+
}>;
|
|
220
|
+
};
|
|
221
|
+
}>;
|
|
222
|
+
};
|
|
223
|
+
export type DefaultSchema = ReturnType<typeof createTables>;
|
|
224
|
+
export declare function SQLiteDrizzleAdapter(client: BaseSQLiteDatabase<any, any>, tableFn?: SQLiteTableFn<undefined>): Adapter;
|
|
225
|
+
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../src/lib/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,kBAAkB,EAClB,aAAa,EACd,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,qBAAqB,CAAA;AAElE,wBAAgB,YAAY,CAAC,WAAW,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDtD;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAA;AAE3D,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,EACpC,OAAO,2BAAuB,GAC7B,OAAO,CA2IT"}
|
package/lib/sqlite.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { eq, and } from "drizzle-orm";
|
|
2
|
+
import { integer, sqliteTable as defaultSqliteTableFn, text, primaryKey, } from "drizzle-orm/sqlite-core";
|
|
3
|
+
export function createTables(sqliteTable) {
|
|
4
|
+
const users = sqliteTable("user", {
|
|
5
|
+
id: text("id").notNull().primaryKey(),
|
|
6
|
+
name: text("name"),
|
|
7
|
+
email: text("email").notNull(),
|
|
8
|
+
emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
9
|
+
image: text("image"),
|
|
10
|
+
});
|
|
11
|
+
const accounts = sqliteTable("account", {
|
|
12
|
+
userId: text("userId")
|
|
13
|
+
.notNull()
|
|
14
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
15
|
+
type: text("type").$type().notNull(),
|
|
16
|
+
provider: text("provider").notNull(),
|
|
17
|
+
providerAccountId: text("providerAccountId").notNull(),
|
|
18
|
+
refresh_token: text("refresh_token"),
|
|
19
|
+
access_token: text("access_token"),
|
|
20
|
+
expires_at: integer("expires_at"),
|
|
21
|
+
token_type: text("token_type"),
|
|
22
|
+
scope: text("scope"),
|
|
23
|
+
id_token: text("id_token"),
|
|
24
|
+
session_state: text("session_state"),
|
|
25
|
+
}, (account) => ({
|
|
26
|
+
compoundKey: primaryKey(account.provider, account.providerAccountId),
|
|
27
|
+
}));
|
|
28
|
+
const sessions = sqliteTable("session", {
|
|
29
|
+
sessionToken: text("sessionToken").notNull().primaryKey(),
|
|
30
|
+
userId: text("userId")
|
|
31
|
+
.notNull()
|
|
32
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
33
|
+
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
34
|
+
});
|
|
35
|
+
const verificationTokens = sqliteTable("verificationToken", {
|
|
36
|
+
identifier: text("identifier").notNull(),
|
|
37
|
+
token: text("token").notNull(),
|
|
38
|
+
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
39
|
+
}, (vt) => ({
|
|
40
|
+
compoundKey: primaryKey(vt.identifier, vt.token),
|
|
41
|
+
}));
|
|
42
|
+
return { users, accounts, sessions, verificationTokens };
|
|
43
|
+
}
|
|
44
|
+
export function SQLiteDrizzleAdapter(client, tableFn = defaultSqliteTableFn) {
|
|
45
|
+
const { users, accounts, sessions, verificationTokens } = createTables(tableFn);
|
|
46
|
+
return {
|
|
47
|
+
createUser(data) {
|
|
48
|
+
return client
|
|
49
|
+
.insert(users)
|
|
50
|
+
.values({ ...data, id: crypto.randomUUID() })
|
|
51
|
+
.returning()
|
|
52
|
+
.get();
|
|
53
|
+
},
|
|
54
|
+
getUser(data) {
|
|
55
|
+
return client.select().from(users).where(eq(users.id, data)).get() ?? null;
|
|
56
|
+
},
|
|
57
|
+
getUserByEmail(data) {
|
|
58
|
+
return (client.select().from(users).where(eq(users.email, data)).get() ?? null);
|
|
59
|
+
},
|
|
60
|
+
createSession(data) {
|
|
61
|
+
return client.insert(sessions).values(data).returning().get();
|
|
62
|
+
},
|
|
63
|
+
getSessionAndUser(data) {
|
|
64
|
+
return (client
|
|
65
|
+
.select({
|
|
66
|
+
session: sessions,
|
|
67
|
+
user: users,
|
|
68
|
+
})
|
|
69
|
+
.from(sessions)
|
|
70
|
+
.where(eq(sessions.sessionToken, data))
|
|
71
|
+
.innerJoin(users, eq(users.id, sessions.userId))
|
|
72
|
+
.get() ?? null);
|
|
73
|
+
},
|
|
74
|
+
updateUser(data) {
|
|
75
|
+
if (!data.id) {
|
|
76
|
+
throw new Error("No user id.");
|
|
77
|
+
}
|
|
78
|
+
return client
|
|
79
|
+
.update(users)
|
|
80
|
+
.set(data)
|
|
81
|
+
.where(eq(users.id, data.id))
|
|
82
|
+
.returning()
|
|
83
|
+
.get();
|
|
84
|
+
},
|
|
85
|
+
updateSession(data) {
|
|
86
|
+
return client
|
|
87
|
+
.update(sessions)
|
|
88
|
+
.set(data)
|
|
89
|
+
.where(eq(sessions.sessionToken, data.sessionToken))
|
|
90
|
+
.returning()
|
|
91
|
+
.get();
|
|
92
|
+
},
|
|
93
|
+
linkAccount(rawAccount) {
|
|
94
|
+
const updatedAccount = client
|
|
95
|
+
.insert(accounts)
|
|
96
|
+
.values(rawAccount)
|
|
97
|
+
.returning()
|
|
98
|
+
.get();
|
|
99
|
+
const account = {
|
|
100
|
+
...updatedAccount,
|
|
101
|
+
type: updatedAccount.type,
|
|
102
|
+
access_token: updatedAccount.access_token ?? undefined,
|
|
103
|
+
token_type: updatedAccount.token_type ?? undefined,
|
|
104
|
+
id_token: updatedAccount.id_token ?? undefined,
|
|
105
|
+
refresh_token: updatedAccount.refresh_token ?? undefined,
|
|
106
|
+
scope: updatedAccount.scope ?? undefined,
|
|
107
|
+
expires_at: updatedAccount.expires_at ?? undefined,
|
|
108
|
+
session_state: updatedAccount.session_state ?? undefined,
|
|
109
|
+
};
|
|
110
|
+
return account;
|
|
111
|
+
},
|
|
112
|
+
getUserByAccount(account) {
|
|
113
|
+
const results = client
|
|
114
|
+
.select()
|
|
115
|
+
.from(accounts)
|
|
116
|
+
.leftJoin(users, eq(users.id, accounts.userId))
|
|
117
|
+
.where(and(eq(accounts.provider, account.provider), eq(accounts.providerAccountId, account.providerAccountId)))
|
|
118
|
+
.get();
|
|
119
|
+
return results?.user ?? null;
|
|
120
|
+
},
|
|
121
|
+
deleteSession(sessionToken) {
|
|
122
|
+
return (client
|
|
123
|
+
.delete(sessions)
|
|
124
|
+
.where(eq(sessions.sessionToken, sessionToken))
|
|
125
|
+
.returning()
|
|
126
|
+
.get() ?? null);
|
|
127
|
+
},
|
|
128
|
+
createVerificationToken(token) {
|
|
129
|
+
return client.insert(verificationTokens).values(token).returning().get();
|
|
130
|
+
},
|
|
131
|
+
useVerificationToken(token) {
|
|
132
|
+
try {
|
|
133
|
+
return (client
|
|
134
|
+
.delete(verificationTokens)
|
|
135
|
+
.where(and(eq(verificationTokens.identifier, token.identifier), eq(verificationTokens.token, token.token)))
|
|
136
|
+
.returning()
|
|
137
|
+
.get() ?? null);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
throw new Error("No verification token found.");
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
deleteUser(id) {
|
|
144
|
+
return client.delete(users).where(eq(users.id, id)).returning().get();
|
|
145
|
+
},
|
|
146
|
+
unlinkAccount(account) {
|
|
147
|
+
client
|
|
148
|
+
.delete(accounts)
|
|
149
|
+
.where(and(eq(accounts.providerAccountId, account.providerAccountId), eq(accounts.provider, account.provider)))
|
|
150
|
+
.run();
|
|
151
|
+
return undefined;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MySqlDatabase } from "drizzle-orm/mysql-core";
|
|
2
|
+
import { PgDatabase } from "drizzle-orm/pg-core";
|
|
3
|
+
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
|
4
|
+
import type { AnyMySqlTable, MySqlTableFn } from "drizzle-orm/mysql-core";
|
|
5
|
+
import type { AnyPgTable, PgTableFn } from "drizzle-orm/pg-core";
|
|
6
|
+
import type { AnySQLiteTable, SQLiteTableFn } from "drizzle-orm/sqlite-core";
|
|
7
|
+
import type { DefaultSchema as PgSchema } from "./pg.js";
|
|
8
|
+
import type { DefaultSchema as MySqlSchema } from "./mysql.js";
|
|
9
|
+
import type { DefaultSchema as SQLiteSchema } from "./sqlite.js";
|
|
10
|
+
export type AnyMySqlDatabase = MySqlDatabase<any, any>;
|
|
11
|
+
export type AnyPgDatabase = PgDatabase<any, any, any>;
|
|
12
|
+
export type AnySQLiteDatabase = BaseSQLiteDatabase<any, any, any, any>;
|
|
13
|
+
export interface MinimumSchema {
|
|
14
|
+
mysql: MySqlSchema & Record<string, AnyMySqlTable>;
|
|
15
|
+
pg: PgSchema & Record<string, AnyPgTable>;
|
|
16
|
+
sqlite: SQLiteSchema & Record<string, AnySQLiteTable>;
|
|
17
|
+
}
|
|
18
|
+
export type SqlFlavorOptions = AnyMySqlDatabase | AnyPgDatabase | AnySQLiteDatabase;
|
|
19
|
+
export type ClientFlavors<Flavor> = Flavor extends AnyMySqlDatabase ? MinimumSchema["mysql"] : Flavor extends AnyPgDatabase ? MinimumSchema["pg"] : Flavor extends AnySQLiteDatabase ? MinimumSchema["sqlite"] : never;
|
|
20
|
+
export type TableFn<Flavor> = Flavor extends AnyMySqlDatabase ? MySqlTableFn : Flavor extends AnyPgDatabase ? PgTableFn : Flavor extends AnySQLiteDatabase ? SQLiteTableFn : AnySQLiteTable;
|
|
21
|
+
export declare function isMySqlDatabase(db: any): db is MySqlDatabase<any, any, any, any>;
|
|
22
|
+
export declare function isPgDatabase(db: any): db is PgDatabase<any, any, any>;
|
|
23
|
+
export declare function isSQLiteDatabase(db: any): db is AnySQLiteDatabase;
|
|
24
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,EAAE,aAAa,IAAI,QAAQ,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,IAAI,WAAW,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,KAAK,EAAE,aAAa,IAAI,YAAY,EAAE,MAAM,aAAa,CAAA;AAEhE,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AACtD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AACrD,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEtE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAClD,EAAE,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACzC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;CACtD;AAED,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,aAAa,GACb,iBAAiB,CAAA;AAErB,MAAM,MAAM,aAAa,CAAC,MAAM,IAAI,MAAM,SAAS,gBAAgB,GAC/D,aAAa,CAAC,OAAO,CAAC,GACtB,MAAM,SAAS,aAAa,GAC5B,aAAa,CAAC,IAAI,CAAC,GACnB,MAAM,SAAS,iBAAiB,GAChC,aAAa,CAAC,QAAQ,CAAC,GACvB,KAAK,CAAA;AAET,MAAM,MAAM,OAAO,CAAC,MAAM,IAAI,MAAM,SAAS,gBAAgB,GACzD,YAAY,GACZ,MAAM,SAAS,aAAa,GAC5B,SAAS,GACT,MAAM,SAAS,iBAAiB,GAChC,aAAa,GACb,cAAc,CAAA;AAElB,wBAAgB,eAAe,CAC7B,EAAE,EAAE,GAAG,GACN,EAAE,IAAI,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAEzC;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,IAAI,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAErE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,IAAI,iBAAiB,CAEjE"}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MySqlDatabase } from "drizzle-orm/mysql-core";
|
|
2
|
+
import { PgDatabase } from "drizzle-orm/pg-core";
|
|
3
|
+
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
|
4
|
+
export function isMySqlDatabase(db) {
|
|
5
|
+
return db instanceof MySqlDatabase;
|
|
6
|
+
}
|
|
7
|
+
export function isPgDatabase(db) {
|
|
8
|
+
return db instanceof PgDatabase;
|
|
9
|
+
}
|
|
10
|
+
export function isSQLiteDatabase(db) {
|
|
11
|
+
return db instanceof BaseSQLiteDatabase;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth/drizzle-adapter",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Drizzle adapter for Auth.js.",
|
|
5
5
|
"homepage": "https://authjs.dev",
|
|
6
6
|
"repository": "https://github.com/nextauthjs/next-auth",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"types": "./index.d.ts",
|
|
13
13
|
"files": [
|
|
14
|
-
"*.js",
|
|
15
14
|
"*.d.ts*",
|
|
15
|
+
"*.js",
|
|
16
16
|
"lib",
|
|
17
17
|
"src"
|
|
18
18
|
],
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@auth/core": "0.
|
|
39
|
+
"@auth/core": "0.11.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/better-sqlite3": "^7.6.4",
|