cloudaxe-opencode/packages/console/core/src/account.ts

33 lines
772 B
TypeScript
Raw Permalink Normal View History

2025-08-08 17:22:54 +00:00
import { z } from "zod"
2025-10-06 20:15:10 +00:00
import { eq } from "drizzle-orm"
2025-08-08 17:22:54 +00:00
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) =>
2025-12-01 23:33:32 +00:00
Database.use(async (tx) => {
2025-08-08 17:22:54 +00:00
const id = input.id ?? Identifier.create("account")
await tx.insert(AccountTable).values({
id,
})
return id
}),
)
export const fromID = fn(z.string(), async (id) =>
2025-12-01 23:33:32 +00:00
Database.use((tx) =>
tx
2025-08-08 17:22:54 +00:00
.select()
.from(AccountTable)
.where(eq(AccountTable.id, id))
2025-12-01 23:33:32 +00:00
.then((rows) => rows[0]),
),
2025-08-08 17:22:54 +00:00
)
}