macrostrat.database 3.3.2__tar.gz → 3.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/PKG-INFO +1 -1
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/__init__.py +9 -7
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/utils.py +3 -2
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/pyproject.toml +1 -1
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/mapper/__init__.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/mapper/base.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/mapper/cache.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/mapper/utils.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/postgresql.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/transfer/__init__.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/transfer/dump_database.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/transfer/move_tables.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/transfer/restore_database.py +0 -0
- {macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/transfer/utils.py +0 -0
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import warnings
|
|
2
2
|
from contextlib import contextmanager
|
|
3
|
-
from enum import Enum
|
|
4
3
|
from pathlib import Path
|
|
5
4
|
from typing import Optional, Union
|
|
6
5
|
|
|
7
6
|
from psycopg2.errors import InvalidSavepointSpecification
|
|
8
7
|
from psycopg2.sql import Identifier
|
|
9
|
-
from sqlalchemy import URL, MetaData, create_engine, inspect,
|
|
8
|
+
from sqlalchemy import URL, MetaData, create_engine, inspect, Engine
|
|
10
9
|
from sqlalchemy.exc import IntegrityError, InternalError
|
|
11
10
|
from sqlalchemy.ext.compiler import compiles
|
|
12
11
|
from sqlalchemy.orm import Session, scoped_session, sessionmaker
|
|
13
12
|
from sqlalchemy.sql.expression import Insert
|
|
14
13
|
|
|
15
14
|
from macrostrat.utils import get_logger
|
|
16
|
-
|
|
17
15
|
from .mapper import DatabaseMapper
|
|
18
16
|
from .postgresql import on_conflict, prefix_inserts # noqa
|
|
19
17
|
from .utils import ( # noqa
|
|
@@ -41,14 +39,14 @@ class Database(object):
|
|
|
41
39
|
|
|
42
40
|
__inspector__ = None
|
|
43
41
|
|
|
44
|
-
def __init__(self, db_conn: Union[str, URL], *, echo_sql=False, **kwargs):
|
|
42
|
+
def __init__(self, db_conn: Union[str, URL, Engine], *, echo_sql=False, **kwargs):
|
|
45
43
|
"""
|
|
46
44
|
Wrapper for interacting with a database using SQLAlchemy.
|
|
47
45
|
Optimized for use with PostgreSQL, but usable with SQLite
|
|
48
46
|
as well.
|
|
49
47
|
|
|
50
48
|
Args:
|
|
51
|
-
db_conn (str): Connection string for the database.
|
|
49
|
+
db_conn (str | URL | Engine): Connection string or engine for the database.
|
|
52
50
|
|
|
53
51
|
Keyword Args:
|
|
54
52
|
echo_sql (bool): If True, will echo SQL commands to the
|
|
@@ -61,8 +59,12 @@ class Database(object):
|
|
|
61
59
|
|
|
62
60
|
self.instance_params = kwargs.pop("instance_params", {})
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
if isinstance(db_conn, Engine):
|
|
63
|
+
log.info(f"Set up database connection with engine {db_conn.url}")
|
|
64
|
+
self.engine = db_conn
|
|
65
|
+
else:
|
|
66
|
+
log.info(f"Setting up database connection with URL '{db_conn}'")
|
|
67
|
+
self.engine = create_engine(db_conn, echo=echo_sql, **kwargs)
|
|
66
68
|
self.metadata = kwargs.get("metadata", metadata)
|
|
67
69
|
|
|
68
70
|
# Scoped session for database
|
|
@@ -333,9 +333,10 @@ def _should_raise_query_error(err):
|
|
|
333
333
|
return True
|
|
334
334
|
|
|
335
335
|
# If we cancel statements midstream, we should raise the error.
|
|
336
|
-
# We might want to change this behavior in the future
|
|
336
|
+
# We might want to change this behavior in the future, or support more graceful handling of errors from other
|
|
337
|
+
# database backends.
|
|
337
338
|
# Ideally we could handle operational errors more gracefully
|
|
338
|
-
if isinstance(orig_err, psycopg2.errors.QueryCanceled) or orig_err
|
|
339
|
+
if isinstance(orig_err, psycopg2.errors.QueryCanceled) or getattr(orig_err, "pgcode", None) == "57014":
|
|
339
340
|
return True
|
|
340
341
|
|
|
341
342
|
return False
|
|
@@ -3,7 +3,7 @@ authors = ["Daven Quinn <dev@davenquinn.com>"]
|
|
|
3
3
|
description = "A SQLAlchemy-based database toolkit."
|
|
4
4
|
name = "macrostrat.database"
|
|
5
5
|
packages = [{ include = "macrostrat" }]
|
|
6
|
-
version = "3.
|
|
6
|
+
version = "3.4.0"
|
|
7
7
|
|
|
8
8
|
[tool.poetry.dependencies]
|
|
9
9
|
GeoAlchemy2 = "^0.14.0"
|
{macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/mapper/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/transfer/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/transfer/move_tables.py
RENAMED
|
File without changes
|
|
File without changes
|
{macrostrat_database-3.3.2 → macrostrat_database-3.4.0}/macrostrat/database/transfer/utils.py
RENAMED
|
File without changes
|