tigrbl 0.4.5.dev4__py3-none-any.whl → 0.4.5.dev8__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.
- tigrbl/__init__.py +96 -7
- tigrbl/engine_session/__init__.py +28 -0
- tigrbl/engine_session/base.py +7 -0
- tigrbl/engine_session/spec.py +23 -0
- tigrbl/factories/__init__.py +63 -9
- tigrbl/factories/column.py +17 -94
- tigrbl/factories/engine.py +51 -2
- tigrbl/factories/op.py +2 -13
- tigrbl/factories/router.py +1 -48
- tigrbl/factories/table.py +17 -57
- tigrbl/session/__init__.py +24 -3
- tigrbl/session/base.py +15 -2
- tigrbl/session/spec.py +13 -2
- tigrbl/system/docs/openapi/helpers.py +31 -221
- tigrbl/system/docs/openapi/schema.py +3 -231
- tigrbl/system/docs/openrpc.py +2 -337
- tigrbl/utils/schema.py +10 -5
- {tigrbl-0.4.5.dev4.dist-info → tigrbl-0.4.5.dev8.dist-info}/METADATA +22 -13
- {tigrbl-0.4.5.dev4.dist-info → tigrbl-0.4.5.dev8.dist-info}/RECORD +23 -20
- {tigrbl-0.4.5.dev4.dist-info → tigrbl-0.4.5.dev8.dist-info}/WHEEL +1 -1
- {tigrbl-0.4.5.dev4.dist-info → tigrbl-0.4.5.dev8.dist-info}/entry_points.txt +0 -0
- {tigrbl-0.4.5.dev4.dist-info → tigrbl-0.4.5.dev8.dist-info}/licenses/LICENSE +0 -0
- {tigrbl-0.4.5.dev4.dist-info → tigrbl-0.4.5.dev8.dist-info}/licenses/NOTICE +0 -0
tigrbl/__init__.py
CHANGED
|
@@ -100,6 +100,7 @@ from tigrbl_concrete._concrete import ( # noqa: E402
|
|
|
100
100
|
Column,
|
|
101
101
|
CORSMiddleware,
|
|
102
102
|
CrudTable,
|
|
103
|
+
EngineSession,
|
|
103
104
|
EventStreamTable,
|
|
104
105
|
EventStreamResponse,
|
|
105
106
|
FileResponse,
|
|
@@ -185,7 +186,39 @@ from tigrbl_concrete._decorators.middlewares import ( # noqa: E402
|
|
|
185
186
|
middleware as middleware,
|
|
186
187
|
middlewares as middlewares,
|
|
187
188
|
)
|
|
188
|
-
from tigrbl.factories.op import op # noqa: E402
|
|
189
|
+
from tigrbl.factories.op import makeOp, op # noqa: E402
|
|
190
|
+
from tigrbl.factories.table import ( # noqa: E402
|
|
191
|
+
activateTableSpec,
|
|
192
|
+
activateTableSpecs,
|
|
193
|
+
defineTableSpec,
|
|
194
|
+
deriveTableSpec,
|
|
195
|
+
provideTableSpec,
|
|
196
|
+
)
|
|
197
|
+
from tigrbl_concrete.records import ( # noqa: E402
|
|
198
|
+
clear_table_records,
|
|
199
|
+
clear_records,
|
|
200
|
+
create_table_record,
|
|
201
|
+
create_record,
|
|
202
|
+
database_from_context,
|
|
203
|
+
delete_table_record,
|
|
204
|
+
delete_record,
|
|
205
|
+
field,
|
|
206
|
+
field_value,
|
|
207
|
+
first_table_record,
|
|
208
|
+
first_record,
|
|
209
|
+
invoke_table_operation,
|
|
210
|
+
list_table_records,
|
|
211
|
+
list_records,
|
|
212
|
+
maybe_await,
|
|
213
|
+
normalize_items,
|
|
214
|
+
payload_from_context,
|
|
215
|
+
provideTableHandler,
|
|
216
|
+
read_table_record,
|
|
217
|
+
read_record,
|
|
218
|
+
record_identifier,
|
|
219
|
+
update_table_record,
|
|
220
|
+
update_record,
|
|
221
|
+
)
|
|
189
222
|
from tigrbl.schema import _build_list_params, _build_schema, get_schema # noqa: E402
|
|
190
223
|
from tigrbl.ddl import bootstrap_dbschema, ensure_schemas, register_sqlite_attach # noqa: E402
|
|
191
224
|
|
|
@@ -194,6 +227,7 @@ from tigrbl_base._base import ( # noqa: E402
|
|
|
194
227
|
CrudTableBase,
|
|
195
228
|
EngineBase,
|
|
196
229
|
EngineProviderBase,
|
|
230
|
+
EngineSessionBase,
|
|
197
231
|
ForeignKeyBase,
|
|
198
232
|
HookBase,
|
|
199
233
|
RealtimeTableBase,
|
|
@@ -229,6 +263,7 @@ from tigrbl_core._spec import ( # noqa: E402
|
|
|
229
263
|
HttpRestProtocolBindingSpec,
|
|
230
264
|
HttpStreamBindingSpec,
|
|
231
265
|
IOSpec,
|
|
266
|
+
JsonRpcFramingSpec,
|
|
232
267
|
OpSpec,
|
|
233
268
|
PathKind,
|
|
234
269
|
PathSpec,
|
|
@@ -242,7 +277,8 @@ from tigrbl_core._spec import ( # noqa: E402
|
|
|
242
277
|
SchemaArg,
|
|
243
278
|
SchemaRef,
|
|
244
279
|
SchemaSpec,
|
|
245
|
-
|
|
280
|
+
EngineSessionCfg,
|
|
281
|
+
EngineSessionSpec,
|
|
246
282
|
StorageSpec,
|
|
247
283
|
StorageTransformSpec,
|
|
248
284
|
StorageTypeRef,
|
|
@@ -346,21 +382,41 @@ async def rpc_call(*args, **kwargs):
|
|
|
346
382
|
)
|
|
347
383
|
|
|
348
384
|
|
|
349
|
-
from tigrbl_core.
|
|
385
|
+
from tigrbl_core._compat import warn_legacy_engine_session_name # noqa: E402
|
|
386
|
+
from tigrbl_core._spec.engine_session_spec import ( # noqa: E402
|
|
350
387
|
readonly as _readonly_fn,
|
|
351
|
-
|
|
388
|
+
engine_session_spec as _engine_session_spec_fn,
|
|
352
389
|
tx_read_committed as _tx_read_committed_fn,
|
|
353
390
|
tx_repeatable_read as _tx_repeatable_read_fn,
|
|
354
391
|
tx_serializable as _tx_serializable_fn,
|
|
355
392
|
)
|
|
356
393
|
|
|
357
394
|
readonly = _readonly_fn
|
|
358
|
-
|
|
395
|
+
engine_session_spec = _engine_session_spec_fn
|
|
359
396
|
tx_read_committed = _tx_read_committed_fn
|
|
360
397
|
tx_repeatable_read = _tx_repeatable_read_fn
|
|
361
398
|
tx_serializable = _tx_serializable_fn
|
|
362
399
|
|
|
363
400
|
|
|
401
|
+
def __getattr__(name: str):
|
|
402
|
+
if name == "SessionSpec":
|
|
403
|
+
warn_legacy_engine_session_name("tigrbl.SessionSpec", "EngineSessionSpec")
|
|
404
|
+
return EngineSessionSpec
|
|
405
|
+
if name == "SessionCfg":
|
|
406
|
+
warn_legacy_engine_session_name("tigrbl.SessionCfg", "EngineSessionCfg")
|
|
407
|
+
return EngineSessionCfg
|
|
408
|
+
if name == "session_spec":
|
|
409
|
+
warn_legacy_engine_session_name("tigrbl.session_spec", "engine_session_spec")
|
|
410
|
+
return engine_session_spec
|
|
411
|
+
if name == "TigrblSessionBase":
|
|
412
|
+
warn_legacy_engine_session_name("tigrbl.TigrblSessionBase", "EngineSessionBase")
|
|
413
|
+
return EngineSessionBase
|
|
414
|
+
if name == "DefaultSession":
|
|
415
|
+
warn_legacy_engine_session_name("tigrbl.DefaultSession", "EngineSession")
|
|
416
|
+
return EngineSession
|
|
417
|
+
raise AttributeError(name)
|
|
418
|
+
|
|
419
|
+
|
|
364
420
|
__all__ = [
|
|
365
421
|
"specs",
|
|
366
422
|
"base",
|
|
@@ -383,8 +439,38 @@ __all__ = [
|
|
|
383
439
|
"CrudTableBase",
|
|
384
440
|
"RealtimeTableBase",
|
|
385
441
|
"RouterBase",
|
|
442
|
+
"EngineSessionBase",
|
|
386
443
|
"Op",
|
|
387
444
|
"op",
|
|
445
|
+
"makeOp",
|
|
446
|
+
"defineTableSpec",
|
|
447
|
+
"deriveTableSpec",
|
|
448
|
+
"provideTableSpec",
|
|
449
|
+
"activateTableSpec",
|
|
450
|
+
"activateTableSpecs",
|
|
451
|
+
"clear_table_records",
|
|
452
|
+
"clear_records",
|
|
453
|
+
"create_table_record",
|
|
454
|
+
"create_record",
|
|
455
|
+
"database_from_context",
|
|
456
|
+
"delete_table_record",
|
|
457
|
+
"delete_record",
|
|
458
|
+
"field",
|
|
459
|
+
"field_value",
|
|
460
|
+
"first_table_record",
|
|
461
|
+
"first_record",
|
|
462
|
+
"invoke_table_operation",
|
|
463
|
+
"list_table_records",
|
|
464
|
+
"list_records",
|
|
465
|
+
"maybe_await",
|
|
466
|
+
"normalize_items",
|
|
467
|
+
"payload_from_context",
|
|
468
|
+
"provideTableHandler",
|
|
469
|
+
"read_table_record",
|
|
470
|
+
"read_record",
|
|
471
|
+
"record_identifier",
|
|
472
|
+
"update_table_record",
|
|
473
|
+
"update_record",
|
|
388
474
|
"HTTPBasic",
|
|
389
475
|
"HTTPBearer",
|
|
390
476
|
"APIKey",
|
|
@@ -401,6 +487,7 @@ __all__ = [
|
|
|
401
487
|
"HookPhase",
|
|
402
488
|
"Exchange",
|
|
403
489
|
"Framing",
|
|
490
|
+
"JsonRpcFramingSpec",
|
|
404
491
|
"HTTPBindingSpec",
|
|
405
492
|
"HttpJsonRpcBindingSpec",
|
|
406
493
|
"HttpJsonRpcProtocolBindingSpec",
|
|
@@ -475,6 +562,7 @@ __all__ = [
|
|
|
475
562
|
"Request",
|
|
476
563
|
"UploadedFile",
|
|
477
564
|
"WebSocket",
|
|
565
|
+
"EngineSession",
|
|
478
566
|
"Response",
|
|
479
567
|
"TransportResponse",
|
|
480
568
|
"JSONResponse",
|
|
@@ -499,8 +587,9 @@ __all__ = [
|
|
|
499
587
|
"HeadersSpec",
|
|
500
588
|
"RequestSpec",
|
|
501
589
|
"SchemaSpec",
|
|
502
|
-
"
|
|
503
|
-
"
|
|
590
|
+
"EngineSessionCfg",
|
|
591
|
+
"EngineSessionSpec",
|
|
592
|
+
"engine_session_spec",
|
|
504
593
|
"tx_read_committed",
|
|
505
594
|
"tx_repeatable_read",
|
|
506
595
|
"tx_serializable",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Canonical engine database session exports."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from tigrbl_base._base import EngineSessionBase
|
|
6
|
+
from tigrbl_concrete._concrete import EngineSession, wrap_sessionmaker
|
|
7
|
+
from tigrbl_core._spec.engine_session_spec import (
|
|
8
|
+
EngineSessionCfg,
|
|
9
|
+
EngineSessionSpec,
|
|
10
|
+
engine_session_spec,
|
|
11
|
+
readonly,
|
|
12
|
+
tx_read_committed,
|
|
13
|
+
tx_repeatable_read,
|
|
14
|
+
tx_serializable,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"EngineSession",
|
|
19
|
+
"EngineSessionBase",
|
|
20
|
+
"EngineSessionCfg",
|
|
21
|
+
"EngineSessionSpec",
|
|
22
|
+
"engine_session_spec",
|
|
23
|
+
"wrap_sessionmaker",
|
|
24
|
+
"readonly",
|
|
25
|
+
"tx_read_committed",
|
|
26
|
+
"tx_repeatable_read",
|
|
27
|
+
"tx_serializable",
|
|
28
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Canonical engine session spec exports."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from tigrbl_core._spec.engine_session_spec import (
|
|
6
|
+
EngineSessionCfg,
|
|
7
|
+
EngineSessionSpec,
|
|
8
|
+
engine_session_spec,
|
|
9
|
+
readonly,
|
|
10
|
+
tx_read_committed,
|
|
11
|
+
tx_repeatable_read,
|
|
12
|
+
tx_serializable,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"EngineSessionCfg",
|
|
17
|
+
"EngineSessionSpec",
|
|
18
|
+
"engine_session_spec",
|
|
19
|
+
"readonly",
|
|
20
|
+
"tx_read_committed",
|
|
21
|
+
"tx_repeatable_read",
|
|
22
|
+
"tx_serializable",
|
|
23
|
+
]
|
tigrbl/factories/__init__.py
CHANGED
|
@@ -14,18 +14,72 @@ _MODULES = (
|
|
|
14
14
|
"table",
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
_EXPORT_MODULE = {
|
|
18
|
+
"Column": "column",
|
|
19
|
+
"ColumnSpec": "column",
|
|
20
|
+
"F": "column",
|
|
21
|
+
"IO": "column",
|
|
22
|
+
"S": "column",
|
|
23
|
+
"acol": "column",
|
|
24
|
+
"activateTableSpec": "table",
|
|
25
|
+
"activateTableSpecs": "table",
|
|
26
|
+
"as_event_stream": "responses",
|
|
27
|
+
"as_file": "responses",
|
|
28
|
+
"as_html": "responses",
|
|
29
|
+
"as_json": "responses",
|
|
30
|
+
"as_redirect": "responses",
|
|
31
|
+
"as_stream": "responses",
|
|
32
|
+
"as_text": "responses",
|
|
33
|
+
"defineAppSpec": "app",
|
|
34
|
+
"defineRouterSpec": "router",
|
|
35
|
+
"defineTableSpec": "table",
|
|
36
|
+
"deriveApp": "app",
|
|
37
|
+
"deriveRouter": "router",
|
|
38
|
+
"deriveTable": "table",
|
|
39
|
+
"deriveTableSpec": "table",
|
|
40
|
+
"engine": "engine",
|
|
41
|
+
"engine_spec": "engine",
|
|
42
|
+
"hook": "hook",
|
|
43
|
+
"hook_spec": "hook",
|
|
44
|
+
"makeColumn": "column",
|
|
45
|
+
"makeOp": "op",
|
|
46
|
+
"makeVirtualColumn": "column",
|
|
47
|
+
"mariadb": "engine",
|
|
48
|
+
"mariadb_cfg": "engine",
|
|
49
|
+
"mem": "engine",
|
|
50
|
+
"mysql": "engine",
|
|
51
|
+
"mysql_cfg": "engine",
|
|
52
|
+
"op": "op",
|
|
53
|
+
"pg": "engine",
|
|
54
|
+
"pg_cfg": "engine",
|
|
55
|
+
"pga": "engine",
|
|
56
|
+
"pgs": "engine",
|
|
57
|
+
"prov": "engine",
|
|
58
|
+
"provider_mariadb": "engine",
|
|
59
|
+
"provider_mysql": "engine",
|
|
60
|
+
"provider_postgres": "engine",
|
|
61
|
+
"provider_sqlite_file": "engine",
|
|
62
|
+
"provider_sqlite_memory": "engine",
|
|
63
|
+
"provideTableSpec": "table",
|
|
64
|
+
"schema": "schema",
|
|
65
|
+
"schema_spec": "schema",
|
|
66
|
+
"sqlite_cfg": "engine",
|
|
67
|
+
"sqlitef": "engine",
|
|
68
|
+
"vcol": "column",
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
__all__ = sorted((*_MODULES, *_EXPORT_MODULE))
|
|
18
72
|
|
|
19
73
|
|
|
20
74
|
def __getattr__(name: str):
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
75
|
+
module_name = name if name in _MODULES else _EXPORT_MODULE.get(name)
|
|
76
|
+
if module_name is None:
|
|
77
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
78
|
+
module = import_module(f"{__name__}.{module_name}")
|
|
79
|
+
value = module if name in _MODULES else getattr(module, name)
|
|
80
|
+
globals()[name] = value
|
|
81
|
+
return value
|
|
28
82
|
|
|
29
83
|
|
|
30
84
|
def __dir__() -> list[str]:
|
|
31
|
-
return sorted(__all__
|
|
85
|
+
return sorted(set(__all__) | {key for key in globals() if not key.startswith("_")})
|
tigrbl/factories/column.py
CHANGED
|
@@ -1,100 +1,23 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
from tigrbl_concrete.factories.column import (
|
|
2
|
+
Column,
|
|
3
|
+
ColumnSpec,
|
|
4
|
+
F,
|
|
5
|
+
IO,
|
|
6
|
+
S,
|
|
7
|
+
acol,
|
|
8
|
+
makeColumn,
|
|
9
|
+
makeVirtualColumn,
|
|
10
|
+
vcol,
|
|
11
|
+
)
|
|
10
12
|
|
|
11
13
|
__all__ = [
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"acol",
|
|
15
|
-
"vcol",
|
|
14
|
+
"Column",
|
|
15
|
+
"ColumnSpec",
|
|
16
16
|
"F",
|
|
17
17
|
"IO",
|
|
18
18
|
"S",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"acol",
|
|
20
|
+
"makeColumn",
|
|
21
|
+
"makeVirtualColumn",
|
|
22
|
+
"vcol",
|
|
21
23
|
]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def makeColumn(
|
|
25
|
-
*,
|
|
26
|
-
storage: S | None = None,
|
|
27
|
-
field: F | None = None,
|
|
28
|
-
io: IO | None = None,
|
|
29
|
-
default_factory: Optional[Callable[[dict], Any]] = None,
|
|
30
|
-
read_producer: Optional[Callable[[object, dict], Any]] = None,
|
|
31
|
-
spec: ColumnSpec | None = None,
|
|
32
|
-
**kw: Any,
|
|
33
|
-
) -> Column:
|
|
34
|
-
"""Return a :class:`Column` descriptor for declarative models."""
|
|
35
|
-
if spec is not None:
|
|
36
|
-
if any(
|
|
37
|
-
x is not None for x in (storage, field, io, default_factory, read_producer)
|
|
38
|
-
):
|
|
39
|
-
raise ValueError("Provide either spec or individual components, not both.")
|
|
40
|
-
if spec is None:
|
|
41
|
-
if read_producer is not None and storage is not None:
|
|
42
|
-
raise ValueError(
|
|
43
|
-
"read_producer is only valid for virtual (storage=None) columns."
|
|
44
|
-
)
|
|
45
|
-
spec = ColumnSpec(
|
|
46
|
-
storage=storage,
|
|
47
|
-
field=field,
|
|
48
|
-
io=io,
|
|
49
|
-
default_factory=default_factory,
|
|
50
|
-
read_producer=read_producer,
|
|
51
|
-
)
|
|
52
|
-
return Column(spec=spec, **kw)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def makeVirtualColumn(
|
|
56
|
-
*,
|
|
57
|
-
field: F | None = None,
|
|
58
|
-
io: IO | None = None,
|
|
59
|
-
default_factory: Optional[Callable[[dict], Any]] = None,
|
|
60
|
-
producer: Optional[Callable[[object, dict], Any]] = None,
|
|
61
|
-
read_producer: Optional[Callable[[object, dict], Any]] = None,
|
|
62
|
-
spec: ColumnSpec | None = None,
|
|
63
|
-
**kw: Any,
|
|
64
|
-
) -> Column:
|
|
65
|
-
"""Convenience for wire-only virtual columns."""
|
|
66
|
-
if spec is not None:
|
|
67
|
-
if any(x is not None for x in (field, io, default_factory)):
|
|
68
|
-
raise ValueError("Provide either spec or individual components, not both.")
|
|
69
|
-
if producer is not None and read_producer is not None:
|
|
70
|
-
raise ValueError(
|
|
71
|
-
"Provide only one of producer= or read_producer=, not both."
|
|
72
|
-
)
|
|
73
|
-
rp = read_producer or producer
|
|
74
|
-
if rp is not None:
|
|
75
|
-
spec = ColumnSpec(
|
|
76
|
-
storage=spec.storage,
|
|
77
|
-
field=spec.field,
|
|
78
|
-
io=spec.io,
|
|
79
|
-
default_factory=spec.default_factory,
|
|
80
|
-
read_producer=rp,
|
|
81
|
-
)
|
|
82
|
-
return Column(spec=spec, **kw)
|
|
83
|
-
if producer is not None and read_producer is not None:
|
|
84
|
-
raise ValueError("Provide only one of producer= or read_producer=, not both.")
|
|
85
|
-
rp = read_producer or producer
|
|
86
|
-
return Column(
|
|
87
|
-
spec=ColumnSpec(
|
|
88
|
-
storage=None,
|
|
89
|
-
field=field,
|
|
90
|
-
io=io,
|
|
91
|
-
default_factory=default_factory,
|
|
92
|
-
read_producer=rp,
|
|
93
|
-
),
|
|
94
|
-
**kw,
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# Convenience aliases retained for backward compatibility
|
|
99
|
-
acol = makeColumn
|
|
100
|
-
vcol = makeVirtualColumn
|
tigrbl/factories/engine.py
CHANGED
|
@@ -28,7 +28,7 @@ def engine_spec(
|
|
|
28
28
|
kind = kw.get("kind")
|
|
29
29
|
if not kind:
|
|
30
30
|
raise ValueError(
|
|
31
|
-
"Provide spec=<DSN|mapping> or kind=('sqlite'|'postgres') with appropriate fields"
|
|
31
|
+
"Provide spec=<DSN|mapping> or kind=('sqlite'|'postgres'|'mysql') with appropriate fields"
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
async_kw = kw.get("async_")
|
|
@@ -69,8 +69,17 @@ def engine_spec(
|
|
|
69
69
|
"pool_size": kw.get("pool_size", 10),
|
|
70
70
|
"max": kw.get("max", 20),
|
|
71
71
|
}
|
|
72
|
+
elif kind in ("mariadb", "mysql"):
|
|
73
|
+
async_ = bool(async_kw) if async_kw is not None else False
|
|
74
|
+
spec = {
|
|
75
|
+
"kind": kind, "async": async_,
|
|
76
|
+
"user": kw.get("user", "app"), "pwd": kw.get("pwd", "secret"),
|
|
77
|
+
"host": kw.get("host", "localhost"), "port": kw.get("port", 3306),
|
|
78
|
+
"db": kw.get("name", kw.get("db", "app_db")),
|
|
79
|
+
"pool_size": kw.get("pool_size", 10), "max": kw.get("max", 20),
|
|
80
|
+
}
|
|
72
81
|
else:
|
|
73
|
-
raise ValueError("kind must be 'sqlite' or '
|
|
82
|
+
raise ValueError("kind must be 'sqlite', 'postgres', or 'mysql'")
|
|
74
83
|
|
|
75
84
|
return EngineSpec.from_any(spec)
|
|
76
85
|
|
|
@@ -142,6 +151,26 @@ def pg_cfg(
|
|
|
142
151
|
}
|
|
143
152
|
|
|
144
153
|
|
|
154
|
+
def mysql_cfg(*, async_: bool = False, user: str = "app", pwd: str = "secret",
|
|
155
|
+
host: str = "localhost", port: int = 3306, name: str = "app_db",
|
|
156
|
+
pool_size: int = 10, max: int = 20) -> EngineCfg:
|
|
157
|
+
return {"kind": "mysql", "async": async_, "user": user, "pwd": pwd,
|
|
158
|
+
"host": host, "port": port, "db": name, "pool_size": pool_size, "max": max}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def mariadb_cfg(*, async_: bool = False, user: str = "app", pwd: str = "secret",
|
|
162
|
+
host: str = "localhost", port: int = 3306, name: str = "app_db",
|
|
163
|
+
pool_size: int = 10, max: int = 20) -> EngineCfg:
|
|
164
|
+
return {"kind": "mariadb", "async": async_, "user": user, "pwd": pwd,
|
|
165
|
+
"host": host, "port": port, "db": name, "pool_size": pool_size, "max": max}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def mariadb(**kw: Any) -> EngineCfg:
|
|
169
|
+
"""Sync MariaDB EngineCfg (PyMySQL)."""
|
|
170
|
+
kw.setdefault("async_", False)
|
|
171
|
+
return mariadb_cfg(**kw)
|
|
172
|
+
|
|
173
|
+
|
|
145
174
|
def mem(async_: bool = True) -> EngineCfg:
|
|
146
175
|
"""SQLite in-memory (StaticPool) EngineCfg mapping."""
|
|
147
176
|
return {"kind": "sqlite", "async": async_, "mode": "memory"}
|
|
@@ -174,6 +203,12 @@ def pgs(**kw: Any) -> EngineCfg:
|
|
|
174
203
|
return pg_cfg(**kw)
|
|
175
204
|
|
|
176
205
|
|
|
206
|
+
def mysql(**kw: Any) -> EngineCfg:
|
|
207
|
+
"""Sync MySQL EngineCfg (PyMySQL)."""
|
|
208
|
+
kw.setdefault("async_", False)
|
|
209
|
+
return mysql_cfg(**kw)
|
|
210
|
+
|
|
211
|
+
|
|
177
212
|
# ---------------------------------------------------------------------------
|
|
178
213
|
# Provider one-liners
|
|
179
214
|
# ---------------------------------------------------------------------------
|
|
@@ -213,6 +248,14 @@ def provider_postgres(
|
|
|
213
248
|
)
|
|
214
249
|
|
|
215
250
|
|
|
251
|
+
def provider_mariadb(**kw: Any) -> Provider:
|
|
252
|
+
return provider_from_spec(engine_spec(mariadb_cfg(**kw)))
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def provider_mysql(**kw: Any) -> Provider:
|
|
256
|
+
return provider_from_spec(engine_spec(mysql_cfg(**kw)))
|
|
257
|
+
|
|
258
|
+
|
|
216
259
|
__all__ = [
|
|
217
260
|
# EngineSpec / Provider / Engine helpers
|
|
218
261
|
"engine_spec",
|
|
@@ -221,13 +264,19 @@ __all__ = [
|
|
|
221
264
|
# convenience EngineCfg helpers
|
|
222
265
|
"sqlite_cfg",
|
|
223
266
|
"pg_cfg",
|
|
267
|
+
"mysql_cfg",
|
|
268
|
+
"mariadb_cfg",
|
|
224
269
|
"mem",
|
|
225
270
|
"sqlitef",
|
|
226
271
|
"pg",
|
|
227
272
|
"pga",
|
|
228
273
|
"pgs",
|
|
274
|
+
"mysql",
|
|
275
|
+
"mariadb",
|
|
229
276
|
# direct providers
|
|
230
277
|
"provider_sqlite_memory",
|
|
231
278
|
"provider_sqlite_file",
|
|
232
279
|
"provider_postgres",
|
|
280
|
+
"provider_mysql",
|
|
281
|
+
"provider_mariadb",
|
|
233
282
|
]
|
tigrbl/factories/op.py
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
from
|
|
1
|
+
from tigrbl_concrete.factories.op import makeOp, op
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def make(**kwargs: Any):
|
|
7
|
-
from tigrbl import Op
|
|
8
|
-
|
|
9
|
-
return Op(**kwargs)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
op = make
|
|
13
|
-
|
|
14
|
-
__all__ = ["make", "op"]
|
|
3
|
+
__all__ = ["makeOp", "op"]
|
tigrbl/factories/router.py
CHANGED
|
@@ -1,50 +1,3 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
3
|
-
from typing import Any, Sequence, Type
|
|
4
|
-
|
|
5
|
-
from .._spec.router_spec import RouterSpec
|
|
6
|
-
from .._concrete._router import Router
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def defineRouterSpec(
|
|
10
|
-
*,
|
|
11
|
-
name: str = "router",
|
|
12
|
-
prefix: str = "",
|
|
13
|
-
tags: Sequence[str] = (),
|
|
14
|
-
engine: Any = None,
|
|
15
|
-
engine_name: str | None = None,
|
|
16
|
-
ops: Sequence[Any] = (),
|
|
17
|
-
schemas: Sequence[Any] = (),
|
|
18
|
-
hooks: Sequence[Any] = (),
|
|
19
|
-
security_deps: Sequence[Any] = (),
|
|
20
|
-
deps: Sequence[Any] = (),
|
|
21
|
-
middlewares: Sequence[Any] = (),
|
|
22
|
-
response: Any = None,
|
|
23
|
-
paths: Sequence[Any] = (),
|
|
24
|
-
tables: Sequence[Any] = (),
|
|
25
|
-
) -> Type[RouterSpec]:
|
|
26
|
-
attrs = dict(
|
|
27
|
-
NAME=name,
|
|
28
|
-
PREFIX=prefix,
|
|
29
|
-
TAGS=tuple(tags or ()),
|
|
30
|
-
ENGINE=engine,
|
|
31
|
-
ENGINE_NAME=engine_name,
|
|
32
|
-
OPS=tuple(ops or ()),
|
|
33
|
-
SCHEMAS=tuple(schemas or ()),
|
|
34
|
-
HOOKS=tuple(hooks or ()),
|
|
35
|
-
SECURITY_DEPS=tuple(security_deps or ()),
|
|
36
|
-
DEPS=tuple(deps or ()),
|
|
37
|
-
MIDDLEWARES=tuple(middlewares or ()),
|
|
38
|
-
RESPONSE=response,
|
|
39
|
-
PATHS=tuple(paths or ()),
|
|
40
|
-
TABLES=tuple(tables or ()),
|
|
41
|
-
)
|
|
42
|
-
return type("RouterSpec", (RouterSpec,), attrs)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def deriveRouter(**kw: Any) -> Type[Router]:
|
|
46
|
-
spec = defineRouterSpec(**kw)
|
|
47
|
-
return type("RouterWithSpec", (Router, spec), {})
|
|
48
|
-
|
|
1
|
+
from tigrbl_concrete.factories.router import defineRouterSpec, deriveRouter
|
|
49
2
|
|
|
50
3
|
__all__ = ["defineRouterSpec", "deriveRouter"]
|
tigrbl/factories/table.py
CHANGED
|
@@ -1,57 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
from
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
hooks: Sequence[Any] = (),
|
|
19
|
-
# dependency stacks
|
|
20
|
-
security_deps: Sequence[Any] = (),
|
|
21
|
-
deps: Sequence[Any] = (),
|
|
22
|
-
) -> Type[TableSpec]:
|
|
23
|
-
"""
|
|
24
|
-
Build a Table-spec class with class attributes only (no instances).
|
|
25
|
-
Use directly in your ORM class MRO:
|
|
26
|
-
|
|
27
|
-
class User(defineTableSpec(engine=..., ops=(...)), Base, Table):
|
|
28
|
-
__tablename__ = "users"
|
|
29
|
-
|
|
30
|
-
or pass it to `deriveTable(Model, ...)` to get a configured subclass.
|
|
31
|
-
"""
|
|
32
|
-
attrs = {
|
|
33
|
-
# top-level mirrors read by collectors
|
|
34
|
-
"OPS": tuple(ops or ()),
|
|
35
|
-
"COLUMNS": tuple(columns or ()),
|
|
36
|
-
"SCHEMAS": tuple(schemas or ()),
|
|
37
|
-
"HOOKS": tuple(hooks or ()),
|
|
38
|
-
"SECURITY_DEPS": tuple(security_deps or ()),
|
|
39
|
-
"DEPS": tuple(deps or ()),
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
# Engine binding is conventionally stored under table_config["engine"]
|
|
43
|
-
# (and legacy "db" for backward compatibility) so collectors can find it.
|
|
44
|
-
if engine is not None:
|
|
45
|
-
attrs["table_config"] = {"engine": engine, "db": engine}
|
|
46
|
-
|
|
47
|
-
return type("TableSpec", (TableSpec,), attrs)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def deriveTable(model: Type[Table], **kw: Any) -> Type[Table]:
|
|
51
|
-
"""Produce a concrete ORM subclass that inherits the spec."""
|
|
52
|
-
Spec = defineTableSpec(**kw)
|
|
53
|
-
name = f"{model.__name__}WithSpec"
|
|
54
|
-
return type(name, (Spec, model), {})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
__all__ = ["defineTableSpec", "deriveTable"]
|
|
1
|
+
from tigrbl_concrete.factories.table import (
|
|
2
|
+
defineTableSpec,
|
|
3
|
+
deriveTable,
|
|
4
|
+
deriveTableSpec,
|
|
5
|
+
provideTableSpec,
|
|
6
|
+
)
|
|
7
|
+
from tigrbl_concrete.factories.activation import activateTableSpec, activateTableSpecs
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"activateTableSpec",
|
|
12
|
+
"activateTableSpecs",
|
|
13
|
+
"defineTableSpec",
|
|
14
|
+
"deriveTable",
|
|
15
|
+
"deriveTableSpec",
|
|
16
|
+
"provideTableSpec",
|
|
17
|
+
]
|