Last active
November 24, 2023 22:26
-
-
Save asciant/ea34c67fb56656f367183ce1f1069606 to your computer and use it in GitHub Desktop.
class-model.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Class based abstraction layer for Drizzle (using nextjs) | |
import z from "zod"; | |
import { db } from "@/lib/db"; | |
import { validate } from "@/lib/validate"; | |
import { model } from "@/drizzle/schema"; | |
type NewModel = typeof model.$inferInsert; | |
type Model = typeof model.$inferSelect; | |
class Model { | |
async create(formData: Record<string, FormDataEntryValue>) { | |
return { errors: null, model: null }; | |
} | |
get destroy() { | |
return db.delete; | |
} | |
get findFirst() { | |
return db.query.model.findFirst; | |
} | |
get findMany() { | |
return db.query.model.findMany; | |
} | |
get schema() { | |
return model; | |
} | |
get select() { | |
return db.select; | |
} | |
async update(formData: { [k: string]: FormDataEntryValue }, id: Model["id"]) { | |
return { errors: null, model: null }; | |
} | |
} | |
const DataModel = new Model(); | |
export { DataModel }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Class based abstratction layer for Prisma (using remix) | |
import type { Prisma } from "@prisma/client"; | |
import z from "zod"; | |
import { prisma } from "~/services/db.server"; | |
import { validate } from "~/services/validate.server"; | |
class Model { | |
get aggregate() { | |
return prisma.model.aggregate; | |
} | |
get count() { | |
return prisma.model.count; | |
} | |
async create(formData: { [k: string]: FormDataEntryValue }) { | |
return { errors: null, model: null }; | |
} | |
createMany() { | |
return { count: 0 }; | |
} | |
get destroy() { | |
return prisma.model.delete; | |
} | |
get destroyMany() { | |
return prisma.model.deleteMany; | |
} | |
get findFirst() { | |
return prisma.model.findFirst; | |
} | |
get findMany() { | |
return prisma.model.findMany; | |
} | |
get findUnique() { | |
return prisma.model.findUnique | |
} | |
get groupBy() { | |
return prisma.model.groupBy; | |
} | |
async update(formData: { [k: string]: FormDataEntryValue }, id: Model["id"]) { | |
return { errors: null, model: null }; | |
} | |
updateMany() { | |
return { count: 0 }; | |
} | |
upsert() { | |
return null; | |
} | |
} | |
const DataModel = new Model(); | |
export { DataModel }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment