macrostrat.database 4.0.2__tar.gz → 4.1.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.
Files changed (18) hide show
  1. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/PKG-INFO +5 -5
  2. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/query.py +22 -6
  3. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/utils.py +4 -2
  4. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/pyproject.toml +5 -5
  5. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/.DS_Store +0 -0
  6. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/__init__.py +0 -0
  7. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/compat.py +0 -0
  8. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/mapper/__init__.py +0 -0
  9. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/mapper/base.py +0 -0
  10. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/mapper/cache.py +0 -0
  11. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/mapper/utils.py +0 -0
  12. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/postgresql.py +0 -0
  13. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/transfer/__init__.py +0 -0
  14. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/transfer/dump_database.py +0 -0
  15. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/transfer/move_tables.py +0 -0
  16. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/transfer/restore_database.py +0 -0
  17. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/macrostrat/database/transfer/stream_utils.py +0 -0
  18. {macrostrat_database-4.0.2 → macrostrat_database-4.1.0}/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.0
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
@@ -319,7 +320,7 @@ def _run_sql(connectable, sql, params=None, *, print_skipped=True, **kwargs):
319
320
  params = [params] * len(queries)
320
321
 
321
322
  for index, (query, _params) in enumerate(zip(queries, params)):
322
- _query, sql_text = _render_query_text(connectable, query, _params)
323
+ _query, sql_text, rest_params = _render_query_text(connectable, query, _params)
323
324
  if sql_text == "":
324
325
  continue
325
326
 
@@ -349,6 +350,11 @@ def _render_query_text(connectable, query, params):
349
350
  if isinstance(query, (psql2.SQL, psql2.Composed)):
350
351
  query = update_legacy_identifier(query)
351
352
 
353
+ if isinstance(query, str):
354
+ # Escape postgresql cast parameters after SQLAlchemy binds
355
+ # (e.g., :param::text)
356
+ query = escape_postgresql_cast_parameters(query)
357
+
352
358
  if pre_bind_params is not None:
353
359
  if not isinstance(query, SQL):
354
360
  query = SQL(query)
@@ -360,9 +366,19 @@ def _render_query_text(connectable, query, params):
360
366
 
361
367
  sql_text = str(query)
362
368
  if isinstance(query, str):
363
- sql_text = format(query, strip_comments=True).strip()
369
+ sql_text = format(sql_text, strip_comments=True).strip()
370
+
371
+ return query, sql_text, params
364
372
 
365
- return query, sql_text
373
+
374
+ def escape_postgresql_cast_parameters(sql_text):
375
+ regex = r":([\w]+)::([a-zA-Z]+)"
376
+ for res in re.findall(regex, sql_text):
377
+ param, cast_type = res
378
+ sql_text = sql_text.replace(
379
+ f":{param}::{cast_type}", f":{param}\:\:{cast_type}"
380
+ )
381
+ return sql_text
366
382
 
367
383
 
368
384
  def _execute_one(
@@ -377,7 +393,7 @@ def _execute_one(
377
393
  ):
378
394
  params = result.params
379
395
 
380
- query, sql_text = _render_query_text(connectable, result.query, params)
396
+ query, sql_text, _params = _render_query_text(connectable, result.query, params)
381
397
  if has_server_binds is None:
382
398
  has_server_binds = infer_has_server_binds(sql_text)
383
399
 
@@ -402,11 +418,11 @@ def _execute_one(
402
418
  log.debug("Executing SQL: \n %s", query)
403
419
  if has_server_binds:
404
420
  conn = _get_connection(connectable)
405
- res = conn.exec_driver_sql(query, params)
421
+ res = conn.exec_driver_sql(query, _params)
406
422
  else:
407
423
  if not isinstance(query, TextClause):
408
424
  query = text(query)
409
- res = connectable.execute(query, params)
425
+ res = connectable.execute(query, _params)
410
426
 
411
427
  yield res
412
428
 
@@ -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.0"
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
  ]