Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
database-lib
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
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
Global Dynamic Exposure
Libraries
database-lib
Merge requests
!9
Resolve "Implement server-side cursors"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Resolve "Implement server-side cursors"
9-implement-server-side-cursors
into
main
Overview
4
Commits
1
Pipelines
11
Changes
1
Merged
Laurens Oostwegel
requested to merge
9-implement-server-side-cursors
into
main
2 years ago
Overview
4
Commits
1
Pipelines
11
Changes
1
Closes
#9 (closed)
\approve
@gislars
@ds
Edited
2 years ago
by
Laurens Oostwegel
0
0
Merge request reports
Compare
main
version 9
744fdb35
2 years ago
version 8
46613df5
2 years ago
version 7
3f9eda3e
2 years ago
version 6
1269983a
2 years ago
version 5
b6e4ceab
2 years ago
version 4
ffa00375
2 years ago
version 3
c6037069
2 years ago
version 2
ac7ea579
2 years ago
version 1
e6ca59cf
2 years ago
main (base)
and
version 2
latest version
1b14e0be
1 commit,
2 years ago
version 9
744fdb35
4 commits,
2 years ago
version 8
46613df5
3 commits,
2 years ago
version 7
3f9eda3e
2 commits,
2 years ago
version 6
1269983a
1 commit,
2 years ago
version 5
b6e4ceab
4 commits,
2 years ago
version 4
ffa00375
3 commits,
2 years ago
version 3
c6037069
2 commits,
2 years ago
version 2
ac7ea579
1 commit,
2 years ago
version 1
e6ca59cf
1 commit,
2 years ago
1 file
+
20
−
12
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
databaselib/database.py
+
20
−
12
View file @ ac7ea579
Edit in single-file editor
Open in Web IDE
Show full file
@@ -21,6 +21,7 @@ import logging
import
sqlite3
import
psycopg2
from
packaging
import
version
from
uuid
import
uuid4
logger
=
logging
.
getLogger
()
@@ -213,8 +214,15 @@ class PostGISDatabase(AbstractDatabase):
self
.
username
=
username
self
.
password
=
password
self
.
timeout
=
timeout
self
.
connection_string
=
(
f
"
host=
{
self
.
host
}
"
f
"
dbname=
{
self
.
dbname
}
"
f
"
user=
{
self
.
username
}
"
f
"
password=
{
self
.
password
}
"
f
"
port=
{
self
.
port
}
"
)
def
connect
(
self
,
timeout
:
int
=
None
):
def
connect
(
self
,
timeout
:
int
=
None
,
server_side_cursor
:
bool
=
False
):
"""
Creates a database connection and a cursor with psycopg2 with the
given credentials and include the connection and cursor as new attributes.
@@ -222,26 +230,26 @@ class PostGISDatabase(AbstractDatabase):
Args:
timeout (int, optional):
Timeout value for SQL queries in milliseconds.
server_side_cursor (bool, optional):
If `True`, the queries are run on the server side. This is needed if big queries
lead to memory issues on the client side.
"""
connection_string
=
(
f
"
host=
{
self
.
host
}
"
f
"
dbname=
{
self
.
dbname
}
"
f
"
user=
{
self
.
username
}
"
f
"
password=
{
self
.
password
}
"
f
"
port=
{
self
.
port
}
"
)
try
:
if
timeout
:
self
.
connection
=
psycopg2
.
connect
(
connection_string
,
options
=
f
"
-c statement_timeout=
{
timeout
*
1000
}
"
self
.
connection_string
,
options
=
f
"
-c statement_timeout=
{
timeout
*
1000
}
"
)
elif
self
.
timeout
:
self
.
connection
=
psycopg2
.
connect
(
connection_string
,
options
=
f
"
-c statement_timeout=
{
self
.
timeout
*
1000
}
"
self
.
connection_string
,
options
=
f
"
-c statement_timeout=
{
self
.
timeout
*
1000
}
"
)
else
:
self
.
connection
=
psycopg2
.
connect
(
connection_string
)
self
.
cursor
=
self
.
connection
.
cursor
()
self
.
connection
=
psycopg2
.
connect
(
self
.
connection_string
)
if
server_side_cursor
:
self
.
cursor
=
self
.
connection
.
cursor
(
name
=
f
"
{
uuid4
()
}
"
)
else
:
self
.
cursor
=
self
.
connection
.
cursor
()
except
Exception
as
e
:
logger
.
exception
(
e
)
Loading