Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
Web-CoreX
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
Hendrik Garske
Web-CoreX
Commits
30a7cde4
Commit
30a7cde4
authored
Dec 27, 2025
by
Hendrik Garske
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Datenbank-Connection lazy initialisieren für Build-Kompatibilität
parent
b092c6c3
Pipeline
#23
passed with stages
in 1 minute and 33 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
16 deletions
+25
-16
db.ts
lib/db.ts
+25
-16
No files found.
lib/db.ts
View file @
30a7cde4
import
{
Pool
}
from
'pg'
import
{
Pool
}
from
'pg'
const
connectionString
=
process
.
env
.
DATABASE_URL
let
pool
:
Pool
|
undefined
if
(
!
connectionString
)
{
// Lazy initialization of the database pool
throw
new
Error
(
'DATABASE_URL environment variable is not set'
)
function
getPool
():
Pool
{
}
if
(
!
pool
)
{
const
connectionString
=
process
.
env
.
DATABASE_URL
if
(
!
connectionString
)
{
throw
new
Error
(
'DATABASE_URL environment variable is not set'
)
}
// Create a singleton pool instance
pool
=
new
Pool
({
const
pool
=
new
Pool
({
connectionString
,
connectionString
,
ssl
:
process
.
env
.
NODE_ENV
===
'production'
?
{
rejectUnauthorized
:
false
}
:
false
,
ssl
:
process
.
env
.
NODE_ENV
===
'production'
?
{
rejectUnauthorized
:
false
}
:
false
,
})
})
// Handle pool errors
// Handle pool errors
pool
.
on
(
'error'
,
(
err
)
=>
{
pool
.
on
(
'error'
,
(
err
)
=>
{
console
.
error
(
'Unexpected error on idle client'
,
err
)
console
.
error
(
'Unexpected error on idle client'
,
err
)
process
.
exit
(
-
1
)
process
.
exit
(
-
1
)
})
})
}
return
pool
}
export
{
p
ool
as
db
}
export
{
getP
ool
as
db
}
// Helper function to query the database
// Helper function to query the database
export
async
function
query
(
text
:
string
,
params
?:
unknown
[])
{
export
async
function
query
(
text
:
string
,
params
?:
unknown
[])
{
const
dbPool
=
getPool
()
const
start
=
Date
.
now
()
const
start
=
Date
.
now
()
const
res
=
await
p
ool
.
query
(
text
,
params
)
const
res
=
await
dbP
ool
.
query
(
text
,
params
)
const
duration
=
Date
.
now
()
-
start
const
duration
=
Date
.
now
()
-
start
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
console
.
log
(
'Executed query'
,
{
text
,
duration
,
rows
:
res
.
rowCount
})
console
.
log
(
'Executed query'
,
{
text
,
duration
,
rows
:
res
.
rowCount
})
...
...
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