CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-simple-ddl-parser

Simple DDL Parser to parse SQL & dialects like HQL, TSQL (MSSQL), Oracle, AWS Redshift, Snowflake, MySQL, PostgreSQL, etc ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc.; sequences, alters, custom types & other entities from ddl.

Pending
Overview
Eval results
Files

cli.mddocs/

Command Line Interface

CLI tool accessible via the sdp command for processing DDL files from the command line with various output options and batch processing capabilities. The CLI provides convenient access to all parser functionality without requiring Python programming.

Capabilities

Main CLI Entry Point

Primary CLI function exposed as the sdp system command for command-line DDL parsing.

def main():
    """
    Main CLI entry point exposed as 'sdp' command.
    Handles command-line argument parsing and execution.
    """

Argument Parser Creation

Create and configure the command-line argument parser with all available options.

def cli():
    """
    Create and configure argument parser for CLI interface.
    
    Returns:
    ArgumentParser configured with all CLI options
    """

File Processing

Process individual DDL files with specified options and output formatting.

def run_for_file(args):
    """
    Process a single DDL file with specified arguments.
    
    Parameters:
    - args: Parsed command-line arguments containing file path and options
    """

File Extension Validation

Validate file extensions to ensure appropriate files are processed.

def correct_extension(file_name: str) -> bool:
    """
    Check if file has a valid DDL file extension.
    
    Parameters:
    - file_name (str): Name of file to check
    
    Returns:
    bool: True if file has valid extension (.sql, .ddl, etc.)
    """

CLI Usage

Basic Usage

# Parse a single DDL file
sdp schema.sql

# Parse with specific output dialect
sdp schema.sql --output-mode postgres

# Parse directory of DDL files (processes all .sql, .ddl, .hql, .bql files)
sdp /path/to/ddl/directory

Output Options

# Save output to custom directory (default: schemas/)
sdp schema.sql --target ./output

# Print results to console only (no file output)
sdp schema.sql --no-dump

# Enable verbose output to console
sdp schema.sql -v

Dialect-Specific Processing

# MySQL-specific output
sdp mysql_schema.sql --output-mode mysql

# PostgreSQL-specific output  
sdp postgres_schema.sql --output-mode postgres

# BigQuery-specific output
sdp bigquery_schema.sql --output-mode bigquery

# Oracle-specific output
sdp oracle_schema.sql --output-mode oracle

# Available output modes: sql, mysql, postgres, oracle, mssql, hql, 
# snowflake, bigquery, redshift, spark_sql, databricks, sqlite, 
# vertics, ibm_db2, athena

Command Line Arguments

Positional Arguments

  • ddl_file_path: Path to DDL file or directory to parse

Optional Arguments

  • -t, --target: Target directory to save parse results in .json files (default: "schemas")
  • -v: Verbose mode - print results to console
  • --no-dump: Parse without saving files, only print to console
  • -o, --output-mode: Output dialect mode for formatting results (default: "sql")

Examples

Simple Table Parsing

# Input file: simple_table.sql
CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    email VARCHAR(100) UNIQUE
);

# Command:
sdp simple_table.sql

# Result: Creates simple_table_schema.json in schemas/ directory

Verbose Output

# Parse and display results in terminal
sdp schema.sql -v

# Parse without creating files, only show in terminal
sdp schema.sql --no-dump

Custom Output Directory

# Save results to custom directory
sdp schema.sql --target ./my_output_dir

# Parse with specific dialect formatting
sdp postgres_schema.sql --output-mode postgres --target ./postgres_schemas

Directory Processing

# Process all DDL files in a directory
sdp /path/to/ddl/files/

# Process directory with verbose output
sdp /path/to/ddl/files/ -v --output-mode mysql

Multi-Dialect Processing

# Process same schema for different target databases
sdp schema.sql --output-mode mysql --target ./mysql_output
sdp schema.sql --output-mode postgres --target ./postgres_output  
sdp schema.sql --output-mode oracle --target ./oracle_output

Integration with Python

The CLI functionality can also be accessed programmatically:

from simple_ddl_parser.cli import main, cli, run_for_file
import sys

# Simulate CLI call
sys.argv = ['sdp', 'schema.sql', '--output-mode', 'postgres']
main()

# Or use individual functions
parser = cli()
args = parser.parse_args(['schema.sql', '--target', './output'])
run_for_file(args)

Install with Tessl CLI

npx tessl i tessl/pypi-simple-ddl-parser

docs

cli.md

core-parsing.md

exceptions.md

index.md

input-dialects.md

output-formatting.md

tile.json