tracktolib 0.55.0__py3-none-any.whl → 0.57.0__py3-none-any.whl

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.
tracktolib/pg_sync.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from pathlib import Path
2
- from typing import Iterable, Any, overload, Literal, cast, Optional
2
+ from typing import Iterable, Any, overload, Literal, cast, Optional, Mapping, Sequence
3
3
 
4
4
  from typing_extensions import LiteralString
5
5
 
@@ -14,7 +14,6 @@ except ImportError:
14
14
 
15
15
  from .pg_utils import get_tmp_table_query
16
16
 
17
-
18
17
  __all__ = (
19
18
  "clean_tables",
20
19
  "drop_db",
@@ -68,36 +67,44 @@ def fetch_one(engine: Connection, query: Query, *args, required: bool = False) -
68
67
  return _data
69
68
 
70
69
 
71
- def _parse_value(v):
70
+ def _parse_value(v: Any) -> Any:
72
71
  if isinstance(v, dict):
73
72
  return Json(v)
74
73
  return v
75
74
 
76
75
 
77
- def get_insert_data(table: LiteralString, data: list[dict]) -> tuple[LiteralString, list[tuple[Any, ...]]]:
76
+ def get_insert_data(
77
+ table: LiteralString, data: Sequence[Mapping[str, Any]]
78
+ ) -> tuple[LiteralString, list[tuple[Any, ...]]]:
78
79
  keys = data[0].keys()
79
80
  _values = ",".join("%s" for _ in range(0, len(keys)))
80
- query = f"INSERT INTO {table} as t ({','.join(keys)}) VALUES ({_values})"
81
+ query = cast(LiteralString, f"INSERT INTO {table} as t ({','.join(keys)}) VALUES ({_values})")
81
82
  return query, [tuple(_parse_value(_x) for _x in x.values()) for x in data]
82
83
 
83
84
 
84
- def insert_many(engine: Connection, table: LiteralString, data: list[dict]):
85
+ def insert_many(engine: Connection | Cursor, table: LiteralString, data: Sequence[Mapping[str, Any]]):
85
86
  query, _data = get_insert_data(table, data)
86
- with engine.cursor() as cur:
87
- _ = cur.executemany(query, _data)
88
- engine.commit()
87
+ if isinstance(engine, Connection):
88
+ with engine.cursor() as cur:
89
+ _ = cur.executemany(query, _data)
90
+ engine.commit()
91
+ else:
92
+ # If we are using a cursor, we can use executemany directly
93
+ _ = engine.executemany(query, _data)
89
94
 
90
95
 
91
96
  @overload
92
- def insert_one(engine: Connection, table: LiteralString, data: dict, returning: None = None) -> None: ...
97
+ def insert_one(engine: Connection, table: LiteralString, data: Mapping[str, Any], returning: None = None) -> None: ...
93
98
 
94
99
 
95
100
  @overload
96
- def insert_one(engine: Connection, table: LiteralString, data: dict, returning: list[LiteralString]) -> dict: ...
101
+ def insert_one(
102
+ engine: Connection, table: LiteralString, data: Mapping[str, Any], returning: list[LiteralString]
103
+ ) -> dict: ...
97
104
 
98
105
 
99
106
  def insert_one(
100
- engine: Connection, table: LiteralString, data: dict, returning: list[LiteralString] | None = None
107
+ engine: Connection, table: LiteralString, data: Mapping[str, Any], returning: list[LiteralString] | None = None
101
108
  ) -> dict | None:
102
109
  query, _data = get_insert_data(table, [data])
103
110
  _is_returning = False
@@ -138,11 +145,11 @@ def clean_tables(engine: Connection, tables: Iterable[LiteralString], reset_seq:
138
145
 
139
146
  def get_tables(engine: Connection, schemas: list[str], ignored_tables: Iterable[str] | None = None):
140
147
  table_query = """
141
- SELECT CONCAT_WS('.', schemaname, tablename) AS table
142
- FROM pg_catalog.pg_tables
143
- WHERE schemaname = ANY(%s)
144
- ORDER BY schemaname, tablename
145
- """
148
+ SELECT CONCAT_WS('.', schemaname, tablename) AS table
149
+ FROM pg_catalog.pg_tables
150
+ WHERE schemaname = ANY (%s)
151
+ ORDER BY schemaname, tablename \
152
+ """
146
153
  resp = fetch_all(engine, table_query, schemas)
147
154
 
148
155
  # Foreign keys
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: tracktolib
3
- Version: 0.55.0
3
+ Version: 0.57.0
4
4
  Summary: Utility library for python
5
5
  License: MIT
6
6
  Keywords: utility
@@ -5,14 +5,14 @@ tracktolib/logs.py,sha256=xgfRDnviZPr9qinSOgab8neIWPv9Rj2xzDHnIBvWQcU,2201
5
5
  tracktolib/pg/__init__.py,sha256=j67e3B3gBbCHLD20QBybptmNdbbVMzNhZE6XjIPuKVo,349
6
6
  tracktolib/pg/query.py,sha256=MBYOTL9aLnYRBhaLy8-P6uGNXOmyluejNyUdt3Gfx5M,14504
7
7
  tracktolib/pg/utils.py,sha256=cL24KEt4SWJQ7LJPzaO3c8Xg0ZLmjhn22DtTWg86nwc,6324
8
- tracktolib/pg_sync.py,sha256=QSvt5C92UTcc6EhtjrdUe6eDs7m9mIyBYclzQo9wKGQ,5959
8
+ tracktolib/pg_sync.py,sha256=snfYtj5ICWa2C_QWRFKZecHPgVx1yhofhGst0e6CGxs,6351
9
9
  tracktolib/pg_utils.py,sha256=VXPpy1jGq6aCgTlfFJDIrq6JDujR83JN5ZRiCi8Lx4E,2582
10
10
  tracktolib/s3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  tracktolib/s3/minio.py,sha256=wMEjkSes9Fp39fD17IctALpD6zB2xwDRQEmO7Vzan3g,1387
12
12
  tracktolib/s3/s3.py,sha256=0HbSAPoaup5-W4LK54zRCjrQ5mr8OWR-N9WjW99Q4aw,5937
13
13
  tracktolib/tests.py,sha256=gKE--epQjgMZGXc5ydbl4zjOdmwztJS42UMV0p4hXEA,399
14
14
  tracktolib/utils.py,sha256=ysTBF9V35fVXQVBPk0kfE_84SGRxzrayqmg9RbtoJq4,5761
15
- tracktolib-0.55.0.dist-info/LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
16
- tracktolib-0.55.0.dist-info/METADATA,sha256=MRCRmul0rCAPnWJe3HZJH28llOPQowxPEVXc6q4JGHI,3704
17
- tracktolib-0.55.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
18
- tracktolib-0.55.0.dist-info/RECORD,,
15
+ tracktolib-0.57.0.dist-info/LICENSE,sha256=uUanH0X7SeZEPdsRTHegMSMTiIHMurt9H0jSwEwKE1Y,1081
16
+ tracktolib-0.57.0.dist-info/METADATA,sha256=88PzWoI3eX1blMUAWEHUzuYFPWndH7O0sCPr9_ScSNE,3704
17
+ tracktolib-0.57.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
18
+ tracktolib-0.57.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.2
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any