Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
leximpact-legi-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leximpact
Exploration
leximpact-legi-ui
Commits
cf1e5ab0
Commit
cf1e5ab0
authored
2 months ago
by
David Smadja
Browse files
Options
Downloads
Patches
Plain Diff
Improve db connection pool management
parent
b1c927dc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/hooks.server.ts
+2
-3
2 additions, 3 deletions
src/hooks.server.ts
src/lib/server/db-connect.ts
+17
-18
17 additions, 18 deletions
src/lib/server/db-connect.ts
src/routes/api/toc/[id]/+server.ts
+4
-2
4 additions, 2 deletions
src/routes/api/toc/[id]/+server.ts
with
23 additions
and
23 deletions
src/hooks.server.ts
+
2
−
3
View file @
cf1e5ab0
import
{
dbConnect
}
from
"
$lib/server/db-connect
"
import
{
getDbPool
}
from
"
$lib/server/db-connect
"
import
type
{
Handle
}
from
"
@sveltejs/kit
"
export
const
handle
:
Handle
=
async
({
event
,
resolve
})
=>
{
if
(
!
event
.
locals
.
sql
)
{
const
sql
=
await
dbConnect
()
event
.
locals
=
{
sql
}
event
.
locals
.
sql
=
await
getDbPool
()
}
return
await
resolve
(
event
)
}
This diff is collapsed.
Click to expand it.
src/lib/server/db-connect.ts
+
17
−
18
View file @
cf1e5ab0
import
config
from
"
$lib/server/config
"
import
postgres
from
"
postgres
"
import
config
from
"
$lib/server/config
"
let
sql
:
ReturnType
<
typeof
postgres
>
|
null
=
null
export
async
function
dbConnect
()
{
try
{
const
sql
=
postgres
({
export
async
function
getDbPool
()
{
if
(
!
sql
)
{
sql
=
postgres
({
host
:
config
.
db
.
host
,
database
:
config
.
db
.
database
,
port
:
config
.
db
.
port
,
username
:
config
.
db
.
username
,
password
:
config
.
db
.
password
,
max
:
20
,
idle_timeout
:
30
,
connection
:
{
application_name
:
"
legi-ui
"
,
},
})
}
return
sql
}
catch
(
error
:
unknown
)
{
if
(
typeof
error
===
"
string
"
)
{
console
.
log
(
"
An error occured while calling oracledb.createPool:
\n
"
,
error
,
)
}
else
if
(
error
instanceof
Error
)
{
console
.
log
(
"
An error occured while calling oracledb.createPool:
\n
"
,
error
.
stack
,
)
}
throw
error
export
async
function
closeDbPool
()
{
if
(
sql
)
{
await
sql
.
end
()
sql
=
null
}
}
This diff is collapsed.
Click to expand it.
src/routes/api/toc/[id]/+server.ts
+
4
−
2
View file @
cf1e5ab0
...
...
@@ -10,10 +10,10 @@ export const GET: RequestHandler = async ({ params, locals }) => {
const
{
id
}
=
params
as
{
id
:
string
}
const
{
sql
}
=
locals
const
dbConnection
=
await
sql
.
reserve
()
switch
(
true
)
{
case
id
.
startsWith
(
"
LEGITEXT
"
):
{
const
dbConnection
=
await
sql
.
reserve
()
const
structDataFromDb
:
queryDataStructData
[]
=
await
dbConnection
<
JSON
>
`
select jsonb_path_query(data, '$.STRUCT') AS struct_data
from textelr
...
...
@@ -35,6 +35,8 @@ export const GET: RequestHandler = async ({ params, locals }) => {
}
}
case
id
.
startsWith
(
"
LEGISCTA
"
):
{
const
dbConnection
=
await
sql
.
reserve
()
const
structDataFromDb
:
queryDataStructData
[]
=
await
dbConnection
<
JSON
>
`
select jsonb_path_query(data, '$.STRUCTURE_TA') AS struct_data
from section_ta
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment