nlbone 0.1.28__py3-none-any.whl → 0.1.29__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.
- nlbone/adapters/db/__init__.py +1 -1
- nlbone/adapters/db/sqlalchemy/__init__.py +2 -1
- nlbone/adapters/db/sqlalchemy/base.py +5 -0
- nlbone/adapters/db/sqlalchemy/engine.py +2 -1
- nlbone/adapters/db/sqlalchemy/schema.py +29 -0
- nlbone/interfaces/cli/init_db.py +17 -0
- {nlbone-0.1.28.dist-info → nlbone-0.1.29.dist-info}/METADATA +1 -1
- {nlbone-0.1.28.dist-info → nlbone-0.1.29.dist-info}/RECORD +10 -7
- {nlbone-0.1.28.dist-info → nlbone-0.1.29.dist-info}/WHEEL +0 -0
- {nlbone-0.1.28.dist-info → nlbone-0.1.29.dist-info}/licenses/LICENSE +0 -0
nlbone/adapters/db/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
from .sqlalchemy.engine import init_async_engine, async_session, async_ping, init_sync_engine, sync_session, sync_ping
|
|
2
|
-
from .sqlalchemy
|
|
2
|
+
from .sqlalchemy import *
|
|
@@ -112,7 +112,8 @@ def sync_session() -> Generator[Session, None, None]:
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
def sync_ping() -> None:
|
|
115
|
-
"""Health check
|
|
115
|
+
"""Health check for sync."""
|
|
116
116
|
eng = init_sync_engine()
|
|
117
117
|
with eng.connect() as conn:
|
|
118
118
|
conn.execute(text("SELECT 1"))
|
|
119
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
import importlib
|
|
3
|
+
from typing import Sequence
|
|
4
|
+
|
|
5
|
+
from nlbone.adapters.db.sqlalchemy.base import Base
|
|
6
|
+
from nlbone.adapters.db.sqlalchemy.engine import init_async_engine, init_sync_engine
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
DEFAULT_MODEL_MODULES: Sequence[str] = (
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
def import_model_modules(modules: Sequence[str] | None = None) -> None:
|
|
13
|
+
for m in (modules or DEFAULT_MODEL_MODULES):
|
|
14
|
+
importlib.import_module(m)
|
|
15
|
+
|
|
16
|
+
# --------- Async (SQLAlchemy 2.x) ----------
|
|
17
|
+
async def init_db_async(model_modules: Sequence[str] | None = None) -> None:
|
|
18
|
+
"""Create tables using AsyncEngine (dev/test). Prefer Alembic in prod."""
|
|
19
|
+
import_model_modules(model_modules)
|
|
20
|
+
engine = init_async_engine()
|
|
21
|
+
async with engine.begin() as conn:
|
|
22
|
+
await conn.run_sync(Base.metadata.create_all)
|
|
23
|
+
|
|
24
|
+
# --------- Sync ----------
|
|
25
|
+
def init_db_sync(model_modules: Sequence[str] | None = None) -> None:
|
|
26
|
+
"""Create tables using Sync Engine (dev/test). Prefer Alembic in prod."""
|
|
27
|
+
import_model_modules(model_modules)
|
|
28
|
+
engine = init_sync_engine()
|
|
29
|
+
Base.metadata.create_all(bind=engine)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import anyio
|
|
3
|
+
|
|
4
|
+
from nlbone.adapters.db.sqlalchemy.schema import init_db_async, init_db_sync
|
|
5
|
+
|
|
6
|
+
def main() -> None:
|
|
7
|
+
parser = argparse.ArgumentParser(description="Initialize database schema (create_all).")
|
|
8
|
+
parser.add_argument("--async", dest="use_async", action="store_true", help="Use AsyncEngine")
|
|
9
|
+
args = parser.parse_args()
|
|
10
|
+
|
|
11
|
+
if args.use_async:
|
|
12
|
+
anyio.run(init_db_async)
|
|
13
|
+
else:
|
|
14
|
+
init_db_sync()
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
main()
|
|
@@ -3,12 +3,14 @@ nlbone/types.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
3
3
|
nlbone/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
nlbone/adapters/auth/__init__.py,sha256=Eh9kWjY1I8vi17gK0oOzBLJwJX_GFuUcJIN7cLU6lJg,41
|
|
5
5
|
nlbone/adapters/auth/keycloak.py,sha256=W5siUCFtOANDHZH9eDHsXIQ5cC6BDTk_Zv5mh3STSGo,2416
|
|
6
|
-
nlbone/adapters/db/__init__.py,sha256=
|
|
6
|
+
nlbone/adapters/db/__init__.py,sha256=aHur2GuykZd26RpEmIbkAfflkksZuKWAlYLJMIYotQE,144
|
|
7
7
|
nlbone/adapters/db/memory.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
nlbone/adapters/db/postgres.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
nlbone/adapters/db/query_builder.py,sha256=qL2Ppe39X7pnKpHfWZZanxfEKqQW3grZv5bQLS52mfU,6066
|
|
10
|
-
nlbone/adapters/db/sqlalchemy/__init__.py,sha256=
|
|
11
|
-
nlbone/adapters/db/sqlalchemy/
|
|
10
|
+
nlbone/adapters/db/sqlalchemy/__init__.py,sha256=REK4P8SF6kvDNYgkZIbSowhHPivyFVnMCYGfYT1dlxk,158
|
|
11
|
+
nlbone/adapters/db/sqlalchemy/base.py,sha256=-5FnCMKETJ2xykhViHQuNBdbRMaxuieuatgiEl4Lllw,73
|
|
12
|
+
nlbone/adapters/db/sqlalchemy/engine.py,sha256=m3nVY7KU12ksM3vK9fEgYEobrz9L8hfsgjI8cSNtBMY,3030
|
|
13
|
+
nlbone/adapters/db/sqlalchemy/schema.py,sha256=iiE42UT-DJh-ohezLFBWTBFN5WtrfZdtKToQDNLvoOs,1044
|
|
12
14
|
nlbone/adapters/db/sqlalchemy/query/__init__.py,sha256=9SFkoNkklaji6kZt_Nl6X6vqMFE92GiqW36Zezr5PuE,129
|
|
13
15
|
nlbone/adapters/db/sqlalchemy/query/builder.py,sha256=AzUX2MlfrMGY-EITzVJoq9naM5sTL9h9yzI7cCeEBRk,886
|
|
14
16
|
nlbone/adapters/db/sqlalchemy/query/coercion.py,sha256=uYClfEuew_W4r-vbwj2c5MVpayejhpOMl6h4iUrMotQ,2142
|
|
@@ -46,12 +48,13 @@ nlbone/interfaces/api/schemas.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
|
46
48
|
nlbone/interfaces/api/pagination/__init__.py,sha256=fdTqy5efdYIcUWbK1mVPQMieGd3HV1lZ8vmIhhsuUKs,58
|
|
47
49
|
nlbone/interfaces/api/pagination/offset_base.py,sha256=W0SJ0rHLMIqoyiPEAjnoKqY57LBXEyT5J-_5bS8r-NY,4535
|
|
48
50
|
nlbone/interfaces/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
51
|
+
nlbone/interfaces/cli/init_db.py,sha256=6Q05gwcPa6ywwz3Dzi0hiV8bycg0zU_3eWGsL6VNVRk,479
|
|
49
52
|
nlbone/interfaces/cli/main.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
50
53
|
nlbone/interfaces/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
51
54
|
nlbone/interfaces/jobs/sync_tokens.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
52
55
|
nlbone/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
53
56
|
nlbone/utils/time.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
54
|
-
nlbone-0.1.
|
|
55
|
-
nlbone-0.1.
|
|
56
|
-
nlbone-0.1.
|
|
57
|
-
nlbone-0.1.
|
|
57
|
+
nlbone-0.1.29.dist-info/METADATA,sha256=px5zji1xoB5XO5m8WkVjgoBF7bZVtU1UQxkH-Fnx6zc,2256
|
|
58
|
+
nlbone-0.1.29.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
59
|
+
nlbone-0.1.29.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
60
|
+
nlbone-0.1.29.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|