Library to generate DDL for different dialects
Project description
Simple DDL Generator
What is it?
Simple DDL Generator generate SQL DDL from 3 different inputs. Idea of the generator same as for parser to support as much as possible DDLs in future.
Simple DDL Generator generate SQL DDL from 3 input formats - 1st from output Simple DDL Parser (https://github.com/xnuinside/simple-ddl-parser), 2nd from py-models-parser - https://github.com/xnuinside/py-models-parser. Or you can directly pass TableMeta classes (https://github.com/xnuinside/table-meta) to generator
How to use
As usually - more samples in tests/
pip install simple-ddl-generator
from simple_ddl_generator import DDLGenerator
from simple_ddl_parser import DDLParser
# take initial DDL
ddl = """CREATE EXTERNAL TABLE IF NOT EXISTS database.table_name
(
day_long_nm string,
calendar_dt date,
source_batch_id string,
field_qty decimal(10, 0),
field_bool boolean,
field_float float,
create_tmst timestamp,
field_double double,
field_long bigint
) PARTITIONED BY (batch_id int);"""
# get result from parser
data = DDLParser(ddl).run(group_by_type=True, output_mode="bigquery")
# rename, for example, table name
data["tables"][0]["table_name"] = "new_table_name"
g = DDLGenerator(data)
g.generate()
print(g.result)
# and result will be:
"""
CREATE EXTERNAL TABLE "database.new_table_name" (
day_long_nm string,
calendar_dt date,
source_batch_id string,
field_qty decimal(10, 0),
field_bool boolean,
field_float float,
create_tmst timestamp,
field_double double,
field_long bigint)
PARTITIONED BY (batch_id int);
"""
Changelog
v0.1.0
Base Generator Functionality with several test cases.
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
Built Distribution
Close
Hashes for simple-ddl-generator-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11eec9aa680935112ffc957f6d337c71b96fc9bc727e27165dab2eeb2c1c4b0b |
|
MD5 | dc2a68ff836b688d5ced95d5e21f1dbd |
|
BLAKE2b-256 | 634a024b0dabe63e222c0d37efb4d52a55c48796f1a563f87568e62d23d9e27c |
Close
Hashes for simple_ddl_generator-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0da3b4d864acf099a0f97ef5c26fbc3856858a27c762e667ea99b95d94b48045 |
|
MD5 | 8e960dc22974b21349be105c7fb3875d |
|
BLAKE2b-256 | b42f2ff006a60c85078566e11547aa8dc4252dd5d560103b51800173b0aacc46 |