Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
postgrestutils
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tools
postgrestutils
Commits
4ac811eb
Commit
4ac811eb
authored
6 years ago
by
Fynn Becker
Browse files
Options
Downloads
Patches
Plain Diff
Improve exception message, set default BASE_URI
parent
d00ca304
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
postgrestutils/__init__.py
+1
-0
1 addition, 0 deletions
postgrestutils/__init__.py
postgrestutils/client/postgrestclient.py
+9
-5
9 additions, 5 deletions
postgrestutils/client/postgrestclient.py
postgrestutils/settings.py
+1
-3
1 addition, 3 deletions
postgrestutils/settings.py
with
11 additions
and
8 deletions
postgrestutils/__init__.py
+
1
−
0
View file @
4ac811eb
import
logging
from
.
import
settings
from
requests
import
HTTPError
logger
=
logging
.
getLogger
(
"
postgrestutils
"
)
...
...
This diff is collapsed.
Click to expand it.
postgrestutils/client/postgrestclient.py
+
9
−
5
View file @
4ac811eb
...
...
@@ -16,16 +16,20 @@ class PostgrestClient:
:param path_and_query: specifies the endpoint and optionally filter queries
:param singular: if True returns a JSON object rather than a list (406 when multiple results are returned)
:param parse_dt: if True attempts to parse datetime strings to python datetime objects
:return: result(s) as
JSON
or raises HTTPError
:return: result(s) as
python object
or raises HTTPError
"""
if
singular
:
self
.
session
.
headers
[
"
Accept
"
]
=
"
application/vnd.pgrst.object+json
"
else
:
self
.
session
.
headers
[
"
Accept
"
]
=
"
application/json
"
r
=
self
.
session
.
get
(
urljoin
(
self
.
base_uri
,
path_and_query
))
r
.
raise_for_status
()
res
=
self
.
session
.
get
(
urljoin
(
self
.
base_uri
,
path_and_query
))
try
:
res
.
raise_for_status
()
except
requests
.
HTTPError
as
e
:
raise
type
(
e
)(
res
.
status_code
,
res
.
reason
,
res
.
text
)
if
parse_dt
:
json_result
=
r
.
json
(
object_hook
=
datetime_parser
)
json_result
=
r
es
.
json
(
object_hook
=
datetime_parser
)
else
:
json_result
=
r
.
json
()
json_result
=
r
es
.
json
()
return
json_result
This diff is collapsed.
Click to expand it.
postgrestutils/settings.py
+
1
−
3
View file @
4ac811eb
import
re
BASE_URI
=
str
()
BASE_URI
=
"
http://127.0.0.1:3000
"
JWT
=
str
()
...
...
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