Commit 49140e33 authored by 王曜嵚 Wang Yaoqin's avatar 王曜嵚 Wang Yaoqin

dev: 回收PG client

parent 3781a01b
......@@ -31,10 +31,10 @@ export default defineEventHandler(async (event) => {
let result = await executePgQuery({ client, query: "SELECT u.datname FROM pg_catalog.pg_database u where u.datname='" + database + "';" })
if (result.rows.length === 0) {
await executePgQuery({ client, query: 'CREATE DATABASE ' + database })
await client.end()
client = await createPgClient({ host: HOST, port: PgPort, database: database })
await stopPgClient(client)
client = await createPgClient({ host: HOST, port: +PgPort, database: database })
await executePgQuery({ client, query: 'CREATE SCHEMA library' })
await client.end()
await stopPgClient(client)
}
}
})
......
......@@ -3,7 +3,6 @@ import { TableV2 } from "~/server/utils/postgres"
export default defineEventHandler(async (event) => {
let username = event.context.username
let docker = createDockerFactory(username)
let pgClient = await createPgClientFactory('backend_helper')
const row = await getPgTableData( 'v2', username)
const info: Partial<TableV2> & { branch: string } = { ...row, branch: '' }
info.status = row?.status || 'null'
......
......@@ -17,11 +17,11 @@ export default defineNitroPlugin(async (nitroApp) => {
let result = await executePgQuery({ client, query: "SELECT u.datname FROM pg_catalog.pg_database u where u.datname='backend_helper';" })
if (result.rows.length === 0) {
await executePgQuery({ client, query: fs.readFileSync(path.resolve('./public/files/postgres/create_backend_helper.sql'), { encoding: 'utf-8'})})
await client.end()
await stopPgClient(client)
client = await createPgClientFactory('backend_helper')
await executePgQuery({ client, query: fs.readFileSync(path.resolve('./public/files/postgres/create_user.sql'), { encoding: 'utf-8' })})
await executePgQuery({ client, query: fs.readFileSync(path.resolve('./public/files/postgres/create_v2.sql'), { encoding: 'utf-8' })})
await executePgQuery({ client, query: fs.readFileSync(path.resolve('./public/files/postgres/create_v1.sql'), { encoding: 'utf-8'})})
await client.end()
await stopPgClient(client)
}
})
\ No newline at end of file
......@@ -38,8 +38,8 @@ export function executePgQuery ({ client, query }: { client: pg.Client, query: s
export function createPgClientFactory (database?: string) {
return createPgClient({ database })
}
export async function stopPgClient (pgClient: pg.Client) {
await pgClient.end()
export function stopPgClient (pgClient: pg.Client) {
return pgClient.end()
}
export type TableUser = { username: string, port: number }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment