ddlglot 0.1.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.
Files changed (51) hide show
  1. ddlglot-0.1.0/.commitlintrc.json +6 -0
  2. ddlglot-0.1.0/.github/pull_request_template.md +25 -0
  3. ddlglot-0.1.0/.github/workflows/ci.yml +96 -0
  4. ddlglot-0.1.0/.github/workflows/docs.yml +56 -0
  5. ddlglot-0.1.0/.github/workflows/release-please.yml +60 -0
  6. ddlglot-0.1.0/.gitignore +8 -0
  7. ddlglot-0.1.0/.pre-commit-config.yaml +23 -0
  8. ddlglot-0.1.0/.python-version +1 -0
  9. ddlglot-0.1.0/.release-please-config.json +10 -0
  10. ddlglot-0.1.0/.release-please-manifest.json +3 -0
  11. ddlglot-0.1.0/AGENTS.md +248 -0
  12. ddlglot-0.1.0/CHANGELOG.md +57 -0
  13. ddlglot-0.1.0/PKG-INFO +140 -0
  14. ddlglot-0.1.0/PLAN.md +356 -0
  15. ddlglot-0.1.0/README.md +123 -0
  16. ddlglot-0.1.0/docs/_static/.gitkeep +0 -0
  17. ddlglot-0.1.0/docs/api_reference.rst +142 -0
  18. ddlglot-0.1.0/docs/conf.py +25 -0
  19. ddlglot-0.1.0/docs/core_builder.rst +177 -0
  20. ddlglot-0.1.0/docs/index.rst +53 -0
  21. ddlglot-0.1.0/docs/quickstart.rst +175 -0
  22. ddlglot-0.1.0/docs/variants/bigquery.rst +60 -0
  23. ddlglot-0.1.0/docs/variants/duckdb.rst +39 -0
  24. ddlglot-0.1.0/docs/variants/hive.rst +70 -0
  25. ddlglot-0.1.0/docs/variants/index.rst +11 -0
  26. ddlglot-0.1.0/docs/variants/postgres.rst +29 -0
  27. ddlglot-0.1.0/docs/variants/spark_delta.rst +90 -0
  28. ddlglot-0.1.0/init.md +544 -0
  29. ddlglot-0.1.0/prd.md +297 -0
  30. ddlglot-0.1.0/pyproject.toml +49 -0
  31. ddlglot-0.1.0/src/ddlglot/__init__.py +69 -0
  32. ddlglot-0.1.0/src/ddlglot/builder.py +231 -0
  33. ddlglot-0.1.0/src/ddlglot/exceptions.py +78 -0
  34. ddlglot-0.1.0/src/ddlglot/properties.py +78 -0
  35. ddlglot-0.1.0/src/ddlglot/registry.py +94 -0
  36. ddlglot-0.1.0/src/ddlglot/variants/__init__.py +22 -0
  37. ddlglot-0.1.0/src/ddlglot/variants/bigquery.py +111 -0
  38. ddlglot-0.1.0/src/ddlglot/variants/duckdb.py +122 -0
  39. ddlglot-0.1.0/src/ddlglot/variants/hive.py +182 -0
  40. ddlglot-0.1.0/src/ddlglot/variants/postgres.py +85 -0
  41. ddlglot-0.1.0/src/ddlglot/variants/spark_delta.py +169 -0
  42. ddlglot-0.1.0/tests/conftest.py +3 -0
  43. ddlglot-0.1.0/tests/test_bigquery.py +63 -0
  44. ddlglot-0.1.0/tests/test_core.py +289 -0
  45. ddlglot-0.1.0/tests/test_duckdb.py +52 -0
  46. ddlglot-0.1.0/tests/test_hive.py +107 -0
  47. ddlglot-0.1.0/tests/test_postgres.py +87 -0
  48. ddlglot-0.1.0/tests/test_registry.py +156 -0
  49. ddlglot-0.1.0/tests/test_spark_delta.py +135 -0
  50. ddlglot-0.1.0/tests/test_validation.py +130 -0
  51. ddlglot-0.1.0/uv.lock +678 -0
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": ["@commitlint/config-conventional"],
3
+ "rules": {
4
+ "type-enum": [2, "always", ["feat", "fix", "docs", "style", "refactor", "test", "chore", "ci", "build", "perf", "revert"]]
5
+ }
6
+ }
@@ -0,0 +1,25 @@
1
+ ## Description
2
+
3
+ <!-- Describe your changes -->
4
+
5
+ ## Type of Change
6
+
7
+ - [ ] Bug fix
8
+ - [ ] New feature
9
+ - [ ] Breaking change
10
+ - [ ] Documentation update
11
+ - [ ] Refactoring
12
+
13
+ ## Checklist
14
+
15
+ - [ ] My code follows the style guidelines
16
+ - [ ] I have performed a self-review
17
+ - [ ] I have commented my code where necessary
18
+ - [ ] I have updated the documentation
19
+ - [ ] My changes generate no new warnings
20
+ - [ ] I have added tests that prove my fix is effective
21
+ - [ ] New and existing tests pass locally
22
+
23
+ ## Related Issue
24
+
25
+ <!-- Link to related issue (e.g., "Closes #123") -->
@@ -0,0 +1,96 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main, develop]
6
+ pull_request:
7
+ branches: [main, develop]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ test:
12
+ name: Test
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+
20
+ - name: Set up Python
21
+ uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.13"
24
+
25
+ - name: Install uv
26
+ uses: astral-sh/setup-uv@v4
27
+ with:
28
+ enable-cache: true
29
+
30
+ - name: Install dependencies
31
+ run: uv sync --all-extras
32
+
33
+ - name: Lint
34
+ run: uv run ruff check src tests
35
+
36
+ - name: Format check
37
+ run: uv run ruff format --check src tests
38
+
39
+ - name: Commitlint
40
+ uses: wagoid/commitlint-github-action@v6
41
+ with:
42
+ configFile: .commitlintrc.json
43
+
44
+ - name: Type check
45
+ run: uv run mypy src
46
+
47
+ - name: Run tests
48
+ run: uv run pytest tests --cov=ddlglot --cov-report=term-missing --cov-report=xml
49
+
50
+ - name: Upload coverage
51
+ uses: actions/upload-artifact@v4
52
+ with:
53
+ name: coverage
54
+ path: coverage.xml
55
+ retention-days: 1
56
+
57
+ - name: Upload to Codecov
58
+ uses: codecov/codecov-action@v4
59
+ with:
60
+ files: coverage.xml
61
+ continue-on-error: true
62
+
63
+ build:
64
+ name: Build
65
+ needs: test
66
+ runs-on: ubuntu-latest
67
+ steps:
68
+ - uses: actions/checkout@v4
69
+ with:
70
+ fetch-depth: 0
71
+
72
+ - name: Set up Python
73
+ uses: actions/setup-python@v5
74
+ with:
75
+ python-version: "3.13"
76
+
77
+ - name: Install uv
78
+ uses: astral-sh/setup-uv@v4
79
+
80
+ - name: Install build
81
+ run: uv pip install --system build hatch
82
+
83
+ - name: Build package
84
+ run: python -m build
85
+
86
+ - name: Verify build
87
+ run: |
88
+ pip install dist/*.whl --force-reinstall
89
+ python -c "import ddlglot; print('ddlglot imported successfully')"
90
+
91
+ - name: Upload artifacts
92
+ uses: actions/upload-artifact@v4
93
+ with:
94
+ name: dist
95
+ path: dist/
96
+ retention-days: 5
@@ -0,0 +1,56 @@
1
+ name: Deploy Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+ pages: write
11
+ id-token: write
12
+
13
+ concurrency:
14
+ group: pages
15
+ cancel-in-progress: false
16
+
17
+ jobs:
18
+ build:
19
+ name: Build
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Set up Python
25
+ uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.13"
28
+
29
+ - name: Install uv
30
+ uses: astral-sh/setup-uv@v4
31
+ with:
32
+ enable-cache: true
33
+
34
+ - name: Install docs dependencies
35
+ run: uv sync --extra docs
36
+
37
+ - name: Build docs
38
+ run: |
39
+ uv run sphinx-build -b html docs docs/_build/html
40
+
41
+ - name: Upload artifact
42
+ uses: actions/upload-pages-artifact@v3
43
+ with:
44
+ path: docs/_build/html
45
+
46
+ deploy:
47
+ name: Deploy
48
+ needs: build
49
+ runs-on: ubuntu-latest
50
+ environment:
51
+ name: github-pages
52
+ url: ${{ steps.deployment.outputs.page_url }}
53
+ steps:
54
+ - name: Deploy to GitHub Pages
55
+ id: deployment
56
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,60 @@
1
+ name: Release Please
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ permissions:
8
+ contents: write
9
+ pull-requests: write
10
+ id-token: write
11
+
12
+ jobs:
13
+ release-please:
14
+ runs-on: ubuntu-latest
15
+ outputs:
16
+ releases_created: ${{ steps.release-please.outputs.releases_created }}
17
+ version: ${{ steps.release-please.outputs.version }}
18
+ sha: ${{ steps.release-please.outputs.sha }}
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ with:
22
+ fetch-depth: 0
23
+
24
+ - uses: googleapis/release-please-action@v4
25
+ id: release-please
26
+ with:
27
+ release-type: python
28
+ config-file: .release-please-config.json
29
+ manifest-file: .release-please-manifest.json
30
+ token: ${{ secrets.GITHUB_TOKEN }}
31
+
32
+ publish:
33
+ needs: release-please
34
+ if: ${{ needs.release-please.outputs.releases_created }}
35
+ runs-on: ubuntu-latest
36
+ environment:
37
+ name: pypi
38
+ url: https://pypi.org/project/ddlglot/
39
+ steps:
40
+ - uses: actions/checkout@v4
41
+ with:
42
+ ref: ${{ needs.release-please.outputs.sha }}
43
+
44
+ - name: Set up Python
45
+ uses: actions/setup-python@v5
46
+ with:
47
+ python-version: "3.13"
48
+
49
+ - name: Install uv
50
+ uses: astral-sh/setup-uv@v4
51
+
52
+ - name: Build package
53
+ run: |
54
+ uv pip install --system build hatch
55
+ python -m build
56
+
57
+ - name: Publish to PyPI
58
+ uses: pypa/gh-action-pypi-publish@release/v1
59
+ with:
60
+ skip_existing: true
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .git/
5
+
6
+ # Docs build
7
+ docs/_build/
8
+
@@ -0,0 +1,23 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.5.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ - id: check-added-large-files
9
+ - id: check-toml
10
+
11
+ - repo: https://github.com/astral-sh/ruff-pre-commit
12
+ rev: v0.1.8
13
+ hooks:
14
+ - id: ruff
15
+ args: [--fix]
16
+ - id: ruff-format
17
+
18
+ - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
19
+ rev: v9.24.0
20
+ hooks:
21
+ - id: commitlint
22
+ stages: [commit-msg]
23
+ additional_dependencies: ["@commitlint/config-conventional"]
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://github.com/googleapis/release-please/raw/main/schemas/config.json",
3
+ "packages": {
4
+ ".": {
5
+ "package-name": "ddlglot",
6
+ "release-type": "python"
7
+ }
8
+ }
9
+ }
10
+
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.1.0"
3
+ }
@@ -0,0 +1,248 @@
1
+ # AGENTS.md - Developer Guide for ddlglot
2
+
3
+ ## Overview
4
+
5
+ `ddlglot` is a Python library that provides a fluent builder API for generating DDL (Data Definition Language) statements using SQLGlot's AST. It supports multiple SQL dialects (PostgreSQL, SQLite, DuckDB, Spark/Delta Lake, etc.).
6
+
7
+ ---
8
+
9
+ ## 1. Commands
10
+
11
+ ### Build & Install
12
+
13
+ ```bash
14
+ # Install the package in editable mode
15
+ pip install -e .
16
+
17
+ # Build the package
18
+ hatch build
19
+ ```
20
+
21
+ ### Testing
22
+
23
+ ```bash
24
+ # Run all tests
25
+ pytest
26
+
27
+ # Run a single test file
28
+ pytest tests/test_core.py
29
+
30
+ # Run a single test function
31
+ pytest tests/test_core.py::test_create_table_basic
32
+
33
+ # Run tests with verbose output
34
+ pytest -v
35
+
36
+ # Run tests with coverage
37
+ pytest --cov=ddlglot --cov-report=term-missing
38
+ ```
39
+
40
+ ### Linting & Type Checking
41
+
42
+ ```bash
43
+ # Run ruff (linter + formatter)
44
+ ruff check .
45
+ ruff format .
46
+
47
+ # Run mypy (type checking)
48
+ mypy src/ddlglot
49
+ ```
50
+
51
+ ---
52
+
53
+ ## 2. Code Style Guidelines
54
+
55
+ ### General
56
+
57
+ - **Language**: English for all code, comments, and documentation
58
+ - **Python version**: 3.13+
59
+ - **Build system**: hatchling (via `pyproject.toml`)
60
+
61
+ ### Imports
62
+
63
+ ```python
64
+ # Standard library first
65
+ from __future__ import annotations
66
+ from typing import Any, Dict, List, Optional, Tuple, Union
67
+
68
+ # Third-party packages
69
+ from sqlglot import expressions as exp
70
+
71
+ # Local modules
72
+ from ddlglot.builder import CreateBuilder, create
73
+ from ddlglot.variants.spark_delta import create_spark_delta
74
+ ```
75
+
76
+ - Use `from __future__ import annotations` for forward references
77
+ - Always use explicit relative imports for package modules (`from ..builder import ...`)
78
+ - Alphabetize imports within each group
79
+
80
+ ### Formatting
81
+
82
+ - **Line length**: 100 characters max
83
+ - **Indentation**: 4 spaces (no tabs)
84
+ - **Quotes**: Double quotes for strings, except when string contains double quotes
85
+ - **Trailing commas**: Use in multi-line expressions
86
+
87
+ ```python
88
+ # Good
89
+ def example(
90
+ arg1: str,
91
+ arg2: int,
92
+ ) -> Dict[str, Any]:
93
+ return {"arg1": arg1, "arg2": arg2}
94
+
95
+ # Bad
96
+ def example(arg1: str, arg2: int) -> Dict[str, Any]:
97
+ return {"arg1": arg1, "arg2": arg2}
98
+ ```
99
+
100
+ ### Types
101
+
102
+ - Use explicit type hints for all function parameters and return types
103
+ - Use `Optional[X]` instead of `X | None` for Python < 3.10 compatibility
104
+ - Prefer type aliases for complex types:
105
+
106
+ ```python
107
+ Lit = Union[str, int, float, bool]
108
+ ```
109
+
110
+ ### Naming Conventions
111
+
112
+ | Element | Convention | Example |
113
+ |---------|------------|---------|
114
+ | Modules | snake_case | `spark_delta.py` |
115
+ | Classes | PascalCase | `CreateBuilder` |
116
+ | Functions | snake_case | `create()`, `to_ast()` |
117
+ | Variables | snake_case | `self._table` |
118
+ | Constants | UPPER_SNAKE_CASE | `DELTA_FORMAT` |
119
+ | Private members | `_leading_underscore` | `self._columns` |
120
+
121
+ ### Classes & Methods
122
+
123
+ - Use fluent builder pattern: methods return `self` for chaining
124
+ - Use `__init__` for object construction
125
+ - Use `@staticmethod` for pure utility functions
126
+
127
+ ```python
128
+ class CreateBuilder:
129
+ def name(self, table: str) -> "CreateBuilder":
130
+ self._table = table
131
+ return self
132
+ ```
133
+
134
+ ### Error Handling
135
+
136
+ - Use explicit exceptions with descriptive messages
137
+ - Raise `ValueError` for invalid arguments
138
+
139
+ ```python
140
+ def to_ast(self) -> exp.Create:
141
+ if not self._table:
142
+ raise ValueError("Falta .name(<tabla>)")
143
+ ```
144
+
145
+ ### Docstrings
146
+
147
+ - Use Google-style docstrings for public APIs:
148
+
149
+ ```python
150
+ def sql(self, dialect: Optional[str] = None, pretty: bool = False) -> str:
151
+ """Generate SQL DDL string.
152
+
153
+ Args:
154
+ dialect: SQL dialect (e.g., "postgres", "spark").
155
+ pretty: Enable pretty formatting.
156
+
157
+ Returns:
158
+ The generated SQL string.
159
+ """
160
+ return self.to_ast().sql(dialect=dialect, pretty=pretty)
161
+ ```
162
+
163
+ - **Do not add comments** unless explicitly requested
164
+
165
+ ### Testing
166
+
167
+ - Place tests in `tests/` directory
168
+ - Use `pytest` as test runner
169
+ - Follow naming: `test_<module>.py`
170
+ - One test class per module, test functions prefixed with `test_`
171
+
172
+ ```python
173
+ # tests/test_core.py
174
+ import pytest
175
+ from ddlglot import create
176
+
177
+ def test_create_table_basic():
178
+ sql = (
179
+ create("table")
180
+ .name("public.users")
181
+ .column("id", "INT", not_null=True)
182
+ .sql(dialect="postgres")
183
+ )
184
+ assert "CREATE TABLE" in sql
185
+ ```
186
+
187
+ ---
188
+
189
+ ## 3. Project Structure
190
+
191
+ ```
192
+ ddlglot/
193
+ ├── pyproject.toml
194
+ ├── src/ddlglot/
195
+ │ ├── __init__.py
196
+ │ ├── builder.py # Core fluent builder
197
+ │ ├── properties.py # Property helpers
198
+ │ └── variants/
199
+ │ ├── __init__.py
200
+ │ └── spark_delta.py # Spark + Delta preset
201
+ └── tests/
202
+ ├── test_core.py
203
+ └── test_spark_delta.py
204
+ ```
205
+
206
+ ---
207
+
208
+ ## 4. Key Libraries
209
+
210
+ - **sqlglot**: AST and SQL generation (installed as dependency)
211
+ - **pytest**: Testing framework
212
+ - **ruff**: Linting and formatting
213
+ - **mypy**: Static type checking
214
+
215
+ ---
216
+
217
+ ## 5. Dialect-Specific Notes
218
+
219
+ - The builder is **dialect-agnostic** at the AST level
220
+ - Dialect-specific generation happens at `.sql(dialect=...)` call
221
+ - Supported dialects: `postgres`, `sqlite`, `duckdb`, `spark`, `databricks`, etc.
222
+ - SQLGlot's `Generator` handles dialect-specific syntax (e.g., `PARTITIONED BY` placement)
223
+
224
+ ---
225
+
226
+ ## 6. Common Tasks
227
+
228
+ ### Adding a New Dialect Preset
229
+
230
+ 1. Create `src/ddlglot/variants/<dialect>.py`
231
+ 2. Extend `CreateBuilder` following the pattern in `spark_delta.py`
232
+ 3. Export factory function `<dialect>_builder()`
233
+ 4. Add tests in `tests/test_<dialect>.py`
234
+
235
+ ### Adding New DDL Properties
236
+
237
+ 1. Add method to `CreateBuilder` (e.g., `.tblproperties()`)
238
+ 2. Implement property building in `_build_properties()`
239
+ 3. Use appropriate SQLGlot expression type (e.g., `exp.Properties`, `exp.Property`)
240
+ 4. Add tests covering the new property
241
+
242
+ ---
243
+
244
+ ## 7. Git Workflow
245
+
246
+ - Use Conventional Commits: `feat(scope): description`, `fix(scope): description`
247
+ - Run `pytest` and `ruff check .` before committing
248
+ - Never commit directly to `main`; use feature branches
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [26.4.0](https://github.com/alexmarco/ddlglot/compare/v26.3.2...v26.4.0) (2026-03-21)
9
+
10
+
11
+ ### Features
12
+
13
+ * **ci:** add release-please and commitlint for automated versioning ([5fb6b81](https://github.com/alexmarco/ddlglot/commit/5fb6b8136da4cc9898783f3db3cfbbf8a8dbdf11))
14
+ * **ci:** add release-please and commitlint for automated versioning ([b8f3db1](https://github.com/alexmarco/ddlglot/commit/b8f3db16c430d7b9c3684a82adcf89d8e3739b31))
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **docs:** remove tag trigger to avoid environment protection rules ([cb26ded](https://github.com/alexmarco/ddlglot/commit/cb26dedc10ac526b361403b86444770b2c62ae73))
20
+
21
+ ## [26.3.2] - 2026-03-21
22
+
23
+ ### Added
24
+
25
+ - `.sql()` now accepts `indent`, `pad`, and `max_text_width` parameters for fine-grained pretty printing control
26
+
27
+ ## [26.3.1] - 2026-03-21
28
+
29
+ ### Fixed
30
+
31
+ - CREATE TABLE now produces correct SQL without spurious `AS` clause
32
+
33
+ ## [26.3.0] - 2026-03-20
34
+
35
+ ### Added
36
+
37
+ - Core builder with fluent API for DDL generation
38
+ - Support for multiple SQL dialects:
39
+ - Spark+Delta Lake with CDF support
40
+ - Apache Hive with SERDE/ROW FORMAT
41
+ - PostgreSQL
42
+ - DuckDB
43
+ - BigQuery
44
+ - Plugin registry system for custom variants
45
+ - Dialect-specific validation
46
+ - Comprehensive test suite (92 tests)
47
+ - GitHub Actions CI/CD
48
+ - Sphinx documentation
49
+ - Pre-commit hooks
50
+
51
+ ### Features
52
+
53
+ - `create()` factory function for generic DDL
54
+ - `create_spark_delta()`, `create_hive()`, etc. for dialect-specific DDL
55
+ - Fluent method chaining for all DDL operations
56
+ - Type hints and validation
57
+ - SQLGlot-powered AST generation