Skip to main content

SQL Column Parser

Project description

WIP: SQL Column Parser

Codecov GitHub contributors

Library used to parse SQL CREATE TABLE statements into Python code used for code generation.

Intended usecase

Consider the following:

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE users (
    identifier UUID DEFAULT uuid_generate_v4(),
    email VARCHAR(256) UNIQUE NOT NULL,
    name VARCHAR(256) NOT NULL,
    is_admin BOOLEAN DEFAULT False,
    password VARCHAR(512) NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (identifier)
);
CREATE INDEX users_email_idx ON users USING btree (email);
CREATE INDEX users_name_idx ON users USING btree (name);

The output would then be a list of columns of type:

@dataclasses.dataclass
class Table:
    """Table.
    """

    columns: List[Column]
    names: Names

class ColumnType(pydantic.BaseModel):
    """ColumnType.
    """

    name: str
    max_bytesize: Optional[pydantic.conint(ge=1)]
    nullable: bool = True
    default: Optional[str] = None


@dataclasses.dataclass
class Column:
    """Column.
    """

    name: str
    col_type: ColumnType
    is_primary_key: bool

@dataclasses.dataclass
class Names():
    """Names.
    """

    singular_name: str
    plural_name: str

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sql_column_parser-0.1.0.tar.gz (6.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page