This commit is contained in:
Daniel Flanagan 2024-12-27 11:02:11 -06:00
parent ece80a7359
commit 556553ce1a

7
db.ts
View file

@ -30,16 +30,17 @@ export function all<T extends Table>(
type Create<T> = Omit<T, 'id' | 'createdAt'> | Partial<T>
export function create<T extends Table, K extends Identifiable>(
export async function create<T extends Table, K extends typeof Identifiable>(
a: T,
payload: Create<K>,
): Deno.KvListIterator<Model<T>> {
): Promise<Deno.KvCommitResult> {
const data: Create<Model<T>> | undefined = schema[a].parse(payload)
// we want to create our own ID since this is `create` and not `update`
if (Identifiable.safeParse(data).success) {
delete data.id
}
if (Created.safeParse(data).success) {
delete data.createdBy
}
return kv.set([a, )
return await kv.set([a, payload.id], payload)
}