Db
This commit is contained in:
parent
ece80a7359
commit
556553ce1a
1 changed files with 4 additions and 3 deletions
7
db.ts
7
db.ts
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue