macrostrat.database 4.0.2__tar.gz → 4.1.1__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.
Files changed (18) hide show
  1. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/PKG-INFO +5 -5
  2. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/query.py +26 -11
  3. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/utils.py +4 -2
  4. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/pyproject.toml +5 -5
  5. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/.DS_Store +0 -0
  6. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/__init__.py +0 -0
  7. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/compat.py +0 -0
  8. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/mapper/__init__.py +0 -0
  9. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/mapper/base.py +0 -0
  10. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/mapper/cache.py +0 -0
  11. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/mapper/utils.py +0 -0
  12. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/postgresql.py +0 -0
  13. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/transfer/__init__.py +0 -0
  14. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/transfer/dump_database.py +0 -0
  15. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/transfer/move_tables.py +0 -0
  16. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/transfer/restore_database.py +0 -0
  17. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/transfer/stream_utils.py +0 -0
  18. {macrostrat_database-4.0.2 → macrostrat_database-4.1.1}/macrostrat/database/transfer/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: macrostrat.database
3
- Version: 4.0.2
3
+ Version: 4.1.1
4
4
  Summary: A SQLAlchemy-based database toolkit.
5
5
  Author: Daven Quinn
6
6
  Author-email: Daven Quinn <dev@davenquinn.com>
@@ -10,14 +10,14 @@ Classifier: Programming Language :: Python :: 3.11
10
10
  Classifier: Programming Language :: Python :: 3.12
11
11
  Classifier: Programming Language :: Python :: 3.13
12
12
  Classifier: Programming Language :: Python :: 3.14
13
- Requires-Dist: geoalchemy2>=0.15.2,<0.16
13
+ Requires-Dist: geoalchemy2>=0.15.2,<0.21.0
14
14
  Requires-Dist: sqlalchemy>=2.0.18,<3
15
- Requires-Dist: sqlalchemy-utils>=0.41.1,<0.42
15
+ Requires-Dist: sqlalchemy-utils>=0.41.1,<0.43
16
16
  Requires-Dist: click>=8.1.3,<9
17
17
  Requires-Dist: macrostrat-utils>=1.3.3,<2
18
18
  Requires-Dist: sqlparse>=0.5.1,<0.6
19
- Requires-Dist: aiofiles>=23.2.1,<24
20
- Requires-Dist: rich>=13.7.1,<14
19
+ Requires-Dist: aiofiles>=23.2.1,<26
20
+ Requires-Dist: rich>=13.7.1,<16
21
21
  Requires-Dist: psycopg>=3.2.1,<4
22
22
  Requires-Dist: psycopg2>=2.9.11,<3
23
23
  Requires-Python: >=3.10, <4
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import re
2
3
  from dataclasses import dataclass
3
4
  from enum import Enum
4
5
  from pathlib import Path
@@ -9,6 +10,10 @@ from warnings import warn
9
10
 
10
11
  import psycopg2.sql as psql2
11
12
  from click import secho
13
+ from macrostrat.database.compat import (
14
+ update_legacy_identifier,
15
+ )
16
+ from macrostrat.utils import get_logger
12
17
  from psycopg.errors import QueryCanceled
13
18
  from psycopg.sql import SQL, Composable, Composed
14
19
  from rich.console import Console
