115 lines
2.2 KiB
TypeScript
115 lines
2.2 KiB
TypeScript
import { DATABASE_URL } from '$env/static/private';
|
|
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
|
|
import type { Prisma } from '@prisma/client';
|
|
import { PrismaClient } from '@prisma/client';
|
|
|
|
const adapter = new PrismaBetterSqlite3({
|
|
url: DATABASE_URL
|
|
});
|
|
const db = new PrismaClient({ adapter });
|
|
|
|
const GET = {
|
|
year: async (where: Prisma.YearWhereUniqueInput) => {
|
|
return await db.year.findUnique({
|
|
where,
|
|
include: {
|
|
people: true
|
|
}
|
|
});
|
|
},
|
|
years: async (where: Prisma.YearWhereInput) => {
|
|
return await db.year.findMany({
|
|
where
|
|
});
|
|
},
|
|
|
|
person: async (where: Prisma.PersonWhereUniqueInput) => {
|
|
return await db.person.findUnique({
|
|
where
|
|
});
|
|
},
|
|
people: async (where: Prisma.PersonWhereInput) => {
|
|
return await db.person.findMany({
|
|
where,
|
|
include: {
|
|
gifts: true
|
|
}
|
|
});
|
|
},
|
|
|
|
gift: async (where: Prisma.GiftWhereUniqueInput) => {
|
|
return await db.gift.findUnique({
|
|
where
|
|
});
|
|
},
|
|
gifts: async (where: Prisma.GiftWhereUniqueInput) => {
|
|
return await db.gift.findMany({
|
|
where
|
|
});
|
|
}
|
|
};
|
|
|
|
const CREATE = {
|
|
year: async (data: Prisma.YearCreateInput) => {
|
|
return await db.year.create({
|
|
data
|
|
});
|
|
},
|
|
person: async (data: Prisma.PersonCreateInput) => {
|
|
return await db.person.create({
|
|
data
|
|
});
|
|
},
|
|
gift: async (data: Prisma.GiftCreateInput) => {
|
|
return await db.gift.create({
|
|
data
|
|
});
|
|
}
|
|
};
|
|
|
|
const UPDATE = {
|
|
year: async (where: Prisma.YearWhereUniqueInput, data: Prisma.YearUpdateInput) => {
|
|
return await db.year.update({
|
|
where,
|
|
data
|
|
});
|
|
},
|
|
person: async (where: Prisma.PersonWhereUniqueInput, data: Prisma.PersonUpdateInput) => {
|
|
return await db.person.update({
|
|
where,
|
|
data
|
|
});
|
|
},
|
|
gift: async (where: Prisma.GiftWhereUniqueInput, data: Prisma.GiftUpdateInput) => {
|
|
return await db.gift.update({
|
|
where,
|
|
data
|
|
});
|
|
}
|
|
};
|
|
|
|
const DELETE = {
|
|
year: async (where: Prisma.YearWhereUniqueInput) => {
|
|
return await db.year.delete({
|
|
where
|
|
});
|
|
},
|
|
person: async (where: Prisma.PersonWhereUniqueInput) => {
|
|
return await db.person.delete({
|
|
where
|
|
});
|
|
},
|
|
gift: async (where: Prisma.GiftWhereUniqueInput) => {
|
|
return await db.gift.delete({
|
|
where
|
|
});
|
|
}
|
|
};
|
|
|
|
export const DB = {
|
|
GET,
|
|
CREATE,
|
|
UPDATE,
|
|
DELETE
|
|
};
|