rbtr-lang-sql 2026.9.0.dev1__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.
Files changed (26) hide show
  1. rbtr_lang_sql/__init__.py +1 -0
  2. rbtr_lang_sql/plugin.py +52 -0
  3. rbtr_lang_sql/py.typed +0 -0
  4. rbtr_lang_sql/sql.scm +70 -0
  5. rbtr_lang_sql/tests/__init__.py +0 -0
  6. rbtr_lang_sql/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +1 -0
  7. rbtr_lang_sql/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +268 -0
  8. rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_clickhouse].json +59 -0
  9. rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_duckdb].json +78 -0
  10. rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_mysql].json +59 -0
  11. rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_postgres].json +116 -0
  12. rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_sqlite].json +78 -0
  13. rbtr_lang_sql/tests/cases_extraction.py +265 -0
  14. rbtr_lang_sql/tests/samples/sql/sql.sql +38 -0
  15. rbtr_lang_sql/tests/samples/sql_clickhouse.sql +17 -0
  16. rbtr_lang_sql/tests/samples/sql_duckdb.sql +14 -0
  17. rbtr_lang_sql/tests/samples/sql_mysql.sql +11 -0
  18. rbtr_lang_sql/tests/samples/sql_postgres.sql +18 -0
  19. rbtr_lang_sql/tests/samples/sql_sqlite.sql +11 -0
  20. rbtr_lang_sql/tests/test_extraction.py +85 -0
  21. rbtr_lang_sql/tests/test_samples.py +115 -0
  22. rbtr_lang_sql-2026.9.0.dev1.dist-info/METADATA +79 -0
  23. rbtr_lang_sql-2026.9.0.dev1.dist-info/RECORD +26 -0
  24. rbtr_lang_sql-2026.9.0.dev1.dist-info/WHEEL +4 -0
  25. rbtr_lang_sql-2026.9.0.dev1.dist-info/entry_points.txt +3 -0
  26. rbtr_lang_sql-2026.9.0.dev1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,115 @@
1
+ """SQL sample extraction: the `samples/sql/` project through the real pipeline.
2
+
3
+ The snapshots are the golden record of what SQL extraction produces. The
4
+ `dialect` tests document how the single generic grammar handles each major
5
+ dialect. Engine-wide invariants are covered once in core.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from pathlib import Path
11
+ from typing import TYPE_CHECKING
12
+
13
+ import pytest
14
+ from tree_sitter import Parser
15
+
16
+ from rbtr.domain.models import Chunk, ChunkKind, Edge
17
+ from rbtr.git import FileEntry
18
+ from rbtr.languages.edges import build_resolution_map, infer_import_edges
19
+ from rbtr.languages.extract import extract_file
20
+ from rbtr.languages.manager import get_manager
21
+ from rbtr.testing import render_edges
22
+
23
+ if TYPE_CHECKING:
24
+ from syrupy.assertion import SnapshotAssertion
25
+
26
+
27
+ @pytest.fixture
28
+ def project() -> list[tuple[str, str]]:
29
+ """The `(relative path, text)` files of the `samples/sql/` project."""
30
+ root = Path(__file__).parent / "samples" / "sql"
31
+ return [
32
+ (str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
33
+ ]
34
+
35
+
36
+ @pytest.fixture
37
+ def chunks(project: list[tuple[str, str]]) -> list[Chunk]:
38
+ """Chunks from every project file, each via the real `extract_file`."""
39
+ manager = get_manager()
40
+ out: list[Chunk] = []
41
+ for path, text in project:
42
+ lang = manager.detect_language(path) or "sql"
43
+ out.extend(extract_file(FileEntry(path, "sha1", text.encode()), lang))
44
+ return out
45
+
46
+
47
+ @pytest.fixture
48
+ def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
49
+ """Import edges inferred across the project's files."""
50
+ manager = get_manager()
51
+ repo_files = {path for path, _ in project}
52
+ return infer_import_edges(chunks, repo_files, build_resolution_map(manager))
53
+
54
+
55
+ def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
56
+ """The sample exercises SQL's class, function, and variable chunks."""
57
+ kinds = {c.kind for c in chunks}
58
+ assert {
59
+ ChunkKind.CLASS,
60
+ ChunkKind.FUNCTION,
61
+ ChunkKind.VARIABLE,
62
+ ChunkKind.COMMENT,
63
+ } <= kinds
64
+
65
+
66
+ def test_parses_cleanly(project: list[tuple[str, str]]) -> None:
67
+ """Every project file is valid source — no tree-sitter ERROR/MISSING nodes."""
68
+ manager = get_manager()
69
+ for path, text in project:
70
+ grammar = manager.grammar(manager.detect_language(path) or "sql")
71
+ assert grammar is not None
72
+ assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
73
+
74
+
75
+ def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
76
+ assert chunks == snapshot_json
77
+
78
+
79
+ def test_edges_match_snapshot(
80
+ chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
81
+ ) -> None:
82
+ assert render_edges(edges, chunks) == snapshot_json
83
+
84
+
85
+ # ── SQL dialects ─────────────────────────────────────────────────────
86
+ # rbtr ships one generic SQL grammar for all `.sql` files. These pin
87
+ # current extraction per dialect; the parse-clean test is a strict-xfail
88
+ # sentinel that fires when the grammar gains full support for a dialect.
89
+
90
+
91
+ @pytest.mark.parametrize(
92
+ "dialect", ["sql_postgres", "sql_mysql", "sql_sqlite", "sql_duckdb", "sql_clickhouse"]
93
+ )
94
+ def test_sql_dialect_extraction_matches_snapshot(
95
+ dialect: str, snapshot_json: SnapshotAssertion
96
+ ) -> None:
97
+ """Current extraction for each SQL dialect under the generic grammar."""
98
+ source = (Path(__file__).parent / "samples" / f"{dialect}.sql").read_text()
99
+ chunks = list(extract_file(FileEntry(f"{dialect}.sql", "sha1", source.encode()), "sql"))
100
+ assert chunks == snapshot_json
101
+
102
+
103
+ @pytest.mark.xfail(
104
+ reason="generic SQL grammar does not fully parse dialect-specific syntax",
105
+ strict=True,
106
+ )
107
+ @pytest.mark.parametrize(
108
+ "dialect", ["sql_postgres", "sql_mysql", "sql_sqlite", "sql_duckdb", "sql_clickhouse"]
109
+ )
110
+ def test_sql_dialect_parses_cleanly(dialect: str) -> None:
111
+ """Sentinel: flips to XPASS (failing) when a dialect parses cleanly."""
112
+ source = (Path(__file__).parent / "samples" / f"{dialect}.sql").read_text()
113
+ grammar = get_manager().grammar("sql")
114
+ assert grammar is not None
115
+ assert not Parser(grammar).parse(source.encode()).root_node.has_error
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: rbtr-lang-sql
3
+ Version: 2026.9.0.dev1
4
+ Summary: rbtr — SQL language plugin
5
+ Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,sql
6
+ Author: Alejandro Giacometti
7
+ Author-email: Alejandro Giacometti <alejandro.giacometti@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: SQL
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Topic :: Text Processing :: Indexing
17
+ Classifier: Typing :: Typed
18
+ Requires-Dist: rbtr==2026.9.0.dev1
19
+ Requires-Dist: tree-sitter-sql
20
+ Requires-Python: >=3.13
21
+ Project-URL: Homepage, https://github.com/janrito/rbtr
22
+ Project-URL: Repository, https://github.com/janrito/rbtr
23
+ Project-URL: Documentation, https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-sql#readme
24
+ Project-URL: Issues, https://github.com/janrito/rbtr/issues
25
+ Project-URL: Changelog, https://github.com/janrito/rbtr/releases
26
+ Description-Content-Type: text/markdown
27
+
28
+ # rbtr-lang-sql
29
+
30
+ SQL support for [rbtr]. Optional plugin — install with
31
+ `pip install rbtr[sql]`.
32
+
33
+ [rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
34
+
35
+ ## What it ingests
36
+
37
+ One chunk per top-level SQL statement (plus one per CTE). SQL has no
38
+ classes or functions in the object-oriented sense and no native import
39
+ mechanism, so statements map onto rbtr's capture conventions by shape:
40
+ structural definitions become classes, routines and executable
41
+ statements become functions, and standalone named objects become
42
+ variables.
43
+
44
+ - **Structural definitions** — `CREATE TABLE`, `CREATE VIEW` /
45
+ `MATERIALIZED VIEW`, `CREATE TYPE ... AS ENUM` / composite types.
46
+ - **Routines & statements** — `CREATE FUNCTION`, `SELECT`, `INSERT`,
47
+ `UPDATE`, `DELETE`, `WITH ... AS` (CTEs), `ALTER` / `DROP`.
48
+ - **Named objects** — `CREATE INDEX` / `SEQUENCE` / `SCHEMA` / `ROLE` /
49
+ `TRIGGER`.
50
+
51
+ `CREATE PROCEDURE` and `PRAGMA` are not extracted — the generic grammar
52
+ has no node for them.
53
+
54
+ ## Chunks produced
55
+
56
+ `name` is the statement's target object; `scope` is always empty (SQL
57
+ has no nesting). A statement with no nameable target (`SELECT 1`, a
58
+ `UNION`) carries no name.
59
+
60
+ ```sql
61
+ CREATE TABLE users (id INT, name TEXT); -- class "users"
62
+ CREATE VIEW active AS SELECT * FROM users; -- class "active"
63
+ CREATE TYPE mood AS ENUM ('sad','happy'); -- class "mood"
64
+ CREATE FUNCTION add(a INT) ... -- function "add"
65
+ SELECT id, name FROM users; -- function "users"
66
+ INSERT INTO logs (msg) VALUES ('hi'); -- function "logs"
67
+ WITH ranked AS (...) SELECT ... -- function "ranked" (per CTE)
68
+ CREATE INDEX idx_name ON users (name); -- variable "idx_name"
69
+ CREATE SEQUENCE order_id START 1; -- variable "order_id"
70
+ ```
71
+
72
+ ## Embedded / injected chunks
73
+
74
+ None. SQL does not embed other languages.
75
+
76
+ ## Grammar & dependencies
77
+
78
+ Uses the `tree-sitter-sql` grammar (one generic grammar for all
79
+ dialects). No dependency on other language plugins.
@@ -0,0 +1,26 @@
1
+ rbtr_lang_sql/__init__.py,sha256=lk7BbykaSTxBqCgPjOZN4evgeGLZJPX8uPtsrCduXfs,35
2
+ rbtr_lang_sql/plugin.py,sha256=0_TYkY2B5aCc_Yljq1xLL5fVvWCj2SnyoeAf4WGZmWU,2179
3
+ rbtr_lang_sql/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ rbtr_lang_sql/sql.scm,sha256=JsdNrr8ypnfHD4BEA1rkNcyYnmUMpBnbof3gkDtUd-w,3154
5
+ rbtr_lang_sql/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ rbtr_lang_sql/tests/__snapshots__/test_samples/test_edges_match_snapshot.json,sha256=N1F-Xz3GaBn2H1p7uKzhkhKCQV8QVR0t76XD6wmFtXA,3
7
+ rbtr_lang_sql/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json,sha256=VKmqnSzsxCFz8hX4Bji5iMGa0LmrJoD1Ywyek4rbSUY,6341
8
+ rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_clickhouse].json,sha256=LEsLWNot58JZbTUqhraWm25GBU7IE19duZ3bB5deBL4,1569
9
+ rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_duckdb].json,sha256=KHoek1UegfNStjhuYmpRg041onimWVf_Zz-r-nIwnjQ,1810
10
+ rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_mysql].json,sha256=vddNvRNwdgAdalXU5ojdWEgW2f5Wb5rXAjWoJnujvTU,1551
11
+ rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_postgres].json,sha256=CS3RXHJNMBY-udPLiEphoPABhDIHNQ50NFflsynW-Zk,2775
12
+ rbtr_lang_sql/tests/__snapshots__/test_samples/test_sql_dialect_extraction_matches_snapshot[sql_sqlite].json,sha256=ywxE3JJUwKlSJVDPcLJppVwM2vTQzXt7kL3lbVNum9k,1851
13
+ rbtr_lang_sql/tests/cases_extraction.py,sha256=hEbvK8JkOVumPyiOa8md-XpVETe-bXkZFOPmyzV5oLs,8729
14
+ rbtr_lang_sql/tests/samples/sql/sql.sql,sha256=JdYD1xdfnKiR4phd4oXQeWLv55tTRy-lS6EYIOngkEc,1088
15
+ rbtr_lang_sql/tests/samples/sql_clickhouse.sql,sha256=pXE4bD0rWM9i8ACXiF_QxOCS0YGm9gBinlu-NWOBy1Y,454
16
+ rbtr_lang_sql/tests/samples/sql_duckdb.sql,sha256=TLNCUdLndjwcMbK8HXLmAOV67fOFdkRSaeskcGk2yLM,351
17
+ rbtr_lang_sql/tests/samples/sql_mysql.sql,sha256=3QFvmvkdc-VoRkRL25_6MTcCjI7js9Z4uzvasdXXass,420
18
+ rbtr_lang_sql/tests/samples/sql_postgres.sql,sha256=beefCKnUj6pU9GEL5jaW4rEtRWbhtDyrDrWhO-6KFl4,495
19
+ rbtr_lang_sql/tests/samples/sql_sqlite.sql,sha256=1Zbqd8uF461e9VAmoWTTEu23bj_zN68qm4GAfZzNm8M,353
20
+ rbtr_lang_sql/tests/test_extraction.py,sha256=ZCSd8Afy3uiz39m8vfJ1f3N2oY1OTcZJa26AomaWTuI,3323
21
+ rbtr_lang_sql/tests/test_samples.py,sha256=JEjhm0MdZmSsTZqYQKxWojfVcx-8GgDVzweXaY0ADAU,4342
22
+ rbtr_lang_sql-2026.9.0.dev1.dist-info/licenses/LICENSE,sha256=3LvNTMhogXUXkHsDvTWaXdtGd9C-uuoIVD1ey8w9ITs,1077
23
+ rbtr_lang_sql-2026.9.0.dev1.dist-info/WHEEL,sha256=-i9oRNYVXXZJUIYl5zclLIg6onEb0NLibTX34uln84w,81
24
+ rbtr_lang_sql-2026.9.0.dev1.dist-info/entry_points.txt,sha256=NRu3FcuWbK-k-HpN9LBJmcK5YgElqiMD2zYXaVWMFnU,49
25
+ rbtr_lang_sql-2026.9.0.dev1.dist-info/METADATA,sha256=3DbFQmF4nN60K-dEy2PTDx0uMlxPqz-Drouey7dU7PQ,3165
26
+ rbtr_lang_sql-2026.9.0.dev1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.12.13
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [rbtr.languages]
2
+ sql = rbtr_lang_sql.plugin:sql
3
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alejandro Giacometti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.