dinao 2.2.0.dev174__tar.gz → 2.2.0.dev178__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.
- {dinao-2.2.0.dev174/dinao.egg-info → dinao-2.2.0.dev178}/PKG-INFO +1 -1
- dinao-2.2.0.dev178/dinao/__version__.py +2 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/__init__.py +3 -1
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/asyncpg.py +1 -1
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/binders/async_.py +14 -1
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/binders/base.py +5 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/binders/sync.py +14 -1
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/errors.py +6 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178/dinao.egg-info}/PKG-INFO +1 -1
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/pyproject.toml +3 -0
- dinao-2.2.0.dev174/dinao/__version__.py +0 -2
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/AUTHORS +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/LICENSE +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/README.md +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/__init__.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/base.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/errors.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/mariadb.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/mysql.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/__init__.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/base.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/psycopg2.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/psycopg3.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/sqlite.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/__init__.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/binders/__init__.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/mappers.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/templating.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/mung.py +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao.egg-info/SOURCES.txt +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao.egg-info/dependency_links.txt +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao.egg-info/requires.txt +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao.egg-info/top_level.txt +0 -0
- {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/setup.cfg +0 -0
|
@@ -94,9 +94,11 @@ def create_connection_pool(db_url: str) -> ConnectionPoolBase:
|
|
|
94
94
|
if mode == "async":
|
|
95
95
|
return AsyncConnectionPoolPSQLPsycopg3(db_url)
|
|
96
96
|
return ConnectionPoolPSQLPsycopg3(db_url)
|
|
97
|
-
if backend == "sqlite3"
|
|
97
|
+
if backend == "sqlite3":
|
|
98
98
|
if mode == "async":
|
|
99
99
|
raise UnsupportedBackendError("The sqlite3 backend does not support async mode")
|
|
100
|
+
if engine is not None:
|
|
101
|
+
raise UnsupportedBackendError(f"The backend+engine '{scheme}' is not supported")
|
|
100
102
|
return ConnectionPoolSQLite3(db_url)
|
|
101
103
|
if backend == "mariadb" and engine == "mariadbconnector":
|
|
102
104
|
if mode == "async":
|
|
@@ -14,7 +14,7 @@ from dinao.binding.binders.base import (
|
|
|
14
14
|
BoundTransactionBase,
|
|
15
15
|
FunctionBinderBase,
|
|
16
16
|
)
|
|
17
|
-
from dinao.binding.errors import CannotInferMappingError, NoPoolSetError, TooManyRowsError
|
|
17
|
+
from dinao.binding.errors import CannotInferMappingError, IncompatibleBindingError, NoPoolSetError, TooManyRowsError
|
|
18
18
|
from dinao.binding.mappers import ASYNC_GENERATOR_GENERICS, GENERATOR_GENERICS
|
|
19
19
|
|
|
20
20
|
|
|
@@ -26,6 +26,19 @@ class AsyncFunctionBinder(FunctionBinderBase):
|
|
|
26
26
|
super().__init__()
|
|
27
27
|
self._context_store = contextvars.ContextVar("active_cnx", default=None)
|
|
28
28
|
|
|
29
|
+
def _validate_function(self, func):
|
|
30
|
+
"""Validate that the function is a coroutine.
|
|
31
|
+
|
|
32
|
+
:raises IncompatibleBindingError
|
|
33
|
+
"""
|
|
34
|
+
if not inspect.iscoroutinefunction(func):
|
|
35
|
+
error = (
|
|
36
|
+
f"AsyncFunctionBinder cannot bind sync function"
|
|
37
|
+
f" '{func.__name__}'; use FunctionBinder"
|
|
38
|
+
f" for sync functions"
|
|
39
|
+
)
|
|
40
|
+
self._suppressed_raise(IncompatibleBindingError(error))
|
|
41
|
+
|
|
29
42
|
def _validate_pool(self, pool):
|
|
30
43
|
"""Validate that the pool is an async pool.
|
|
31
44
|
|
|
@@ -69,6 +69,10 @@ class FunctionBinderBase(ABC):
|
|
|
69
69
|
"""Validate a pool before assignment. Override in subclasses for type checking."""
|
|
70
70
|
pass
|
|
71
71
|
|
|
72
|
+
def _validate_function(self, func):
|
|
73
|
+
"""Validate a function before binding. Override in subclasses for type checking."""
|
|
74
|
+
pass # pragma: no cover
|
|
75
|
+
|
|
72
76
|
@property
|
|
73
77
|
def pool(self) -> ConnectionPoolBase:
|
|
74
78
|
"""Get the connection pool used by this binder."""
|
|
@@ -112,6 +116,7 @@ class BoundFunction(ABC):
|
|
|
112
116
|
"""Abstract class for common behaviors between bound functions."""
|
|
113
117
|
|
|
114
118
|
def __init__(self, binder: FunctionBinderBase, func: callable): # noqa: D107
|
|
119
|
+
binder._validate_function(func)
|
|
115
120
|
self._binder = binder
|
|
116
121
|
self._func = func
|
|
117
122
|
self._sig = inspect.signature(func)
|
|
@@ -14,7 +14,7 @@ from dinao.binding.binders.base import (
|
|
|
14
14
|
BoundTransactionBase,
|
|
15
15
|
FunctionBinderBase,
|
|
16
16
|
)
|
|
17
|
-
from dinao.binding.errors import NoPoolSetError, TooManyRowsError
|
|
17
|
+
from dinao.binding.errors import IncompatibleBindingError, NoPoolSetError, TooManyRowsError
|
|
18
18
|
from dinao.binding.mappers import GENERATOR_GENERICS
|
|
19
19
|
|
|
20
20
|
|
|
@@ -26,6 +26,19 @@ class FunctionBinder(FunctionBinderBase):
|
|
|
26
26
|
super().__init__()
|
|
27
27
|
self._context_store = threading.local()
|
|
28
28
|
|
|
29
|
+
def _validate_function(self, func):
|
|
30
|
+
"""Validate that the function is not a coroutine.
|
|
31
|
+
|
|
32
|
+
:raises IncompatibleBindingError
|
|
33
|
+
"""
|
|
34
|
+
if inspect.iscoroutinefunction(func):
|
|
35
|
+
error = (
|
|
36
|
+
f"FunctionBinder cannot bind async function"
|
|
37
|
+
f" '{func.__name__}'; use AsyncFunctionBinder"
|
|
38
|
+
f" for async functions"
|
|
39
|
+
)
|
|
40
|
+
self._suppressed_raise(IncompatibleBindingError(error))
|
|
41
|
+
|
|
29
42
|
def execute(self, sql: str) -> callable:
|
|
30
43
|
"""Binds a given function to a given SQL template.
|
|
31
44
|
|
|
@@ -33,6 +33,12 @@ class TemplateError(BindingError):
|
|
|
33
33
|
pass
|
|
34
34
|
|
|
35
35
|
|
|
36
|
+
class IncompatibleBindingError(BindingError):
|
|
37
|
+
"""Raised when a function's coroutine type is incompatible with its binder."""
|
|
38
|
+
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
|
|
36
42
|
class FunctionAlreadyBoundError(BindingError):
|
|
37
43
|
"""Raised when a function is bound more than once to a query, execution, or transaction."""
|
|
38
44
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|