grapdb 0.27.0__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.
- grapdb/__init__.py +0 -0
- grapdb/cli.py +110 -0
- grapdb/graph.py +755 -0
- grapdb/parser.py +430 -0
- grapdb/planner.py +46 -0
- grapdb/py.typed +0 -0
- grapdb/target/__init__.py +0 -0
- grapdb/target/diesel_orm.py +570 -0
- grapdb/target/rsrc/graph_orm_base.py +601 -0
- grapdb/target/rsrc/graph_orm_base_v14.py +749 -0
- grapdb/target/rsrc/graph_orm_base_v20.py +851 -0
- grapdb/target/sa_orm.py +637 -0
- grapdb-0.27.0.dist-info/METADATA +322 -0
- grapdb-0.27.0.dist-info/RECORD +18 -0
- grapdb-0.27.0.dist-info/WHEEL +4 -0
- grapdb-0.27.0.dist-info/entry_points.txt +3 -0
- test/__init__.py +0 -0
- test/test_basic.py +1685 -0
grapdb/__init__.py
ADDED
|
File without changes
|
grapdb/cli.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from . import parser, planner
|
|
9
|
+
from .graph import Graph
|
|
10
|
+
from .target import diesel_orm, sa_orm
|
|
11
|
+
|
|
12
|
+
description = """\
|
|
13
|
+
Parse GrapDB config files.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
_cmdline_parser = argparse.ArgumentParser(description=description)
|
|
17
|
+
_cmdline_parser.add_argument(
|
|
18
|
+
"-v",
|
|
19
|
+
"--verbose",
|
|
20
|
+
action="store_true",
|
|
21
|
+
help="Print debug messages",
|
|
22
|
+
)
|
|
23
|
+
_subparsers = _cmdline_parser.add_subparsers(title="subcommands", dest="subcommand")
|
|
24
|
+
_subparsers.required = True
|
|
25
|
+
_plan_parser = _subparsers.add_parser("plan", help="Output the migration plan in JSON.")
|
|
26
|
+
_plan_parser.add_argument(
|
|
27
|
+
"config",
|
|
28
|
+
action="store",
|
|
29
|
+
help="Path to config file in TOML format.",
|
|
30
|
+
)
|
|
31
|
+
_sqlalchemy_orm_parser = _subparsers.add_parser(
|
|
32
|
+
"sqlalchemy-orm",
|
|
33
|
+
help="Create a Python module that can be used to interface with the DB.",
|
|
34
|
+
)
|
|
35
|
+
_sqlalchemy_orm_parser.add_argument(
|
|
36
|
+
"config",
|
|
37
|
+
action="store",
|
|
38
|
+
help="Path to config file in TOML format.",
|
|
39
|
+
)
|
|
40
|
+
_sqlalchemy_orm_parser.add_argument(
|
|
41
|
+
"path",
|
|
42
|
+
action="store",
|
|
43
|
+
help="Path to write Python modules (graph_orm_base.py, graph_orm.py).",
|
|
44
|
+
)
|
|
45
|
+
_sqlalchemy_orm_parser.add_argument(
|
|
46
|
+
"--sa-version",
|
|
47
|
+
action="store",
|
|
48
|
+
type=int,
|
|
49
|
+
choices=[13, 14, 20],
|
|
50
|
+
default=13,
|
|
51
|
+
help="Generate for SqlAlchemy v1.4",
|
|
52
|
+
)
|
|
53
|
+
_diesel_orm_parser = _subparsers.add_parser(
|
|
54
|
+
"diesel-orm",
|
|
55
|
+
help="Create Rust modules to interface with the DB.",
|
|
56
|
+
)
|
|
57
|
+
_diesel_orm_parser.add_argument(
|
|
58
|
+
"config",
|
|
59
|
+
action="store",
|
|
60
|
+
help="Path to config file in TOML format.",
|
|
61
|
+
)
|
|
62
|
+
_diesel_orm_parser.add_argument(
|
|
63
|
+
"path",
|
|
64
|
+
action="store",
|
|
65
|
+
help="Path to write Rust modules (schema.rs, model.rs).",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def subcommand_plan(graph: Graph) -> None:
|
|
70
|
+
output = planner.generate(graph)
|
|
71
|
+
print(json.dumps(output, indent=2))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def subcommand_sqlalchemy_orm(graph: Graph, path: Path, sa_version: int) -> None:
|
|
75
|
+
sa_orm.generate(graph, path, sa_version)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def subcommand_diesel_orm(graph: Graph, path: Path) -> None:
|
|
79
|
+
diesel_orm.generate(graph, path)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def main() -> None:
|
|
83
|
+
args = _cmdline_parser.parse_args()
|
|
84
|
+
try:
|
|
85
|
+
graph = parser.graph_from_config_file(args.config)
|
|
86
|
+
except parser.InvalidSpec as e:
|
|
87
|
+
print("error: {}".format(e.args[0]), file=sys.stderr)
|
|
88
|
+
sys.exit(1)
|
|
89
|
+
|
|
90
|
+
if args.subcommand == "plan":
|
|
91
|
+
subcommand_plan(graph)
|
|
92
|
+
elif args.subcommand in {"sqlalchemy-orm", "diesel-orm"}:
|
|
93
|
+
path = Path(args.path)
|
|
94
|
+
if not path.exists():
|
|
95
|
+
print("Path does not exist: %r" % path, file=sys.stderr)
|
|
96
|
+
sys.exit(1)
|
|
97
|
+
if not path.is_dir():
|
|
98
|
+
print("Path is not a folder: %r" % path, file=sys.stderr)
|
|
99
|
+
sys.exit(1)
|
|
100
|
+
if args.subcommand == "sqlalchemy-orm":
|
|
101
|
+
subcommand_sqlalchemy_orm(graph, path, args.sa_version)
|
|
102
|
+
else:
|
|
103
|
+
assert args.subcommand == "diesel-orm"
|
|
104
|
+
subcommand_diesel_orm(graph, path)
|
|
105
|
+
else:
|
|
106
|
+
assert False
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
main()
|