Convert YAML schema definitions to SQL CREATE TABLE statements with intelligent type mapping.
- 🔄 Convert YAML schema files to SQL CREATE TABLE statements
- 🧠 Intelligent type mapping (string → TEXT/VARCHAR, integer → INTEGER, etc.)
- 🏷️ Support for JSON Schema format detection
- 📋 CLI interface with multiple commands
- ✅ YAML validation before conversion
- 🔍 Dry-run mode to preview output
- 📊 Verbose output for debugging
pip install yaml2sqlgit clone https://github.com/johan-Rm/yaml2sql.git
cd yaml2sql
pip install -e .# Basic conversion
yaml2sql convert ./schema/yaml ./output
# Custom output filename
yaml2sql convert ./schema/yaml ./output --output-file tables.sql
# Dry run (preview without writing)
yaml2sql convert ./schema/yaml ./output --dry-run --verbose
# Verbose output
yaml2sql convert ./schema/yaml ./output --verboseyaml2sql validate ./schema/yamlyaml2sql list-files ./schema/yamlfrom yaml2sql import convert_yaml_to_sql
# Convert YAML files to SQL
convert_yaml_to_sql("./schema/yaml", "./output")The converter intelligently maps YAML/JSON Schema types to SQL types:
| YAML/JSON Schema Type | SQL Type | Notes |
|---|---|---|
string |
TEXT |
Default for strings |
string (format: date-time) |
TIMESTAMP |
Date/time fields |
string (field contains "url") |
VARCHAR(500) |
URL fields |
string (field: "hash") |
VARCHAR(64) |
Hash fields |
string (field: "inLanguage") |
VARCHAR(10) |
Language codes |
string (field: "author", "publisher") |
VARCHAR(255) |
Person/org names |
integer |
INTEGER |
Whole numbers |
number |
DECIMAL |
Decimal numbers |
boolean |
BOOLEAN |
True/false values |
# person.yaml
Person:
type: object
properties:
name:
type: string
age:
type: integer
email:
type: string
createdAt:
type: string
format: date-time
isActive:
type: boolean-- Table générée depuis person.yaml
CREATE TABLE IF NOT EXISTS person (
id SERIAL PRIMARY KEY,
name TEXT,
age INTEGER,
email TEXT,
createdAt TIMESTAMP,
isActive BOOLEAN
);git clone https://github.com/johan-Rm/yaml2sql.git
cd yaml2sql
pip install -e ".[dev]"pytest
pytest --cov=yaml2sql # with coverageblack . # Format code
flake8 . # Lint code
mypy . # Type checkingThis project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Initial release
- CLI interface with convert, validate, and list-files commands
- Intelligent type mapping
- JSON Schema format detection
- Dry-run mode and verbose output