feat: Add database connection handling to server hooks

This commit is contained in:
2024-08-28 00:13:46 +09:00
parent e7949b6c5f
commit d3cc3145e0
8 changed files with 109 additions and 87 deletions
+2 -2
View File
@@ -18,8 +18,8 @@ let data: {
updated: "",
};
export const load: PageServerLoad = async ({ params }) => {
const db = await PG();
export const load: PageServerLoad = async ({ params, locals }) => {
const db = await PG(locals.db);
await db.begin();
try {
const recent_articles = await db.query(
@@ -3,11 +3,11 @@ import type { PageServerLoad } from './$types';
import PG from '$lib/server/database';
import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ params }) => {
export const load: PageServerLoad = async ({ params, locals }) => {
const { category, id } = params;
console.log(id);
const db = await PG();
const db = await PG(locals.db);
await db.begin();
try {
const article = await db.query(
@@ -3,11 +3,11 @@ import type { PageServerLoad } from './$types';
import PG from '$lib/server/database';
import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ params }) => {
export const load: PageServerLoad = async ({ params, locals }) => {
const { category, id, series } = params;
console.log(id);
const db = await PG();
const db = await PG(locals.db);
await db.begin();
try {
const article = await db.query(