@@ -24,11 +29,6 @@ from sqlalchemy.exc import (
24
29
  from sqlalchemy.sql.elements import TextClause
25
30
  from sqlparse import format, split
26
31
 
27
- from macrostrat.database.compat import (
28
- update_legacy_identifier,
29
- )
30
- from macrostrat.utils import get_logger
31
-
32
32
  log = get_logger(__name__)
33
33
 
34
34
 
@@ -319,7 +319,7 @@ def _run_sql(connectable, sql, params=None, *, print_skipped=True, **kwargs):
319
319
  params = [params] * len(queries)
320
320
 
321
321
  for index, (query, _params) in enumerate(zip(queries, params)):
322
- _query, sql_text = _render_query_text(connectable, query, _params)
322
+ _query, sql_text, rest_params = _render_query_text(connectable, query, _params)
323
323
  if sql_text == "":
324
324
  continue
325
325
 
@@ -349,6 +349,11 @@ def _render_query_text(connectable, query, params):
349
349
  if isinstance(query, (psql2.SQL, psql2.Composed)):
350
350
  query = update_legacy_identifier(query)
351
351
 
352
+ if isinstance(query, str):
353
+ # Escape postgresql cast parameters after SQLAlchemy binds
354
+ # (e.g., :param::text)
355
+ query = escape_postgresql_cast_parameters(query)
356
+
352
357
  if pre_bind_params is not None:
353
358
  if not isinstance(query, SQL):
354
359
  query = SQL(query)
@@ -360,9 +365,19 @@ def _render_query_text(connectable, query, params):
360
365
 
361
366
  sql_text = str(query)
362
367
  if isinstance(query, str):
363
- sql_text = format(query, strip_comments=True).strip()
368
+ sql_text = format(sql_text, strip_comments=True).strip()
364
369
 
365
- return query, sql_text
370
+ return query, sql_text, params
371
+
372
+
373
+ def escape_postgresql_cast_parameters(sql_text):
374
+ regex = r":([\w]+)::([a-zA-Z]+)"
375
+ for res in re.findall(regex, sql_text):
376
+ param, cast_type = res
377
+ sql_text = sql_text.replace(
378
+ f":{param}::{cast_type}", ":" + param + r"\:\:" + cast_type
379
+ )
380
+ return sql_text
366
381
 
367
382
 
368
383
  def _execute_one(
@@ -377,7 +392,7 @@ def _execute_one(
377
392
  ):
378
393
  params = result.params
379
394
 
380
- query, sql_text = _render_query_text(connectable, result.query, params)
395
+ query, sql_text, _params = _render_query_text(connectable, result.query, params)
381
396
  if has_server_binds is None:
382
397
  has_server_binds = infer_has_server_binds(sql_text)
383
398
 
@@ -402,11 +417,11 @@ def _execute_one(
402
417
  log.debug("Executing SQL: \n %s", query)
403
418
  if has_server_binds:
404
419
  conn = _get_connection(connectable)
405
- res = conn.exec_driver_sql(query, params)
420
+ res = conn.exec_driver_sql(query, _params)
406
421
  else:
407
422
  if not isinstance(query, TextClause):
408
423
  query = text(query)
409
- res = connectable.execute(query, params)
424
+ res = connectable.execute(query, _params)
410
425
 
411
426
  yield res
412
427
 
@@ -101,7 +101,9 @@ def temp_database(conn_string, drop=True, ensure_empty=False):
101
101
  """Create a temporary database and tear it down after tests."""
102
102
  create_database(conn_string, exists_ok=True, replace=ensure_empty)
103
103
  try:
104
- yield create_engine(conn_string)
104
+ engine = create_engine(conn_string)
105
+ yield engine
106
+ engine.dispose()
105
107
  finally:
106
108
  if drop:
107
109
  drop_database(conn_string)
@@ -149,7 +151,7 @@ def create_engine(db_conn, **kwargs):
149
151
  if isinstance(url, str):
150
152
  url = make_url(url)
151
153
  # Set the driver to psycopg if not already set
152
- if url.drivername != "postgresql+psycopg":
154
+ if "postgres" in url.drivername:
153
155
  url = url.set(drivername="postgresql+psycopg")
154
156
 
155
157
  return base_create_engine(url, **kwargs)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "macrostrat.database"
3
- version = "4.0.2"
3
+ version = "4.1.1"
4
4
  description = "A SQLAlchemy-based database toolkit."
5
5
  authors = [{ name = "Daven Quinn", email = "dev@davenquinn.com" }]
6
6
  requires-python = ">=3.10,<4"
@@ -13,14 +13,14 @@ classifiers = [
13
13
  "Programming Language :: Python :: 3.14",
14
14
  ]
15
15
  dependencies = [
16
- "GeoAlchemy2>=0.15.2,<0.16",
16
+ "GeoAlchemy2>=0.15.2,<0.21.0",
17
17
  "SQLAlchemy>=2.0.18,<3",
18
- "SQLAlchemy-Utils>=0.41.1,<0.42",
18
+ "SQLAlchemy-Utils>=0.41.1,<0.43",
19
19
  "click>=8.1.3,<9",
20
20
  "macrostrat.utils>=1.3.3,<2",
21
21
  "sqlparse>=0.5.1,<0.6",
22
- "aiofiles>=23.2.1,<24",
23
- "rich>=13.7.1,<14",
22
+ "aiofiles>=23.2.1,<26",
23
+ "rich>=13.7.1,<16",
24
24
  "psycopg>=3.2.1,<4",
25
25
  "psycopg2>=2.9.11,<3",
26
26
  ]