Skip to content

johan-Rm/yaml2sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YAML to SQL Converter

Convert YAML schema definitions to SQL CREATE TABLE statements with intelligent type mapping.

Features

  • 🔄 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

Installation

From PyPI (when published)

pip install yaml2sql

From Source

git clone https://github.com/johan-Rm/yaml2sql.git
cd yaml2sql
pip install -e .

Usage

CLI Commands

Convert YAML to SQL

# 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 --verbose

Validate YAML Files

yaml2sql validate ./schema/yaml

List Available Files

yaml2sql list-files ./schema/yaml

Python API

from yaml2sql import convert_yaml_to_sql

# Convert YAML files to SQL
convert_yaml_to_sql("./schema/yaml", "./output")

Type Mapping

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

Examples

Input YAML

# person.yaml
Person:
  type: object
  properties:
    name:
      type: string
    age:
      type: integer
    email:
      type: string
    createdAt:
      type: string
      format: date-time
    isActive:
      type: boolean

Generated SQL

-- 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
);

Development

Setup Development Environment

git clone https://github.com/johan-Rm/yaml2sql.git
cd yaml2sql
pip install -e ".[dev]"

Run Tests

pytest
pytest --cov=yaml2sql  # with coverage

Code Quality

black .              # Format code
flake8 .             # Lint code
mypy .               # Type checking

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Changelog

v1.0.0

  • Initial release
  • CLI interface with convert, validate, and list-files commands
  • Intelligent type mapping
  • JSON Schema format detection
  • Dry-run mode and verbose output

About

🎯 Convert YAML schema definitions to SQL CREATE TABLE statements with CLI tools. Support for intelligent type mapping, JSON Schema detection, and validation workflows.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages