synalog 2.8.0__tar.gz → 2.9.0__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.
- {synalog-2.8.0 → synalog-2.9.0}/Cargo.lock +2 -2
- {synalog-2.8.0 → synalog-2.9.0}/Cargo.toml +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/PKG-INFO +9 -6
- {synalog-2.8.0 → synalog-2.9.0}/README.md +8 -5
- {synalog-2.8.0 → synalog-2.9.0}/docs/cli.md +31 -4
- {synalog-2.8.0 → synalog-2.9.0}/docs/development.md +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/run.py +3 -2
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/shop/rules/customer_revenue.l +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/shop/rules/orders_by_status.l +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/shop.log +2 -2
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/smoke/rules/failures_by_device.l +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/smoke.log +2 -2
- {synalog-2.8.0 → synalog-2.9.0}/docs/getting-started.md +6 -6
- {synalog-2.8.0 → synalog-2.9.0}/docs/language/index.md +17 -15
- {synalog-2.8.0 → synalog-2.9.0}/docs/python-api.md +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/pyproject.toml +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/cli.py +133 -4
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/introspect.py +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/project.py +153 -8
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/runners.py +178 -98
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/SKILL.md +14 -13
- {synalog-2.8.0/skills/synalog/examples/company/concepts → synalog-2.9.0/skills/synalog/examples/company/relationships}/works_in.l +2 -2
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/company/rules/team_mate.l +3 -3
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/sales/rules/total_by_region.l +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/uv.lock +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/verified/Cargo.toml +1 -1
- {synalog-2.8.0 → synalog-2.9.0}/.gitignore +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/LICENSE +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/NOTICE +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/assertions.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/assets/synalog-dark.svg +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/assets/synalog-light.svg +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/assets/synalog_favicon.png +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/benchmark/results.json +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/benchmark/speedup_by_engine.png +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/benchmark/speedup_distribution.png +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/benchmark/summary.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/benchmark/summary.png +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/benchmark/time_comparison.png +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/benchmark/verify_by_engine.png +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/benchmark.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/differences-datalog.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/differences.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/engines.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/aggregation.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/aggregation.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/directives.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/directives.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/functions.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/functions.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/functors.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/functors.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/getting_started.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/getting_started.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/knowledge_graphs.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/knowledge_graphs.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/recursion.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/recursion.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/shop/data/orders.csv +0 -0
- {synalog-2.8.0/docs/examples/shop/concepts → synalog-2.9.0/docs/examples/shop/entities}/customer.l +0 -0
- {synalog-2.8.0/docs/examples/shop/concepts → synalog-2.9.0/docs/examples/shop/entities}/order_status.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/shop/layer.toml +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/shop/rules/top_customers.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/shop/tables/orders.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/smoke/data/smoke_tests.csv +0 -0
- {synalog-2.8.0/docs/examples/smoke/concepts → synalog-2.9.0/docs/examples/smoke/entities}/device.l +0 -0
- {synalog-2.8.0/docs/examples/smoke/concepts → synalog-2.9.0/docs/examples/smoke/entities}/test_status.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/smoke/layer.toml +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/smoke/rules/runs_per_day.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/smoke/tables/smoke_tests.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/syntax.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/syntax.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/temporal.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/temporal.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/temporal_graph.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/temporal_graph.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/verification.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/examples/verification.log +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/index.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/javascripts/playground.js +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/javascripts/summarize.js +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/javascripts/synalog-highlight.js +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/knowledge-graphs.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/language/aggregation.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/language/directives.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/language/functions.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/language/functors.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/language/recursion.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/language/syntax.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/language/temporal.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/playground/vendor/codemirror.js +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/playground.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/stylesheets/extra.css +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/verification.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/docs/why.md +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/img/synalog-dark.svg +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/img/synalog-light.svg +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/__init__.py +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/__main__.py +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/checking.py +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/config.py +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/execution.py +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/python/synalog/writes.py +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/company/data/departments.csv +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/company/data/employees.csv +0 -0
- {synalog-2.8.0/skills/synalog/examples/company/concepts → synalog-2.9.0/skills/synalog/examples/company/entities}/department.l +0 -0
- {synalog-2.8.0/skills/synalog/examples/company/concepts → synalog-2.9.0/skills/synalog/examples/company/entities}/person.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/company/layer.toml +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/company/tables/departments.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/company/tables/employees.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/org/data/employees.csv +0 -0
- {synalog-2.8.0/skills/synalog/examples/org/concepts → synalog-2.9.0/skills/synalog/examples/org/entities}/all_managers.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/org/layer.toml +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/org/tables/employees.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/sales/data/sales.csv +0 -0
- {synalog-2.8.0/skills/synalog/examples/sales/concepts → synalog-2.9.0/skills/synalog/examples/sales/entities}/region.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/sales/layer.toml +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/sales/rules/monthly_sales.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/sales/rules/top_region.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/skills/synalog/examples/sales/tables/sales.l +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/assertion/mod.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/assertion/parse.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/assertion/report.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/assertion/translate.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/annotations.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/annotations_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/dialects.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/dialects_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/expr_translate.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/expr_translate_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/functors.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/functors_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/home_guard.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/home_guard_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/mod.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/rule_translate.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/rule_translate_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/builder.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/built_in.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/edge.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/expression.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/graph.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/inference.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/intersection.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/mod.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/type_inference/types.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/universe.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/compiler/universe_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/errors.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/lib.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/json.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/json_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/mod.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/names.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/parse.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/parse_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/rewrite.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/rewrite_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/span.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/span_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/traverse.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/parser/traverse_test.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/python.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/arity.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/assertions.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/cast.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/contradiction.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/dependencies.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/directives.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/front_matter.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/functors.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/mod.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/orderby.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/positional.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/recursion.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/reserved.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/safety.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/sqlexpr.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/stratification.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/undefined.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/verifier/vars.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/src/wasm.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/arity.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/cast.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/contradiction.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/convergence.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/home.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/lib.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/membership.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/page.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/plan.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/quote.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/recursion.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/safety.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/strata.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/verified/src/types.rs +0 -0
- {synalog-2.8.0 → synalog-2.9.0}/zensical.toml +0 -0
|
@@ -300,7 +300,7 @@ dependencies = [
|
|
|
300
300
|
|
|
301
301
|
[[package]]
|
|
302
302
|
name = "synalog"
|
|
303
|
-
version = "2.
|
|
303
|
+
version = "2.9.0"
|
|
304
304
|
dependencies = [
|
|
305
305
|
"anyhow",
|
|
306
306
|
"indexmap",
|
|
@@ -316,7 +316,7 @@ dependencies = [
|
|
|
316
316
|
|
|
317
317
|
[[package]]
|
|
318
318
|
name = "synalog-verified"
|
|
319
|
-
version = "2.
|
|
319
|
+
version = "2.9.0"
|
|
320
320
|
dependencies = [
|
|
321
321
|
"vstd",
|
|
322
322
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: synalog
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.9.0
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -311,13 +311,16 @@ All of these functions accept an optional `engine` keyword that overrides the pr
|
|
|
311
311
|
|
|
312
312
|
## Language overview
|
|
313
313
|
|
|
314
|
-
A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in
|
|
314
|
+
A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in `tables/`, `entities/`, `relationships/` and `rules/`, the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers):
|
|
315
315
|
|
|
316
316
|
```
|
|
317
317
|
shop/
|
|
318
|
+
├── data/orders.csv # local data files, loaded with --load
|
|
318
319
|
├── tables/orders.l # the data: one file per database table
|
|
319
|
-
├──
|
|
320
|
-
├──
|
|
320
|
+
├── entities/customer.l # entities extracted from tables
|
|
321
|
+
├── entities/order_status.l
|
|
322
|
+
├── relationships/ # relationships join entities
|
|
323
|
+
├── rules/customer_revenue.l # insights derived from entities and relationships
|
|
321
324
|
├── rules/top_customers.l
|
|
322
325
|
└── layer.toml # the project's name, description and database
|
|
323
326
|
```
|
|
@@ -336,7 +339,7 @@ Orders(order_id:, customer_id:, amount:, status:) :-
|
|
|
336
339
|
orders(order_id:, customer_id:, amount:, status:);
|
|
337
340
|
```
|
|
338
341
|
|
|
339
|
-
`
|
|
342
|
+
`entities/customer.l`
|
|
340
343
|
|
|
341
344
|
```synalog
|
|
342
345
|
---
|
|
@@ -356,7 +359,7 @@ Customer(customer_id:) distinct :- Orders(customer_id:);
|
|
|
356
359
|
name: CustomerRevenue
|
|
357
360
|
description: Total amount ordered by each customer, all statuses included.
|
|
358
361
|
---
|
|
359
|
-
import
|
|
362
|
+
import entities.customer.Customer;
|
|
360
363
|
import tables.orders.Orders;
|
|
361
364
|
|
|
362
365
|
@OrderBy(CustomerRevenue, "customer_id");
|
|
@@ -263,13 +263,16 @@ All of these functions accept an optional `engine` keyword that overrides the pr
|
|
|
263
263
|
|
|
264
264
|
## Language overview
|
|
265
265
|
|
|
266
|
-
A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in
|
|
266
|
+
A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in `tables/`, `entities/`, `relationships/` and `rules/`, the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers):
|
|
267
267
|
|
|
268
268
|
```
|
|
269
269
|
shop/
|
|
270
|
+
├── data/orders.csv # local data files, loaded with --load
|
|
270
271
|
├── tables/orders.l # the data: one file per database table
|
|
271
|
-
├──
|
|
272
|
-
├──
|
|
272
|
+
├── entities/customer.l # entities extracted from tables
|
|
273
|
+
├── entities/order_status.l
|
|
274
|
+
├── relationships/ # relationships join entities
|
|
275
|
+
├── rules/customer_revenue.l # insights derived from entities and relationships
|
|
273
276
|
├── rules/top_customers.l
|
|
274
277
|
└── layer.toml # the project's name, description and database
|
|
275
278
|
```
|
|
@@ -288,7 +291,7 @@ Orders(order_id:, customer_id:, amount:, status:) :-
|
|
|
288
291
|
orders(order_id:, customer_id:, amount:, status:);
|
|
289
292
|
```
|
|
290
293
|
|
|
291
|
-
`
|
|
294
|
+
`entities/customer.l`
|
|
292
295
|
|
|
293
296
|
```synalog
|
|
294
297
|
---
|
|
@@ -308,7 +311,7 @@ Customer(customer_id:) distinct :- Orders(customer_id:);
|
|
|
308
311
|
name: CustomerRevenue
|
|
309
312
|
description: Total amount ordered by each customer, all statuses included.
|
|
310
313
|
---
|
|
311
|
-
import
|
|
314
|
+
import entities.customer.Customer;
|
|
312
315
|
import tables.orders.Orders;
|
|
313
316
|
|
|
314
317
|
@OrderBy(CustomerRevenue, "customer_id");
|
|
@@ -156,7 +156,7 @@ A failing program never produces partial output: `run` either prints the table o
|
|
|
156
156
|
|
|
157
157
|
## Projects: `layer.toml`
|
|
158
158
|
|
|
159
|
-
A Synalog program is a [project](language/index.md): a folder with a `layer.toml`, its predicates in `tables/`, `
|
|
159
|
+
A Synalog program is a [project](language/index.md): a folder with a `layer.toml`, its predicates in `tables/`, `entities/`, `relationships/` and `rules/`, one per file. The file names and describes the project, and its `[connection]` says which database it runs on, as plain fields — commit it:
|
|
160
160
|
|
|
161
161
|
```toml
|
|
162
162
|
[project]
|
|
@@ -174,20 +174,47 @@ schema = "public"
|
|
|
174
174
|
|
|
175
175
|
Secrets never go in the file (synalog refuses it): each comes from the environment as `SYNALOG_<ENGINE>_<FIELD>` — `SYNALOG_PSQL_PASSWORD`, `SYNALOG_DATABRICKS_ACCESS_TOKEN`, or `GOOGLE_APPLICATION_CREDENTIALS` for BigQuery — usually from the project's `.env`, kept out of git. Anywhere in the project, `run`, `print`, `verify` and `introspect` use that engine and connection, and [imports](#imports) resolve from the project's folder. The project's file is the only place a connection comes from: `--engine` and an `@Engine` annotation choose the dialect, and a remote engine runs only through the project's connection to it. The fields of every engine are in `synalog.project.ENGINES`.
|
|
176
176
|
|
|
177
|
+
### Init
|
|
178
|
+
|
|
179
|
+
```console
|
|
180
|
+
$ synalog init
|
|
181
|
+
Initialized /path/to/sales (data, tables, entities, relationships, rules + layer.toml, .env.template, .gitignore, AGENTS.md, CLAUDE.md)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`synalog init [PATH]` scaffolds a layer project — here, or at the given path:
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
sales/
|
|
188
|
+
├── data/
|
|
189
|
+
├── tables/
|
|
190
|
+
├── entities/
|
|
191
|
+
├── relationships/
|
|
192
|
+
├── rules/
|
|
193
|
+
├── layer.toml
|
|
194
|
+
├── .env.template
|
|
195
|
+
├── .gitignore
|
|
196
|
+
├── AGENTS.md
|
|
197
|
+
└── CLAUDE.md -> AGENTS.md
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Each folder gets a `.gitkeep`; `layer.toml` names the project after its folder and documents every engine's connection, commented out (without one the project runs in memory on DuckDB, the default); `.env.template` lists the engines' secrets, to copy to `.env` and fill in; `.gitignore` keeps `.env` out of git. `AGENTS.md` explains the layer — layout, conventions, commands — to any coding agent; `CLAUDE.md` links to it. An existing `layer.toml` is kept and refuses the command: nothing is overwritten.
|
|
201
|
+
|
|
177
202
|
### Connect
|
|
178
203
|
|
|
179
204
|
```console
|
|
180
205
|
$ synalog connect psql host=db.example.com database=sales user=analyst password=...
|
|
181
|
-
Connected /path/to/sales/layer.toml to psql (secrets in .env)
|
|
206
|
+
Connected /path/to/sales/layer.toml to psql (secrets in .env, connection tested)
|
|
182
207
|
$ synalog connect
|
|
183
208
|
/path/to/sales/layer.toml
|
|
184
209
|
engine = psql
|
|
185
210
|
host = db.example.com
|
|
186
211
|
...
|
|
187
212
|
password: SYNALOG_PSQL_PASSWORD set
|
|
213
|
+
$ synalog connect test
|
|
214
|
+
Connection to psql (db.example.com) works
|
|
188
215
|
```
|
|
189
216
|
|
|
190
|
-
`synalog connect <engine> key=value ...` writes it — the non-secret fields to `layer.toml`, the secret ones to `.env` — `synalog connect` shows it (secrets hidden), `synalog connect clear` removes it. It runs in the project's folder — the nearest `layer.toml`'s, else the current directory — keeps the file's other tables, adds `.env` to `.gitignore`, and writes nothing when a required field is missing.
|
|
217
|
+
`synalog connect <engine> key=value ...` writes it — the non-secret fields to `layer.toml`, the secret ones to `.env` — `synalog connect` shows it (secrets hidden), `synalog connect clear` removes it. It runs in the project's folder — the nearest `layer.toml`'s, else the current directory — keeps the file's other tables, adds `.env` to `.gitignore`, and writes nothing when a required field is missing. The connection is tested before it is written (a database that does not answer writes nothing), and `synalog connect test` re-tests it any time.
|
|
191
218
|
|
|
192
219
|
### Introspect
|
|
193
220
|
|
|
@@ -207,7 +234,7 @@ description: Orders.
|
|
|
207
234
|
PublicOrders(order_id:, customer_id:, amount:, status:) :- public.orders(order_id:, customer_id:, amount:, status:);
|
|
208
235
|
```
|
|
209
236
|
|
|
210
|
-
Run it again when the schema changes: the declarations are regenerated, and a file's front matter (its description, keywords, ...) is kept as written. A table the database no longer has keeps its file, since
|
|
237
|
+
Run it again when the schema changes: the declarations are regenerated, and a file's front matter (its description, keywords, ...) is kept as written. A table the database no longer has keeps its file, since entities and relationships may import it, and is listed. It needs a project connected to its database. PostgreSQL, Trino, Presto, Databricks and BigQuery can be introspected.
|
|
211
238
|
|
|
212
239
|
## Add the skill to your coding agent
|
|
213
240
|
|
|
@@ -153,7 +153,7 @@ It deploys to GitHub Pages automatically on push via `.github/workflows/docs.yml
|
|
|
153
153
|
|
|
154
154
|
### Documentation examples
|
|
155
155
|
|
|
156
|
-
The example projects (`docs/examples/shop/`, `docs/examples/smoke/`) are laid out as every Synalog project is: `tables/`, `
|
|
156
|
+
The example projects (`docs/examples/shop/`, `docs/examples/smoke/`) are laid out as every Synalog project is: `tables/`, `entities/`, `relationships/`, `rules/`, a `layer.toml`, and their data in `data/<table>.csv`. `run.py` loads the data into an in-memory DuckDB, checks every file, runs the predicate its front matter names, and writes the results to `<project>.log`.
|
|
157
157
|
|
|
158
158
|
The feature examples (aggregation, functors, recursion, ...) are single `.l` programs with their data as inline facts. For those, the `run.py` harness validates each program with `synalog.check()`, compiles every predicate listed in its `# run:` header, executes the SQL on an in-memory DuckDB, and writes the combined output to the matching `.log` file. A `# load: <file>.csv as <table>` header loads a CSV from `docs/examples/` into a DuckDB table before the predicates run. The `Today`/`Now` built-in concepts need no special handling, since the compiler inlines them per dialect:
|
|
159
159
|
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"""Run every documentation example and capture its output.
|
|
3
3
|
|
|
4
4
|
Each folder holding a ``layer.toml`` is a project, laid out as every
|
|
5
|
-
Synalog project is: ``tables/``, ``
|
|
5
|
+
Synalog project is: ``tables/``, ``entities/``, ``relationships/`` and
|
|
6
|
+
``rules/``, one predicate per
|
|
6
7
|
file named in its front matter, and its data in ``data/<table>.csv``. Every file
|
|
7
8
|
is checked, then its predicate runs on an in-memory DuckDB holding the data;
|
|
8
9
|
the results go to ``<project>.log``.
|
|
@@ -109,7 +110,7 @@ def run_example(path: Path) -> None:
|
|
|
109
110
|
path.with_suffix(".log").write_text("\n".join(out) + "\n")
|
|
110
111
|
|
|
111
112
|
|
|
112
|
-
FOLDERS = ("tables", "
|
|
113
|
+
FOLDERS = ("tables", "entities", "relationships", "rules")
|
|
113
114
|
|
|
114
115
|
|
|
115
116
|
def run_project(folder: Path) -> None:
|
|
@@ -3,7 +3,7 @@ name: CustomerRevenue
|
|
|
3
3
|
description: Total amount ordered by each customer, all statuses included.
|
|
4
4
|
keywords: [revenue, spend, sales]
|
|
5
5
|
---
|
|
6
|
-
import
|
|
6
|
+
import entities.customer.Customer;
|
|
7
7
|
import tables.orders.Orders;
|
|
8
8
|
|
|
9
9
|
@OrderBy(CustomerRevenue, "customer_id");
|
|
@@ -10,7 +10,7 @@ $ synalog tables/orders.l run Orders
|
|
|
10
10
|
| 5 | 200 | 95 | shipped |
|
|
11
11
|
(5 rows)
|
|
12
12
|
|
|
13
|
-
$ synalog
|
|
13
|
+
$ synalog entities/customer.l run Customer
|
|
14
14
|
| customer_id |
|
|
15
15
|
|-------------|
|
|
16
16
|
| 100 |
|
|
@@ -18,7 +18,7 @@ $ synalog concepts/customer.l run Customer
|
|
|
18
18
|
| 300 |
|
|
19
19
|
(3 rows)
|
|
20
20
|
|
|
21
|
-
$ synalog
|
|
21
|
+
$ synalog entities/order_status.l run OrderStatus
|
|
22
22
|
| status |
|
|
23
23
|
|-----------|
|
|
24
24
|
| cancelled |
|
|
@@ -3,7 +3,7 @@ name: FailuresByDevice
|
|
|
3
3
|
description: Number of failed smoke tests per device, most failures first.
|
|
4
4
|
keywords: [failures, errors, broken devices]
|
|
5
5
|
---
|
|
6
|
-
import
|
|
6
|
+
import entities.device.Device;
|
|
7
7
|
import tables.smoke_tests.SmokeTests;
|
|
8
8
|
|
|
9
9
|
@OrderBy(FailuresByDevice, "failures DESC");
|
|
@@ -17,7 +17,7 @@ $ synalog tables/smoke_tests.l run SmokeTests
|
|
|
17
17
|
| 12 | gateway | passed | 1822 | 2026-06-11 20:00:22 |
|
|
18
18
|
(12 rows)
|
|
19
19
|
|
|
20
|
-
$ synalog
|
|
20
|
+
$ synalog entities/device.l run Device
|
|
21
21
|
| device |
|
|
22
22
|
|----------|
|
|
23
23
|
| gateway |
|
|
@@ -25,7 +25,7 @@ $ synalog concepts/device.l run Device
|
|
|
25
25
|
| sensor-b |
|
|
26
26
|
(3 rows)
|
|
27
27
|
|
|
28
|
-
$ synalog
|
|
28
|
+
$ synalog entities/test_status.l run TestStatus
|
|
29
29
|
| status |
|
|
30
30
|
|--------|
|
|
31
31
|
| failed |
|
|
@@ -19,7 +19,7 @@ duckdb (the default engine), sqlite and PostgreSQL work out of the box: synalog
|
|
|
19
19
|
|
|
20
20
|
## Your first program
|
|
21
21
|
|
|
22
|
-
A Synalog project maps **tables** (the data), defines **
|
|
22
|
+
A Synalog project maps **tables** (the data), defines **entities** and **relationships** (extracted from tables) and writes **rules** (what you want to know), one predicate per file (see [Program structure](language/index.md)). You compile a predicate to SQL and run it with any database driver. To start, a single program can hold its own data as facts:
|
|
23
23
|
|
|
24
24
|
```python
|
|
25
25
|
import synalog
|
|
@@ -105,7 +105,7 @@ $ npx skills add SynaLinks/synalog # this project
|
|
|
105
105
|
$ npx skills add SynaLinks/synalog -g # user-wide, across all projects
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
Then lay out the project as [tables,
|
|
108
|
+
Then lay out the project as [tables, entities, relationships and rules](language/index.md), one predicate per file. See [Add the skill to your coding agent](cli.md#add-the-skill-to-your-coding-agent) for the per-agent options.
|
|
109
109
|
|
|
110
110
|
## Querying a CSV file
|
|
111
111
|
|
|
@@ -119,8 +119,8 @@ Real data lives in files or database tables, not inline facts. Here it is a smal
|
|
|
119
119
|
smoke/
|
|
120
120
|
├── data/smoke_tests.csv
|
|
121
121
|
├── tables/smoke_tests.l
|
|
122
|
-
├──
|
|
123
|
-
├──
|
|
122
|
+
├── entities/device.l
|
|
123
|
+
├── entities/test_status.l
|
|
124
124
|
├── rules/failures_by_device.l
|
|
125
125
|
├── rules/runs_per_day.l
|
|
126
126
|
└── layer.toml
|
|
@@ -132,10 +132,10 @@ The table file maps the database table `smoke_tests`, referenced by its lowercas
|
|
|
132
132
|
--8<-- "docs/examples/smoke/tables/smoke_tests.l"
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
An entity extracts the devices, and a rule counts the failures of each, importing both:
|
|
136
136
|
|
|
137
137
|
```synalog
|
|
138
|
-
--8<-- "docs/examples/smoke/
|
|
138
|
+
--8<-- "docs/examples/smoke/entities/device.l"
|
|
139
139
|
```
|
|
140
140
|
|
|
141
141
|
```synalog
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# Program structure
|
|
2
2
|
|
|
3
|
-
A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in
|
|
3
|
+
A Synalog program is a **project**: a folder with a `layer.toml`, holding one predicate per file in four folders. This is the layout of [semantic layers](https://github.com/SynaLinks/semantic-layers), and the one this documentation follows.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
shop/
|
|
7
7
|
├── tables/ # the data: one file per database table
|
|
8
8
|
│ └── orders.l
|
|
9
|
-
├──
|
|
9
|
+
├── entities/ # what the data is about: one kind of thing per file
|
|
10
10
|
│ ├── customer.l
|
|
11
11
|
│ └── order_status.l
|
|
12
|
+
├── relationships/ # what joins entities: one edge per file
|
|
12
13
|
├── rules/ # what you want to know: counts, rates, rankings
|
|
13
14
|
│ ├── customer_revenue.l
|
|
14
15
|
│ ├── orders_by_status.l
|
|
@@ -21,8 +22,9 @@ A predicate's kind is the folder it is in:
|
|
|
21
22
|
| Folder | Holds |
|
|
22
23
|
|---|---|
|
|
23
24
|
| `tables/` | the data: each file maps one database table to a predicate |
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
25
|
+
| `entities/` | entities extracted from tables (`Customer`, `OrderStatus`), and views that filter tables or rename messy columns |
|
|
26
|
+
| `relationships/` | relationships joining entities (`Purchased`, `WorksIn`) |
|
|
27
|
+
| `rules/` | insights derived from entities, relationships and other rules: counts, rates, rankings, trends |
|
|
26
28
|
|
|
27
29
|
## A file, a predicate
|
|
28
30
|
|
|
@@ -32,7 +34,7 @@ Each file is named after the predicate it defines, in snake_case: `<folder>/<nam
|
|
|
32
34
|
2. one `import` per predicate it builds on, by folder, file and predicate: `import tables.orders.Orders;`;
|
|
33
35
|
3. the predicate's rules, after its directives. Every predicate is ordered with [`@OrderBy`](directives.md#orderby): results are paginated, and without a stable order a page differs between calls.
|
|
34
36
|
|
|
35
|
-
`rules/top_customers.l` builds on `rules/customer_revenue.l`, which builds on
|
|
37
|
+
`rules/top_customers.l` builds on `rules/customer_revenue.l`, which builds on an entity and a table:
|
|
36
38
|
|
|
37
39
|
```synalog
|
|
38
40
|
--8<-- "docs/examples/shop/rules/customer_revenue.l"
|
|
@@ -54,22 +56,22 @@ A table file maps one database table, referenced by its database name (lowercase
|
|
|
54
56
|
|
|
55
57
|
Table files are generated from the database's schema: [`synalog introspect`](../cli.md#introspect) writes one per table, ordered by its first column, with a description made from its name until someone writes a better one, and keeps the front matter written by hand when it runs again.
|
|
56
58
|
|
|
57
|
-
###
|
|
59
|
+
### Entities and relationships
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
Entities and relationships extract what the data is about from tables, each kind in its folder:
|
|
60
62
|
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
+
- Entities are named after the entity: `Customer`, `Product`.
|
|
64
|
+
- Relationships are named after the relationship: `Purchased`, `WorksIn`.
|
|
63
65
|
|
|
64
66
|
```synalog
|
|
65
|
-
--8<-- "docs/examples/shop/
|
|
67
|
+
--8<-- "docs/examples/shop/entities/customer.l"
|
|
66
68
|
```
|
|
67
69
|
|
|
68
70
|
See [Knowledge graphs](../knowledge-graphs.md) for the full modeling conventions.
|
|
69
71
|
|
|
70
72
|
### Rules
|
|
71
73
|
|
|
72
|
-
Rules derive what you want to know from
|
|
74
|
+
Rules derive what you want to know from entities, relationships and other rules. They carry no suffix: `CustomerRevenue`, `TopCustomers`.
|
|
73
75
|
|
|
74
76
|
## Running a project
|
|
75
77
|
|
|
@@ -112,7 +114,7 @@ Orders(order_id: 2, customer_id: 100, amount: 1200, status: "pending");
|
|
|
112
114
|
Every file opens with YAML front matter, as in Markdown: a first line `---`, the YAML, and a closing `---` line. It says what the file is, and carries metadata for the tools around your project (keywords, ownership, ...). Synalog checks that it is well-formed YAML — a syntax error is reported on its line — and reads two keys, both required: `name` is the predicate the file is about — it must be one the file defines and orders with `@OrderBy` — and `description` says what its rows are, in the words someone would search for (see [verification](../verification.md#front-matter)). Other keys are left to the host (`keywords`, `locked`, ...), and the file parses as if the block were not there, so error line numbers stay those of the file. It must be the very first thing in the file; an opening `---` that is never closed is an error.
|
|
113
115
|
|
|
114
116
|
```synalog
|
|
115
|
-
--8<-- "docs/examples/shop/
|
|
117
|
+
--8<-- "docs/examples/shop/entities/customer.l"
|
|
116
118
|
```
|
|
117
119
|
|
|
118
120
|
To read it from Python, use [`front_matter`](../python-api.md#front_matter).
|
|
@@ -126,7 +128,7 @@ The power of logic programming is composition: define a predicate once, in its o
|
|
|
126
128
|
`import` brings one predicate of another file into scope: `import <folder>.<name>.<Name>;` reads the project's `<folder>/<name>.l` and names its predicate `<Name>`. One import statement names exactly one predicate; every import must be used.
|
|
127
129
|
|
|
128
130
|
```synalog
|
|
129
|
-
import
|
|
131
|
+
import entities.customer.Customer;
|
|
130
132
|
import tables.orders.Orders;
|
|
131
133
|
```
|
|
132
134
|
|
|
@@ -138,10 +140,10 @@ Imports resolve from the project's folder (the one holding `layer.toml`) in the
|
|
|
138
140
|
|
|
139
141
|
## Extract categorical values first
|
|
140
142
|
|
|
141
|
-
For columns like `status`, `type`, `tier`, `category` or `country`, extract the distinct values as
|
|
143
|
+
For columns like `status`, `type`, `tier`, `category` or `country`, extract the distinct values as an entity *before* writing rules over them. This gives consistency, reuse and discoverability:
|
|
142
144
|
|
|
143
145
|
```synalog
|
|
144
|
-
--8<-- "docs/examples/shop/
|
|
146
|
+
--8<-- "docs/examples/shop/entities/order_status.l"
|
|
145
147
|
```
|
|
146
148
|
|
|
147
149
|
```synalog
|
|
@@ -222,7 +222,7 @@ The YAML [front matter](language/index.md#front-matter) opening a program file,
|
|
|
222
222
|
```python
|
|
223
223
|
import yaml, synalog
|
|
224
224
|
|
|
225
|
-
source = open("
|
|
225
|
+
source = open("entities/active_customer.l").read()
|
|
226
226
|
meta = yaml.safe_load(synalog.front_matter(source) or "") or {}
|
|
227
227
|
meta.get("description") # "Customers with at least one delivered order."
|
|
228
228
|
```
|
|
@@ -25,6 +25,7 @@ options above also apply to the session.
|
|
|
25
25
|
|
|
26
26
|
from __future__ import annotations
|
|
27
27
|
|
|
28
|
+
import contextlib
|
|
28
29
|
import csv
|
|
29
30
|
import os
|
|
30
31
|
import re
|
|
@@ -38,7 +39,7 @@ from rich.syntax import Syntax
|
|
|
38
39
|
from rich.table import Table
|
|
39
40
|
from rich.text import Text
|
|
40
41
|
|
|
41
|
-
from . import __version__, project
|
|
42
|
+
from . import __version__, project, runners
|
|
42
43
|
from ._synalog import (
|
|
43
44
|
SUPPORTED_ENGINES,
|
|
44
45
|
check,
|
|
@@ -163,6 +164,64 @@ def _load_callback(ctx, param, value):
|
|
|
163
164
|
return loads
|
|
164
165
|
|
|
165
166
|
|
|
167
|
+
# ---------------------------------------------------------------------------
|
|
168
|
+
# Project scaffolding (init)
|
|
169
|
+
# ---------------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def cmd_init(args: tuple[str, ...], project_file: Path | None) -> int:
|
|
173
|
+
"""Scaffold a layer project: its folders, layer.toml and .env.template.
|
|
174
|
+
|
|
175
|
+
\b
|
|
176
|
+
synalog init [PATH] create a layer project here (or at PATH)
|
|
177
|
+
|
|
178
|
+
The project is five folders — data/, tables/, entities/, relationships/,
|
|
179
|
+
rules/ — a layer.toml naming it after its folder, a .env.template
|
|
180
|
+
listing every engine's secrets to copy to .env, a .gitignore keeping
|
|
181
|
+
.env out of git, and an AGENTS.md explaining the layer to coding agents
|
|
182
|
+
(CLAUDE.md links to it). The layer.toml documents every engine's
|
|
183
|
+
connection, commented out — without one the project runs in memory on
|
|
184
|
+
DuckDB, the default. An existing layer.toml is kept and refuses the
|
|
185
|
+
command: nothing is overwritten.
|
|
186
|
+
"""
|
|
187
|
+
if len(args) > 1:
|
|
188
|
+
raise click.UsageError("usage: synalog init [PATH]")
|
|
189
|
+
target = Path(args[0]) if args else Path.cwd()
|
|
190
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
191
|
+
if (target / "layer.toml").exists():
|
|
192
|
+
fail(f"{target / 'layer.toml'} already exists")
|
|
193
|
+
for folder in ("data", "tables", "entities", "relationships", "rules"):
|
|
194
|
+
(target / folder).mkdir(parents=True, exist_ok=True)
|
|
195
|
+
gitkeep = target / folder / ".gitkeep"
|
|
196
|
+
if not gitkeep.exists():
|
|
197
|
+
gitkeep.touch()
|
|
198
|
+
(target / "layer.toml").write_text(project.template(target.name), encoding="utf-8")
|
|
199
|
+
env_template = target / ".env.template"
|
|
200
|
+
if not env_template.exists():
|
|
201
|
+
env_template.write_text(project.env_template(), encoding="utf-8")
|
|
202
|
+
gitignore = target / ".gitignore"
|
|
203
|
+
if not gitignore.exists():
|
|
204
|
+
gitignore.write_text(
|
|
205
|
+
"# Secrets — copy .env.template to .env and fill it in;"
|
|
206
|
+
" never commit .env.\n.env\n",
|
|
207
|
+
encoding="utf-8",
|
|
208
|
+
)
|
|
209
|
+
agents_md = target / "AGENTS.md"
|
|
210
|
+
if not agents_md.exists():
|
|
211
|
+
agents_md.write_text(project.agents_md(target.name), encoding="utf-8")
|
|
212
|
+
claude_md = target / "CLAUDE.md"
|
|
213
|
+
if not claude_md.exists():
|
|
214
|
+
try:
|
|
215
|
+
os.symlink("AGENTS.md", claude_md)
|
|
216
|
+
except (OSError, NotImplementedError): # no symlink privilege
|
|
217
|
+
claude_md.write_text("@AGENTS.md\n", encoding="utf-8")
|
|
218
|
+
click.echo(
|
|
219
|
+
f"Initialized {target} (data, tables, entities, relationships, rules"
|
|
220
|
+
" + layer.toml, .env.template, .gitignore, AGENTS.md, CLAUDE.md)"
|
|
221
|
+
)
|
|
222
|
+
return 0
|
|
223
|
+
|
|
224
|
+
|
|
166
225
|
# ---------------------------------------------------------------------------
|
|
167
226
|
# The project's connection (connect)
|
|
168
227
|
# ---------------------------------------------------------------------------
|
|
@@ -193,17 +252,49 @@ def _engine_fields() -> str:
|
|
|
193
252
|
return "\n".join(lines)
|
|
194
253
|
|
|
195
254
|
|
|
255
|
+
def _candidate(engine: str, fields: dict) -> tuple[dict, dict[str, str]]:
|
|
256
|
+
"""The connection the given fields describe, resolved as it would be once
|
|
257
|
+
written — defaults filled, secrets taken from the fields first, then the
|
|
258
|
+
environment — and the fields' secrets named by variable: some drivers
|
|
259
|
+
(BigQuery's client) read only the environment."""
|
|
260
|
+
overlay = {
|
|
261
|
+
project.secret_env(engine, f.key): str(fields[f.key])
|
|
262
|
+
for f in project.ENGINES[engine].fields
|
|
263
|
+
if f.secret and fields.get(f.key) not in (None, "")
|
|
264
|
+
}
|
|
265
|
+
resolved = project.details({"engine": engine, **fields}, env={**os.environ, **overlay})
|
|
266
|
+
return {"engine": engine, **resolved}, overlay
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@contextlib.contextmanager
|
|
270
|
+
def _env_overlaid(values: dict[str, str]):
|
|
271
|
+
"""``values`` set in the process environment for the block, then restored."""
|
|
272
|
+
saved = {key: os.environ.get(key) for key in values}
|
|
273
|
+
os.environ.update(values)
|
|
274
|
+
try:
|
|
275
|
+
yield
|
|
276
|
+
finally:
|
|
277
|
+
for key, value in saved.items():
|
|
278
|
+
if value is None:
|
|
279
|
+
os.environ.pop(key, None)
|
|
280
|
+
else:
|
|
281
|
+
os.environ[key] = value
|
|
282
|
+
|
|
283
|
+
|
|
196
284
|
def cmd_connect(args: tuple[str, ...], project_file: Path | None) -> int:
|
|
197
285
|
"""Give the project its database, in its layer.toml.
|
|
198
286
|
|
|
199
287
|
\b
|
|
200
288
|
synalog connect show the project's connection (secrets hidden)
|
|
201
289
|
synalog connect <engine> key=value ... connect the project: layer.toml, secrets in .env
|
|
290
|
+
synalog connect test test the project's connection
|
|
202
291
|
synalog connect clear remove the connection (back to in-memory engines)
|
|
203
292
|
|
|
204
293
|
The project is the folder of the nearest layer.toml, else the current
|
|
205
294
|
directory. Secret fields (a password, a token) go to its .env, kept out
|
|
206
|
-
of git; the others to layer.toml, meant to be committed.
|
|
295
|
+
of git; the others to layer.toml, meant to be committed. The connection
|
|
296
|
+
is tested before it is written: a database that does not answer writes
|
|
297
|
+
nothing.
|
|
207
298
|
"""
|
|
208
299
|
folder = project_file.parent if project_file is not None else Path.cwd()
|
|
209
300
|
if not args:
|
|
@@ -225,14 +316,49 @@ def cmd_connect(args: tuple[str, ...], project_file: Path | None) -> int:
|
|
|
225
316
|
project.clear(folder)
|
|
226
317
|
click.echo(f"Removed the connection of {folder / project.PROJECT_FILE}")
|
|
227
318
|
return 0
|
|
319
|
+
if args[0] == "test":
|
|
320
|
+
if len(args) != 1:
|
|
321
|
+
raise click.UsageError("usage: synalog connect test")
|
|
322
|
+
return _connect_test(project_file)
|
|
228
323
|
engine, fields = args[0], _connection_fields(args[1:])
|
|
229
324
|
if engine not in project.ENGINES:
|
|
230
325
|
fail(f"'{engine}' takes no connection; engines that do: {', '.join(project.ENGINES)}\n" + _engine_fields())
|
|
231
326
|
try:
|
|
232
|
-
|
|
327
|
+
fields = project.check(engine, fields)
|
|
328
|
+
candidate, overlay = _candidate(engine, fields)
|
|
233
329
|
except project.ProjectError as e:
|
|
234
330
|
fail(f"{e}\n" + _engine_fields())
|
|
235
|
-
|
|
331
|
+
try:
|
|
332
|
+
with _env_overlaid(overlay): # BigQuery's client reads the environment
|
|
333
|
+
runners.probe(engine, candidate)
|
|
334
|
+
except RunnerUnavailable as e:
|
|
335
|
+
fail(e)
|
|
336
|
+
except Exception as e: # noqa: BLE001 - a driver or server error: report it, no traceback
|
|
337
|
+
fail(f"{type(e).__name__}: {e}")
|
|
338
|
+
# Checked and tested: the write cannot fail.
|
|
339
|
+
path = project.write(folder, engine, fields)
|
|
340
|
+
notes = ["secrets in .env"] if project.secrets(engine, fields) else []
|
|
341
|
+
click.echo(f"Connected {path} to {engine} ({', '.join([*notes, 'connection tested'])})")
|
|
342
|
+
return 0
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def _connect_test(project_file: Path | None) -> int:
|
|
346
|
+
"""`synalog connect test`: probe the project's connection as written."""
|
|
347
|
+
try:
|
|
348
|
+
conn = project.resolve(project_file.parent) if project_file is not None else None
|
|
349
|
+
except project.ProjectError as e:
|
|
350
|
+
fail(e)
|
|
351
|
+
if conn is None:
|
|
352
|
+
click.echo("No connection: synalog runs in memory (duckdb). " + _CONNECT_USAGE)
|
|
353
|
+
return 0
|
|
354
|
+
try:
|
|
355
|
+
runners.probe(conn["engine"], conn)
|
|
356
|
+
except RunnerUnavailable as e:
|
|
357
|
+
fail(e)
|
|
358
|
+
except Exception as e: # noqa: BLE001 - a driver or server error: report it, no traceback
|
|
359
|
+
fail(f"{type(e).__name__}: {e}")
|
|
360
|
+
where = conn.get("host") or conn.get("server_hostname") or conn.get("project")
|
|
361
|
+
click.echo(f"Connection to {conn['engine']} ({where}) works")
|
|
236
362
|
return 0
|
|
237
363
|
|
|
238
364
|
|
|
@@ -351,6 +477,7 @@ def main(args, inline, engine, limit, offset, as_csv, search_pattern,
|
|
|
351
477
|
synalog program.l run Predicate ... execute and print a table
|
|
352
478
|
synalog program.l run Predicate --csv execute and print CSV
|
|
353
479
|
synalog program.l verify [Predicate ...] check the @Assert statements
|
|
480
|
+
synalog init [PATH] scaffold a layer project
|
|
354
481
|
synalog connect ENGINE KEY=VALUE ... connect the project to its database
|
|
355
482
|
synalog introspect [ENGINE] write a project's tables/ from its database
|
|
356
483
|
|
|
@@ -384,6 +511,8 @@ def main(args, inline, engine, limit, offset, as_csv, search_pattern,
|
|
|
384
511
|
if project_file is not None:
|
|
385
512
|
dirs.insert(1 if len(dirs) > 1 else 0, str(project_file.parent))
|
|
386
513
|
config.load_dotenv(*dirs)
|
|
514
|
+
if args and args[0] == "init" and inline is None:
|
|
515
|
+
sys.exit(cmd_init(args[1:], project_file))
|
|
387
516
|
if args and args[0] == "connect" and inline is None:
|
|
388
517
|
sys.exit(cmd_connect(args[1:], project_file))
|
|
389
518
|
if args and args[0] == "introspect" and inline is None:
|
|
@@ -290,7 +290,7 @@ def write_tables(folder: str | Path, found: list[Table]) -> dict[str, list[str]]
|
|
|
290
290
|
keywords, ``locked`` written by hand — and only its declaration is
|
|
291
291
|
regenerated. Returns the tables ``written``, and the table files the
|
|
292
292
|
database no longer has (``gone``, by file name): kept, since the project's
|
|
293
|
-
|
|
293
|
+
entities and relationships may import them. A file named before the snake_case convention
|
|
294
294
|
(``PublicOrders.l``) gives its front matter to its new one and goes.
|
|
295
295
|
"""
|
|
296
296
|
folder = Path(folder)
|