mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-25 03:34:22 +01:00
34 lines
822 B
TypeScript
34 lines
822 B
TypeScript
import { z } from "zod"
|
|
import { eq } from "drizzle-orm"
|
|
import { fn } from "./util/fn"
|
|
import { Database } from "./drizzle"
|
|
import { Identifier } from "./identifier"
|
|
import { AccountTable } from "./schema/account.sql"
|
|
|
|
export namespace Account {
|
|
export const create = fn(
|
|
z.object({
|
|
id: z.string().optional(),
|
|
}),
|
|
async (input) =>
|
|
Database.transaction(async (tx) => {
|
|
const id = input.id ?? Identifier.create("account")
|
|
await tx.insert(AccountTable).values({
|
|
id,
|
|
})
|
|
return id
|
|
}),
|
|
)
|
|
|
|
export const fromID = fn(z.string(), async (id) =>
|
|
Database.transaction(async (tx) => {
|
|
return tx
|
|
.select()
|
|
.from(AccountTable)
|
|
.where(eq(AccountTable.id, id))
|
|
.execute()
|
|
.then((rows) => rows[0])
|
|
}),
|
|
)
|
|
}
|