Add Prisma integration with SQLite, update dependencies, and configure Svelte
This commit is contained in:
15
src/lib/remotes/db.remote.ts
Normal file
15
src/lib/remotes/db.remote.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { command, query } from '$app/server';
|
||||
import { DB } from '$lib/server/db';
|
||||
import * as v from 'valibot';
|
||||
|
||||
export const getYears = query(async () => {
|
||||
return await DB.GET.years();
|
||||
});
|
||||
|
||||
export const addYear = command(v.number(), async (year) => {
|
||||
await DB.CREATE.year({
|
||||
year: year
|
||||
});
|
||||
|
||||
getYears().refresh();
|
||||
});
|
||||
106
src/lib/server/db.ts
Normal file
106
src/lib/server/db.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
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
|
||||
});
|
||||
},
|
||||
years: async () => {
|
||||
return await db.year.findMany();
|
||||
},
|
||||
|
||||
person: async (where: Prisma.PersonWhereUniqueInput) => {
|
||||
return await db.person.findUnique({
|
||||
where
|
||||
});
|
||||
},
|
||||
people: async (where: Prisma.PersonWhereUniqueInput) => {
|
||||
return await db.person.findMany({
|
||||
where
|
||||
});
|
||||
},
|
||||
|
||||
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
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
@import 'tailwindcss';
|
||||
@plugin '@tailwindcss/forms';
|
||||
@plugin '@tailwindcss/typography';
|
||||
@plugin "daisyui";
|
||||
|
||||
Reference in New Issue
Block a user