Skip to content

查询

and 多个条件

ts
import { drizzleInstance } from "~/database/instance.js";
import { otpTable } from "~/database/schema/opt.js";
import { eq, and } from "drizzle-orm";
import type { OtpPurpose } from "~/database/schema/opt.js";

export async function getExistOTPByEmail(email: string, purpose: OtpPurpose) {
  const [otp] = await drizzleInstance
    .select()
    .from(otpTable)
    .where(
      and(
        eq(otpTable.status, "pending"),
        eq(otpTable.channel, "email"),
        eq(otpTable.target, email),
        eq(otpTable.purpose, purpose)
      )
    );
  return otp;
}