wip: move workstation
This commit is contained in:
20
backend/db.ts
Normal file
20
backend/db.ts
Normal 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
13
backend/post.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user