feat: Refactor database initialization and table creation

This commit is contained in:
2024-08-21 02:44:39 +09:00
parent a5b00f3bb2
commit c4a37dcdc5
4 changed files with 111 additions and 110 deletions
+5 -11
View File
@@ -1,8 +1,7 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
// import index from '$lib/index';
import type { Content } from '$lib/article';
import { pool } from '$lib/server/database';
import PG from '$lib/server/database';
let data: {
recent: Content[],
@@ -23,16 +22,11 @@ let data: {
};
export const load: PageServerLoad = async ({ params }) => {
const connect = await pool.connect();
const result = await connect.query('SELECT NOW()')
.then((res) => {
data.updated = res.rows[0].now.toISOString();
})
.catch((err) => {
error(err);
});
connect.release();
const db = await PG();
const now = await db.query('SELECT NOW()');
await db.release();
data.updated = now.rows[0].now;
return data;
}