mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-18 03:30:39 +09:00
23 lines
545 B
TypeScript
23 lines
545 B
TypeScript
|
|
import { eq } from "drizzle-orm";
|
||
|
|
import type { Db } from "@paperclip/db";
|
||
|
|
import { assets } from "@paperclip/db";
|
||
|
|
|
||
|
|
export function assetService(db: Db) {
|
||
|
|
return {
|
||
|
|
create: (companyId: string, data: Omit<typeof assets.$inferInsert, "companyId">) =>
|
||
|
|
db
|
||
|
|
.insert(assets)
|
||
|
|
.values({ ...data, companyId })
|
||
|
|
.returning()
|
||
|
|
.then((rows) => rows[0]),
|
||
|
|
|
||
|
|
getById: (id: string) =>
|
||
|
|
db
|
||
|
|
.select()
|
||
|
|
.from(assets)
|
||
|
|
.where(eq(assets.id, id))
|
||
|
|
.then((rows) => rows[0] ?? null),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|