feat: set up Drizzle
This commit is contained in:
26
src/models/token.ts
Normal file
26
src/models/token.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
|
||||
import type { Env } from "~/types/env";
|
||||
|
||||
import { getDb } from "./db";
|
||||
import { tokenTable } from "./schema";
|
||||
|
||||
export function saveToken(
|
||||
env: Env,
|
||||
deviceId: string,
|
||||
token: string,
|
||||
username: string | null,
|
||||
) {
|
||||
return getDb(env)
|
||||
.insert(tokenTable)
|
||||
.values({ deviceId, token, username })
|
||||
.run();
|
||||
}
|
||||
|
||||
export function updateDeviceLastConnectedAt(env: Env, deviceId: string) {
|
||||
return getDb(env)
|
||||
.update(tokenTable)
|
||||
.set({ lastConnectedAt: sql`(CURRENT_TIMESTAMP)` })
|
||||
.where(eq(tokenTable.deviceId, deviceId))
|
||||
.run();
|
||||
}
|
||||
Reference in New Issue
Block a user