Convert pydal define_tables to SQL using pydal's CREATE TABLE logic
Project description
pydal2sql
Convert pydal define_tables to SQL using pydal's CREATE TABLE logic
Table of Contents
Example
from pydal import DAL, Field
from pydal2sql import generate_sql
db = DAL(None, migrate=False) # <- without running database or with a different type of database
db.define_table(
"person",
Field(
"name",
"string",
nullable=False,
),
Field("age", "integer", default=18),
Field("float", "decimal(2,3)"),
Field("nicknames", "list:string"),
Field("obj", "json"),
)
print(
generate_sql(
db.person, db_type="psql" # or sqlite, or mysql; Optional with fallback to currently using database type.
)
)
CREATE TABLE person
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(512),
age INTEGER,
float NUMERIC(2, 3),
nicknames TEXT,
obj TEXT
);
Installation
pip install pydal2sql
cli
# model_fragment.py
db.define_table(
"person",
Field(...)
)
# optionally:
# db_type = 'postgres'
# tables = ['person']
cat model_fragment.py | pydal2sql # without cli args if settings are set in code, or
cat model_fragment.py | pydal2sql postgres --table person # with args if settings are not in code
# both output the CREATE TABLE statements to stdout.
License
pydal2sql
is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydal2sql-0.2.1.tar.gz
(44.1 kB
view hashes)
Built Distribution
Close
Hashes for pydal2sql-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 671d19eaeaeb6c7d75e48688df76af6aa50dcecdd93e5f0c58bfaad54b6de76c |
|
MD5 | de50edb876d524bf8693135867839dc6 |
|
BLAKE2b-256 | 9490e1bb52b8ab45f502f42147e714ae08a59acfdff893ac3d7b799ec8755ef0 |