Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nuxt-backend-helper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王曜嵚 Wang Yaoqin
nuxt-backend-helper
Commits
49140e33
Commit
49140e33
authored
Jun 21, 2024
by
王曜嵚 Wang Yaoqin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev: 回收PG client
parent
3781a01b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
8 deletions
+7
-8
install.post.ts
server/api/devops/v1/install.post.ts
+3
-3
getProjectInfo.get.ts
server/api/devops/v2/getProjectInfo.get.ts
+0
-1
prepare_postgres.ts
server/plugins/prepare_postgres.ts
+2
-2
postgres.ts
server/utils/postgres.ts
+2
-2
No files found.
server/api/devops/v1/install.post.ts
View file @
49140e33
...
...
@@ -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
)
}
}
})
...
...
server/api/devops/v2/getProjectInfo.get.ts
View file @
49140e33
...
...
@@ -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'
...
...
server/plugins/prepare_postgres.ts
View file @
49140e33
...
...
@@ -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
server/utils/postgres.ts
View file @
49140e33
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment