@auth/drizzle-adapter 0.0.0-manual.ffc00566 → 0.1.0

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/src/lib/mysql.ts CHANGED
@@ -6,10 +6,10 @@ import {
6
6
  primaryKey,
7
7
  varchar,
8
8
  } from "drizzle-orm/mysql-core"
9
+
9
10
  import type { Adapter, AdapterAccount } from "@auth/core/adapters"
10
- import { MySql2Database } from "drizzle-orm/mysql2"
11
+ import type { MySql2Database } from "drizzle-orm/mysql2"
11
12
 
12
- /** @internal */
13
13
  export const users = mysqlTable("users", {
14
14
  id: varchar("id", { length: 255 }).notNull().primaryKey(),
15
15
  name: varchar("name", { length: 255 }),
@@ -21,7 +21,6 @@ export const users = mysqlTable("users", {
21
21
  image: varchar("image", { length: 255 }),
22
22
  })
23
23
 
24
- /** @internal */
25
24
  export const accounts = mysqlTable(
26
25
  "accounts",
27
26
  {
@@ -46,7 +45,6 @@ export const accounts = mysqlTable(
46
45
  })
47
46
  )
48
47
 
49
- /** @internal */
50
48
  export const sessions = mysqlTable("sessions", {
51
49
  sessionToken: varchar("sessionToken", { length: 255 }).notNull().primaryKey(),
52
50
  userId: varchar("userId", { length: 255 })
@@ -55,7 +53,6 @@ export const sessions = mysqlTable("sessions", {
55
53
  expires: timestamp("expires", { mode: "date" }).notNull(),
56
54
  })
57
55
 
58
- /** @internal */
59
56
  export const verificationTokens = mysqlTable(
60
57
  "verificationToken",
61
58
  {
@@ -68,16 +65,14 @@ export const verificationTokens = mysqlTable(
68
65
  })
69
66
  )
70
67
 
71
- /** @internal */
72
68
  export const schema = { users, accounts, sessions, verificationTokens }
73
69
  export type DefaultSchema = typeof schema
74
70
 
75
- /** @internal */
76
71
  export function mySqlDrizzleAdapter(
77
72
  client: MySql2Database<Record<string, never>>
78
73
  ): Adapter {
79
74
  return {
80
- createUser: async (data) => {
75
+ async createUser(data) {
81
76
  const id = crypto.randomUUID()
82
77
 
83
78
  await client.insert(users).values({ ...data, id })
@@ -88,7 +83,7 @@ export function mySqlDrizzleAdapter(
88
83
  .where(eq(users.id, id))
89
84
  .then((res) => res[0])
90
85
  },
91
- getUser: async (data) => {
86
+ async getUser(data) {
92
87
  const thing =
93
88
  (await client
94
89
  .select()
@@ -98,7 +93,7 @@ export function mySqlDrizzleAdapter(
98
93
 
99
94
  return thing
100
95
  },
101
- getUserByEmail: async (data) => {
96
+ async getUserByEmail(data) {
102
97
  const user =
103
98
  (await client
104
99
  .select()
@@ -108,7 +103,7 @@ export function mySqlDrizzleAdapter(
108
103
 
109
104
  return user
110
105
  },
111
- createSession: async (data) => {
106
+ async createSession(data) {
112
107
  await client.insert(sessions).values(data)
113
108
 
114
109
  return await client
@@ -117,7 +112,7 @@ export function mySqlDrizzleAdapter(
117
112
  .where(eq(sessions.sessionToken, data.sessionToken))
118
113
  .then((res) => res[0])
119
114
  },
120
- getSessionAndUser: async (data) => {
115
+ async getSessionAndUser(data) {
121
116
  const sessionAndUser =
122
117
  (await client
123
118
  .select({
@@ -131,7 +126,7 @@ export function mySqlDrizzleAdapter(
131
126
 
132
127
  return sessionAndUser
133
128
  },
134
- updateUser: async (data) => {
129
+ async updateUser(data) {
135
130
  if (!data.id) {
136
131
  throw new Error("No user id.")
137
132
  }
@@ -144,7 +139,7 @@ export function mySqlDrizzleAdapter(
144
139
  .where(eq(users.id, data.id))
145
140
  .then((res) => res[0])
146
141
  },
147
- updateSession: async (data) => {
142
+ async updateSession(data) {
148
143
  await client
149
144
  .update(sessions)
150
145
  .set(data)
@@ -156,13 +151,13 @@ export function mySqlDrizzleAdapter(
156
151
  .where(eq(sessions.sessionToken, data.sessionToken))
157
152
  .then((res) => res[0])
158
153
  },
159
- linkAccount: async (rawAccount) => {
154
+ async linkAccount(rawAccount) {
160
155
  await client
161
156
  .insert(accounts)
162
157
  .values(rawAccount)
163
158
  .then((res) => res[0])
164
159
  },
165
- getUserByAccount: async (account) => {
160
+ async getUserByAccount(account) {
166
161
  const dbAccount =
167
162
  (await client
168
163
  .select()
@@ -182,7 +177,7 @@ export function mySqlDrizzleAdapter(
182
177
 
183
178
  return dbAccount.users
184
179
  },
185
- deleteSession: async (sessionToken) => {
180
+ async deleteSession(sessionToken) {
186
181
  const session =
187
182
  (await client
188
183
  .select()
@@ -196,7 +191,7 @@ export function mySqlDrizzleAdapter(
196
191
 
197
192
  return session
198
193
  },
199
- createVerificationToken: async (token) => {
194
+ async createVerificationToken(token) {
200
195
  await client.insert(verificationTokens).values(token)
201
196
 
202
197
  return await client
@@ -205,7 +200,7 @@ export function mySqlDrizzleAdapter(
205
200
  .where(eq(verificationTokens.identifier, token.identifier))
206
201
  .then((res) => res[0])
207
202
  },
208
- useVerificationToken: async (token) => {
203
+ async useVerificationToken(token) {
209
204
  try {
210
205
  const deletedToken =
211
206
  (await client
@@ -233,7 +228,7 @@ export function mySqlDrizzleAdapter(
233
228
  throw new Error("No verification token found.")
234
229
  }
235
230
  },
236
- deleteUser: async (id) => {
231
+ async deleteUser(id) {
237
232
  const user = await client
238
233
  .select()
239
234
  .from(users)
@@ -244,7 +239,7 @@ export function mySqlDrizzleAdapter(
244
239
 
245
240
  return user
246
241
  },
247
- unlinkAccount: async (account) => {
242
+ async unlinkAccount(account) {
248
243
  await client
249
244
  .delete(accounts)
250
245
  .where(
package/src/lib/pg.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { and, eq } from "drizzle-orm"
1
2
  import {
2
3
  timestamp,
3
4
  pgTable,
@@ -5,11 +6,10 @@ import {
5
6
  primaryKey,
6
7
  integer,
7
8
  } from "drizzle-orm/pg-core"
8
- import { PostgresJsDatabase } from "drizzle-orm/postgres-js"
9
- import { Adapter, AdapterAccount } from "@auth/core/adapters"
10
- import { and, eq } from "drizzle-orm"
11
9
 
12
- /** @internal */
10
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js"
11
+ import type { Adapter, AdapterAccount } from "@auth/core/adapters"
12
+
13
13
  export const users = pgTable("users", {
14
14
  id: text("id").notNull().primaryKey(),
15
15
  name: text("name"),
@@ -18,7 +18,6 @@ export const users = pgTable("users", {
18
18
  image: text("image"),
19
19
  })
20
20
 
21
- /** @internal */
22
21
  export const accounts = pgTable(
23
22
  "accounts",
24
23
  {
@@ -41,7 +40,6 @@ export const accounts = pgTable(
41
40
  })
42
41
  )
43
42
 
44
- /** @internal */
45
43
  export const sessions = pgTable("sessions", {
46
44
  sessionToken: text("sessionToken").notNull().primaryKey(),
47
45
  userId: text("userId")
@@ -50,7 +48,6 @@ export const sessions = pgTable("sessions", {
50
48
  expires: timestamp("expires", { mode: "date" }).notNull(),
51
49
  })
52
50
 
53
- /** @internal */
54
51
  export const verificationTokens = pgTable(
55
52
  "verificationToken",
56
53
  {
@@ -63,44 +60,42 @@ export const verificationTokens = pgTable(
63
60
  })
64
61
  )
65
62
 
66
- /** @internal */
67
63
  export const schema = { users, accounts, sessions, verificationTokens }
68
64
  export type DefaultSchema = typeof schema
69
65
 
70
- /** @internal */
71
66
  export function pgDrizzleAdapter(
72
67
  client: PostgresJsDatabase<Record<string, never>>
73
68
  ): Adapter {
74
69
  return {
75
- createUser: async (data) => {
70
+ async createUser(data) {
76
71
  return await client
77
72
  .insert(users)
78
73
  .values({ ...data, id: crypto.randomUUID() })
79
74
  .returning()
80
75
  .then((res) => res[0] ?? null)
81
76
  },
82
- getUser: async (data) => {
77
+ async getUser(data) {
83
78
  return await client
84
79
  .select()
85
80
  .from(users)
86
81
  .where(eq(users.id, data))
87
82
  .then((res) => res[0] ?? null)
88
83
  },
89
- getUserByEmail: async (data) => {
84
+ async getUserByEmail(data) {
90
85
  return await client
91
86
  .select()
92
87
  .from(users)
93
88
  .where(eq(users.email, data))
94
89
  .then((res) => res[0] ?? null)
95
90
  },
96
- createSession: async (data) => {
91
+ async createSession(data) {
97
92
  return await client
98
93
  .insert(sessions)
99
94
  .values(data)
100
95
  .returning()
101
96
  .then((res) => res[0])
102
97
  },
103
- getSessionAndUser: async (data) => {
98
+ async getSessionAndUser(data) {
104
99
  return await client
105
100
  .select({
106
101
  session: sessions,
@@ -111,7 +106,7 @@ export function pgDrizzleAdapter(
111
106
  .innerJoin(users, eq(users.id, sessions.userId))
112
107
  .then((res) => res[0] ?? null)
113
108
  },
114
- updateUser: async (data) => {
109
+ async updateUser(data) {
115
110
  if (!data.id) {
116
111
  throw new Error("No user id.")
117
112
  }
@@ -123,7 +118,7 @@ export function pgDrizzleAdapter(
123
118
  .returning()
124
119
  .then((res) => res[0])
125
120
  },
126
- updateSession: async (data) => {
121
+ async updateSession(data) {
127
122
  return await client
128
123
  .update(sessions)
129
124
  .set(data)
@@ -131,7 +126,7 @@ export function pgDrizzleAdapter(
131
126
  .returning()
132
127
  .then((res) => res[0])
133
128
  },
134
- linkAccount: async (rawAccount) => {
129
+ async linkAccount(rawAccount) {
135
130
  const updatedAccount = await client
136
131
  .insert(accounts)
137
132
  .values(rawAccount)
@@ -153,7 +148,7 @@ export function pgDrizzleAdapter(
153
148
 
154
149
  return account
155
150
  },
156
- getUserByAccount: async (account) => {
151
+ async getUserByAccount(account) {
157
152
  const dbAccount =
158
153
  (await client
159
154
  .select()
@@ -173,7 +168,7 @@ export function pgDrizzleAdapter(
173
168
 
174
169
  return dbAccount.users
175
170
  },
176
- deleteSession: async (sessionToken) => {
171
+ async deleteSession(sessionToken) {
177
172
  const session = await client
178
173
  .delete(sessions)
179
174
  .where(eq(sessions.sessionToken, sessionToken))
@@ -182,14 +177,14 @@ export function pgDrizzleAdapter(
182
177
 
183
178
  return session
184
179
  },
185
- createVerificationToken: async (token) => {
180
+ async createVerificationToken(token) {
186
181
  return await client
187
182
  .insert(verificationTokens)
188
183
  .values(token)
189
184
  .returning()
190
185
  .then((res) => res[0])
191
186
  },
192
- useVerificationToken: async (token) => {
187
+ async useVerificationToken(token) {
193
188
  try {
194
189
  return await client
195
190
  .delete(verificationTokens)
@@ -205,14 +200,14 @@ export function pgDrizzleAdapter(
205
200
  throw new Error("No verification token found.")
206
201
  }
207
202
  },
208
- deleteUser: async (id) => {
203
+ async deleteUser(id) {
209
204
  await client
210
205
  .delete(users)
211
206
  .where(eq(users.id, id))
212
207
  .returning()
213
208
  .then((res) => res[0] ?? null)
214
209
  },
215
- unlinkAccount: async (account) => {
210
+ async unlinkAccount(account) {
216
211
  const { type, provider, providerAccountId, userId } = await client
217
212
  .delete(accounts)
218
213
  .where(
package/src/lib/sqlite.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { eq, and } from "drizzle-orm"
1
2
  import {
2
3
  integer,
3
4
  sqliteTable,
@@ -5,10 +6,9 @@ import {
5
6
  primaryKey,
6
7
  BaseSQLiteDatabase,
7
8
  } from "drizzle-orm/sqlite-core"
8
- import { Adapter, AdapterAccount } from "@auth/core/adapters"
9
- import { eq, and } from "drizzle-orm"
10
9
 
11
- /** @internal */
10
+ import type { Adapter, AdapterAccount } from "@auth/core/adapters"
11
+
12
12
  export const users = sqliteTable("users", {
13
13
  id: text("id").notNull().primaryKey(),
14
14
  name: text("name"),
@@ -17,7 +17,6 @@ export const users = sqliteTable("users", {
17
17
  image: text("image"),
18
18
  })
19
19
 
20
- /** @internal */
21
20
  export const accounts = sqliteTable(
22
21
  "accounts",
23
22
  {
@@ -40,7 +39,6 @@ export const accounts = sqliteTable(
40
39
  })
41
40
  )
42
41
 
43
- /** @internal */
44
42
  export const sessions = sqliteTable("sessions", {
45
43
  sessionToken: text("sessionToken").notNull().primaryKey(),
46
44
  userId: text("userId")
@@ -49,7 +47,6 @@ export const sessions = sqliteTable("sessions", {
49
47
  expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
50
48
  })
51
49
 
52
- /** @internal */
53
50
  export const verificationTokens = sqliteTable(
54
51
  "verificationToken",
55
52
  {
@@ -62,34 +59,32 @@ export const verificationTokens = sqliteTable(
62
59
  })
63
60
  )
64
61
 
65
- /** @internal */
66
62
  export const schema = { users, accounts, sessions, verificationTokens }
67
63
  export type DefaultSchema = typeof schema
68
64
 
69
- /** @internal */
70
65
  export function SQLiteDrizzleAdapter(
71
66
  client: BaseSQLiteDatabase<any, any>
72
67
  ): Adapter {
73
68
  return {
74
- createUser: (data) => {
69
+ createUser(data) {
75
70
  return client
76
71
  .insert(users)
77
72
  .values({ ...data, id: crypto.randomUUID() })
78
73
  .returning()
79
74
  .get()
80
75
  },
81
- getUser: (data) => {
76
+ getUser(data) {
82
77
  return client.select().from(users).where(eq(users.id, data)).get() ?? null
83
78
  },
84
- getUserByEmail: (data) => {
79
+ getUserByEmail(data) {
85
80
  return (
86
81
  client.select().from(users).where(eq(users.email, data)).get() ?? null
87
82
  )
88
83
  },
89
- createSession: (data) => {
84
+ createSession(data) {
90
85
  return client.insert(sessions).values(data).returning().get()
91
86
  },
92
- getSessionAndUser: (data) => {
87
+ getSessionAndUser(data) {
93
88
  return (
94
89
  client
95
90
  .select({
@@ -102,7 +97,7 @@ export function SQLiteDrizzleAdapter(
102
97
  .get() ?? null
103
98
  )
104
99
  },
105
- updateUser: (data) => {
100
+ updateUser(data) {
106
101
  if (!data.id) {
107
102
  throw new Error("No user id.")
108
103
  }
@@ -114,7 +109,7 @@ export function SQLiteDrizzleAdapter(
114
109
  .returning()
115
110
  .get()
116
111
  },
117
- updateSession: (data) => {
112
+ updateSession(data) {
118
113
  return client
119
114
  .update(sessions)
120
115
  .set(data)
@@ -122,7 +117,7 @@ export function SQLiteDrizzleAdapter(
122
117
  .returning()
123
118
  .get()
124
119
  },
125
- linkAccount: (rawAccount) => {
120
+ linkAccount(rawAccount) {
126
121
  const updatedAccount = client
127
122
  .insert(accounts)
128
123
  .values(rawAccount)
@@ -143,7 +138,7 @@ export function SQLiteDrizzleAdapter(
143
138
 
144
139
  return account
145
140
  },
146
- getUserByAccount: (account) => {
141
+ getUserByAccount(account) {
147
142
  const results = client
148
143
  .select()
149
144
  .from(accounts)
@@ -158,7 +153,7 @@ export function SQLiteDrizzleAdapter(
158
153
 
159
154
  return results?.users ?? null
160
155
  },
161
- deleteSession: (sessionToken) => {
156
+ deleteSession(sessionToken) {
162
157
  return (
163
158
  client
164
159
  .delete(sessions)
@@ -167,10 +162,10 @@ export function SQLiteDrizzleAdapter(
167
162
  .get() ?? null
168
163
  )
169
164
  },
170
- createVerificationToken: (token) => {
165
+ createVerificationToken(token) {
171
166
  return client.insert(verificationTokens).values(token).returning().get()
172
167
  },
173
- useVerificationToken: (token) => {
168
+ useVerificationToken(token) {
174
169
  try {
175
170
  return (
176
171
  client
@@ -188,10 +183,10 @@ export function SQLiteDrizzleAdapter(
188
183
  throw new Error("No verification token found.")
189
184
  }
190
185
  },
191
- deleteUser: (id) => {
186
+ deleteUser(id) {
192
187
  return client.delete(users).where(eq(users.id, id)).returning().get()
193
188
  },
194
- unlinkAccount: (account) => {
189
+ unlinkAccount(account) {
195
190
  client
196
191
  .delete(accounts)
197
192
  .where(
package/src/lib/utils.ts CHANGED
@@ -1,9 +1,13 @@
1
- import { AnyMySqlTable, MySqlDatabase } from "drizzle-orm/mysql-core"
2
- import { AnyPgTable, PgDatabase } from "drizzle-orm/pg-core"
3
- import { AnySQLiteTable, BaseSQLiteDatabase } from "drizzle-orm/sqlite-core"
4
- import { DefaultSchema as PgSchema } from "./pg"
5
- import { DefaultSchema as MySqlSchema } from "./mysql"
6
- import { DefaultSchema as SQLiteSchema } from "./sqlite"
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
+
5
+ import type { AnyMySqlTable } from "drizzle-orm/mysql-core"
6
+ import type { AnyPgTable } from "drizzle-orm/pg-core"
7
+ import type { AnySQLiteTable } from "drizzle-orm/sqlite-core"
8
+ import type { DefaultSchema as PgSchema } from "./pg.js"
9
+ import type { DefaultSchema as MySqlSchema } from "./mysql.js"
10
+ import type { DefaultSchema as SQLiteSchema } from "./sqlite.js"
7
11
 
8
12
  export type AnyMySqlDatabase = MySqlDatabase<any, any>
9
13
  export type AnyPgDatabase = PgDatabase<any, any, any>