Skip to content

Commit

Permalink
Explicitly name db table variables *Table
Browse files Browse the repository at this point in the history
This allows us to use local variables such as `users` in the following
scenario:

  ```
const users = await db.select().from(usersTable)
  ```
  • Loading branch information
venables committed Sep 4, 2023
1 parent 1e0b5bf commit 668810b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions auth/providers/http-email/send-verification-request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { eq } from "drizzle-orm"

import SignInEmail from "@/emails/signin-email"
import { env } from "@/env"
import { db, users } from "@/lib/db"
import { db, usersTable } from "@/lib/db"
import { emailClient } from "@/lib/email"

import type { SendVerificationRequestParams } from "@auth/core/providers"
Expand All @@ -11,15 +11,15 @@ export async function sendVerificationRequest({
identifier: email,
url
}: SendVerificationRequestParams) {
const existingUsers = await db
const users = await db
.select({
emailVerified: users.emailVerified
emailVerified: usersTable.emailVerified
})
.from(users)
.where(eq(users.email, email))
.from(usersTable)
.where(eq(usersTable.email, email))
.limit(1)

const user = existingUsers[0]
const user = users[0]

await emailClient().sendEmail({
from: env.EMAIL_FROM,
Expand Down
12 changes: 6 additions & 6 deletions lib/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ export const pgTable = pgTableCreator((name) => {
}
})

export const users = pgTable("user", {
export const usersTable = pgTable("user", {
id: text("id").notNull().primaryKey(),
name: text("name"),
email: citext("email").notNull().unique(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image")
})

export const accounts = pgTable(
export const accountsTable = pgTable(
"account",
{
userId: text("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
.references(() => usersTable.id, { onDelete: "cascade" }),
type: text("type").$type<AdapterAccount["type"]>().notNull(),
provider: text("provider").notNull(),
providerAccountId: text("providerAccountId").notNull(),
Expand All @@ -58,15 +58,15 @@ export const accounts = pgTable(
})
)

export const sessions = pgTable("session", {
export const sessionsTable = pgTable("session", {
sessionToken: text("sessionToken").notNull().primaryKey(),
userId: text("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
.references(() => usersTable.id, { onDelete: "cascade" }),
expires: timestamp("expires", { mode: "date" }).notNull()
})

export const verificationTokens = pgTable(
export const verificationTokensTable = pgTable(
"verificationToken",
{
identifier: text("identifier").notNull(),
Expand Down

1 comment on commit 668810b

@vercel
Copy link

@vercel vercel bot commented on 668810b Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.