This commit is contained in:
Akis 2023-01-06 21:23:14 +02:00
parent f2f97caf80
commit 13462b5f8a
Signed by untrusted user: akis
GPG Key ID: 267BF5C6677944ED
4 changed files with 32 additions and 28 deletions

View File

@ -1,26 +0,0 @@
import knex from "knex";
import { env } from "$env/dynamic/private";
const db = knex({
client: "pg",
connection: {
host: String(env.DB_HOST),
port: Number(env.DB_PORT),
user: String(env.DB_USERNAME),
password: String(env.DB_PASSWORD),
database: "website"
}
})
if (! await db.schema.hasTable("Announcements")) {
await db.schema.createTable("Announcements", (table) => {
table.increments("id");
table.text("title").notNullable();
table.string("severity").notNullable();
table.string("author").notNullable();
table.string("link").nullable();
table.bigInteger("created").notNullable();
});
}
export default db;

30
src/lib/server/db.ts Normal file
View File

@ -0,0 +1,30 @@
import knex from "knex";
import type { Knex } from "knex";
import { env } from "$env/dynamic/private";
import { building } from "$app/environment";
export let db: Knex;
if (!building) {
db = knex({
client: "pg",
connection: {
host: String(env.DB_HOST),
port: Number(env.DB_PORT),
user: String(env.DB_USERNAME),
password: String(env.DB_PASSWORD),
database: "website"
}
})
if (! await db.schema.hasTable("Announcements")) {
await db.schema.createTable("Announcements", (table) => {
table.increments("id");
table.text("title").notNullable();
table.string("severity").notNullable();
table.string("author").notNullable();
table.string("link").nullable();
table.bigInteger("created").notNullable();
});
}
}

View File

@ -1,7 +1,7 @@
import type { PageServerLoad } from "./$types";
import { compile } from "mdsvex";
import sanitizeHtml from "sanitize-html";
import db from "$lib/db";
import { db } from "$lib/server/db";
export const load: PageServerLoad = async () => {

View File

@ -1,7 +1,7 @@
import type { Actions } from "./$types";
import Joi from "joi";
import { fail } from "@sveltejs/kit";
import db from "$lib/db";
import { db } from "$lib/server/db";
export const actions: Actions = {
add: async ({ request, locals }) => {