wip: move workstation

This commit is contained in:
2023-10-21 10:17:10 +11:00
parent 08db8ef124
commit 6d3dab582a
11 changed files with 760 additions and 6 deletions

20
backend/db.ts Normal file
View File

@@ -0,0 +1,20 @@
import mysql, { PoolOptions } from "mysql2";
const access: PoolOptions = {
host: process.env.MYSQL_HOST,
port: 'MYSQL_PORT' in process.env && typeof process.env.MYSQL_PORT === 'string' ? parseInt(process.env.MYSQL_PORT) : 3306,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: 'MYSQL_DATABASE' in process.env ? process.env.MYSQL_DATABASE : 'blog',
waitForConnections: true,
connectionLimit: 10,
maxIdle: 10,
idleTimeout: 60000,
queueLimit: 0,
enableKeepAlive: true,
keepAliveInitialDelay: 0,
}
export const pool = mysql.createPool(access)
export const promisePool = pool.promise()

13
backend/post.ts Normal file
View File

@@ -0,0 +1,13 @@
import { RowDataPacket } from "mysql2";
import { promisePool } from "@/backend/db";
export async function getPost(slug: string): Promise<string> {
try {
const [rows, fields] = await promisePool.query<RowDataPacket[]>(
'select content from post where slug = ?', [slug])
return rows[0]['content']
} catch (e) {
console.log(e)
throw e
}
}