dycw-utilities 0.150.12__py3-none-any.whl → 0.150.14__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.
- {dycw_utilities-0.150.12.dist-info → dycw_utilities-0.150.14.dist-info}/METADATA +1 -1
- {dycw_utilities-0.150.12.dist-info → dycw_utilities-0.150.14.dist-info}/RECORD +7 -7
- utilities/__init__.py +1 -1
- utilities/sqlalchemy.py +33 -13
- {dycw_utilities-0.150.12.dist-info → dycw_utilities-0.150.14.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.150.12.dist-info → dycw_utilities-0.150.14.dist-info}/entry_points.txt +0 -0
- {dycw_utilities-0.150.12.dist-info → dycw_utilities-0.150.14.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=bT5xIpzoPlIVlbwQr1301PGD5JrP7I8LD4yJhFWChD4,61
|
2
2
|
utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
|
3
3
|
utilities/asyncio.py,sha256=2m2a2C-Qgc6OHTTHL332-t66A7xDITt_SORT7a1DJWo,16792
|
4
4
|
utilities/atomicwrites.py,sha256=xcOWenTBRS0oat3kg7Sqe51AohNThMQ2ixPL7QCG8hw,5795
|
@@ -66,7 +66,7 @@ utilities/sentinel.py,sha256=3jIwgpMekWgDAxPDA_hXMP2St43cPhciKN3LWiZ7kv0,1248
|
|
66
66
|
utilities/shelve.py,sha256=4OzjQI6kGuUbJciqf535rwnao-_IBv66gsT6tRGiUt0,759
|
67
67
|
utilities/slack_sdk.py,sha256=ppFBvKgfg5IRWiIoKPtpTyzBtBF4XmwEvU3I5wLJikM,2140
|
68
68
|
utilities/socket.py,sha256=K77vfREvzoVTrpYKo6MZakol0EYu2q1sWJnnZqL0So0,118
|
69
|
-
utilities/sqlalchemy.py,sha256=
|
69
|
+
utilities/sqlalchemy.py,sha256=QbCFKefrkkqL23iDF5WdOKRfISMj6c-SyrI3rvBATE4,39641
|
70
70
|
utilities/sqlalchemy_polars.py,sha256=18AoEbeNJUKF3-5hroNy9J5LQwS_QJAXbMfKc9sChtk,14250
|
71
71
|
utilities/statsmodels.py,sha256=koyiBHvpMcSiBfh99wFUfSggLNx7cuAw3rwyfAhoKpQ,3410
|
72
72
|
utilities/string.py,sha256=MB0X6UPTUc06JdAdj-PctZ238IXeCjE5dAJibNw6ZrU,587
|
@@ -89,8 +89,8 @@ utilities/zoneinfo.py,sha256=oEH-nL3t4h9uawyZqWDtNtDAl6M-CLpLYGI_nI6DulM,1971
|
|
89
89
|
utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
90
90
|
utilities/pytest_plugins/pytest_randomly.py,sha256=NXzCcGKbpgYouz5yehKb4jmxmi2SexKKpgF4M65bi10,414
|
91
91
|
utilities/pytest_plugins/pytest_regressions.py,sha256=Iwhfv_OJH7UCPZCfoh7ugZ2Xjqjil-BBBsOb8sDwiGI,1471
|
92
|
-
dycw_utilities-0.150.
|
93
|
-
dycw_utilities-0.150.
|
94
|
-
dycw_utilities-0.150.
|
95
|
-
dycw_utilities-0.150.
|
96
|
-
dycw_utilities-0.150.
|
92
|
+
dycw_utilities-0.150.14.dist-info/METADATA,sha256=qROpqych2gxzNw7cNMeSkurdfRUA6V1ivBjBeNA9JUk,1697
|
93
|
+
dycw_utilities-0.150.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
94
|
+
dycw_utilities-0.150.14.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
|
95
|
+
dycw_utilities-0.150.14.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
96
|
+
dycw_utilities-0.150.14.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/sqlalchemy.py
CHANGED
@@ -97,12 +97,17 @@ from utilities.iterables import (
|
|
97
97
|
)
|
98
98
|
from utilities.reprlib import get_repr
|
99
99
|
from utilities.text import secret_str, snake_case
|
100
|
-
from utilities.types import
|
100
|
+
from utilities.types import (
|
101
|
+
Delta,
|
102
|
+
MaybeIterable,
|
103
|
+
MaybeType,
|
104
|
+
StrMapping,
|
105
|
+
TupleOrStrMapping,
|
106
|
+
)
|
101
107
|
|
102
108
|
if TYPE_CHECKING:
|
103
109
|
from enum import Enum, StrEnum
|
104
110
|
|
105
|
-
from whenever import TimeDelta
|
106
111
|
|
107
112
|
type EngineOrConnectionOrAsync = Engine | Connection | AsyncEngine | AsyncConnection
|
108
113
|
type Dialect = Literal["mssql", "mysql", "oracle", "postgresql", "sqlite"]
|
@@ -115,15 +120,29 @@ CHUNK_SIZE_FRAC = 0.8
|
|
115
120
|
##
|
116
121
|
|
117
122
|
|
123
|
+
_SELECT = text("SELECT 1")
|
124
|
+
|
125
|
+
|
118
126
|
def check_connect(engine: Engine, /) -> bool:
|
119
127
|
"""Check if an engine can connect."""
|
120
128
|
try:
|
121
129
|
with engine.connect() as conn:
|
122
|
-
return bool(conn.execute(
|
130
|
+
return bool(conn.execute(_SELECT).scalar_one())
|
123
131
|
except (OperationalError, ProgrammingError):
|
124
132
|
return False
|
125
133
|
|
126
134
|
|
135
|
+
async def check_connect_async(
|
136
|
+
engine: AsyncEngine, /, *, timeout: Delta | None = None
|
137
|
+
) -> bool:
|
138
|
+
"""Check if an engine can connect."""
|
139
|
+
try:
|
140
|
+
async with timeout_td(timeout), engine.connect() as conn:
|
141
|
+
return bool((await conn.execute(_SELECT)).scalar_one())
|
142
|
+
except (OperationalError, ProgrammingError, TimeoutError):
|
143
|
+
return False
|
144
|
+
|
145
|
+
|
127
146
|
##
|
128
147
|
|
129
148
|
|
@@ -131,7 +150,7 @@ async def check_engine(
|
|
131
150
|
engine: AsyncEngine,
|
132
151
|
/,
|
133
152
|
*,
|
134
|
-
timeout:
|
153
|
+
timeout: Delta | None = None,
|
135
154
|
error: type[Exception] = TimeoutError,
|
136
155
|
num_tables: int | tuple[int, float] | None = None,
|
137
156
|
) -> None:
|
@@ -304,7 +323,7 @@ async def ensure_tables_created(
|
|
304
323
|
engine: AsyncEngine,
|
305
324
|
/,
|
306
325
|
*tables_or_orms: TableOrORMInstOrClass,
|
307
|
-
timeout:
|
326
|
+
timeout: Delta | None = None,
|
308
327
|
error: type[Exception] = TimeoutError,
|
309
328
|
) -> None:
|
310
329
|
"""Ensure a table/set of tables is/are created."""
|
@@ -333,7 +352,7 @@ async def ensure_tables_created(
|
|
333
352
|
async def ensure_tables_dropped(
|
334
353
|
engine: AsyncEngine,
|
335
354
|
*tables_or_orms: TableOrORMInstOrClass,
|
336
|
-
timeout:
|
355
|
+
timeout: Delta | None = None,
|
337
356
|
error: type[Exception] = TimeoutError,
|
338
357
|
) -> None:
|
339
358
|
"""Ensure a table/set of tables is/are dropped."""
|
@@ -563,9 +582,9 @@ async def insert_items(
|
|
563
582
|
snake: bool = False,
|
564
583
|
chunk_size_frac: float = CHUNK_SIZE_FRAC,
|
565
584
|
assume_tables_exist: bool = False,
|
566
|
-
timeout_create:
|
585
|
+
timeout_create: Delta | None = None,
|
567
586
|
error_create: type[Exception] = TimeoutError,
|
568
|
-
timeout_insert:
|
587
|
+
timeout_insert: Delta | None = None,
|
569
588
|
error_insert: type[Exception] = TimeoutError,
|
570
589
|
) -> None:
|
571
590
|
"""Insert a set of items into a database.
|
@@ -664,9 +683,9 @@ async def migrate_data(
|
|
664
683
|
table_or_orm_to: TableOrORMInstOrClass | None = None,
|
665
684
|
chunk_size_frac: float = CHUNK_SIZE_FRAC,
|
666
685
|
assume_tables_exist: bool = False,
|
667
|
-
timeout_create:
|
686
|
+
timeout_create: Delta | None = None,
|
668
687
|
error_create: type[Exception] = TimeoutError,
|
669
|
-
timeout_insert:
|
688
|
+
timeout_insert: Delta | None = None,
|
670
689
|
error_insert: type[Exception] = TimeoutError,
|
671
690
|
) -> None:
|
672
691
|
"""Migrate the contents of a table from one database to another."""
|
@@ -800,9 +819,9 @@ async def upsert_items(
|
|
800
819
|
selected_or_all: _SelectedOrAll = "selected",
|
801
820
|
chunk_size_frac: float = CHUNK_SIZE_FRAC,
|
802
821
|
assume_tables_exist: bool = False,
|
803
|
-
timeout_create:
|
822
|
+
timeout_create: Delta | None = None,
|
804
823
|
error_create: type[Exception] = TimeoutError,
|
805
|
-
timeout_insert:
|
824
|
+
timeout_insert: Delta | None = None,
|
806
825
|
error_insert: type[Exception] = TimeoutError,
|
807
826
|
) -> None:
|
808
827
|
"""Upsert a set of items into a database.
|
@@ -922,7 +941,7 @@ async def yield_connection(
|
|
922
941
|
engine: AsyncEngine,
|
923
942
|
/,
|
924
943
|
*,
|
925
|
-
timeout:
|
944
|
+
timeout: Delta | None = None,
|
926
945
|
error: MaybeType[BaseException] = TimeoutError,
|
927
946
|
) -> AsyncIterator[AsyncConnection]:
|
928
947
|
"""Yield an async connection."""
|
@@ -1260,6 +1279,7 @@ __all__ = [
|
|
1260
1279
|
"TablenameMixin",
|
1261
1280
|
"UpsertItemsError",
|
1262
1281
|
"check_connect",
|
1282
|
+
"check_connect_async",
|
1263
1283
|
"check_engine",
|
1264
1284
|
"columnwise_max",
|
1265
1285
|
"columnwise_min",
|
File without changes
|
File without changes
|
File without changes
|