forked from retoor/devplacepy
update
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
from typing import Any
|
||||
|
||||
import devplacepy.database as db_module
|
||||
|
||||
from devplacepy_services.base.db_codec import decode_arg, encode_result, is_write
|
||||
|
||||
|
||||
def build_registry() -> dict[str, Any]:
|
||||
registry: dict[str, Any] = {}
|
||||
for name in db_module.__all__:
|
||||
target = getattr(db_module, name, None)
|
||||
if target is None or not callable(target):
|
||||
continue
|
||||
if inspect.isclass(target):
|
||||
continue
|
||||
registry[name] = target
|
||||
return registry
|
||||
|
||||
|
||||
REGISTRY = build_registry()
|
||||
|
||||
|
||||
_encode_result = encode_result
|
||||
|
||||
|
||||
def run_with_db(db_conn, fn, args, kwargs):
|
||||
from devplacepy_services.database.db_patch import use_db, reset_db
|
||||
|
||||
token = use_db(db_conn)
|
||||
try:
|
||||
decoded_args = decode_arg(args)
|
||||
decoded_kwargs = decode_arg(kwargs)
|
||||
return fn(*decoded_args, **decoded_kwargs)
|
||||
finally:
|
||||
reset_db(token)
|
||||
Reference in New Issue
Block a user