CLI-agnostic pydal2sql code; Convert pydal define_tables to SQL using pydal's CREATE TABLE logic.
Project description
pydal2sql-core
Companion library for pydal2sql
containing the actual logic.
The other library only serves as a Typer-based CLI front-end.
More Documentation coming soon!
Table of Contents
Installation
pip install pydal2sql-core
As a Python Library
pydal2sql-core
also exposes a generate_sql
method that can perform the same actions on one (for CREATE) or two (for
ALTER) pydal.Table
objects when used within Python.
from pydal import DAL, Field
from pydal2sql_core import generate_sql
db = DAL(None, migrate=False) # <- without running database or with a different type of database
person_initial = db.define_table(
"person",
Field(
"name",
"string",
notnull=True,
),
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
);
person_new = db.define_table(
"person",
Field(
"name",
"text",
),
Field("birthday", "datetime"),
redefine=True
)
generate_sql(
person_initial,
person_new,
db_type="psql"
)
ALTER TABLE person
ADD "name__tmp" TEXT;
UPDATE person
SET "name__tmp"=name;
ALTER TABLE person DROP COLUMN name;
ALTER TABLE person
ADD name TEXT;
UPDATE person
SET name="name__tmp";
ALTER TABLE person DROP COLUMN "name__tmp";
ALTER TABLE person
ADD birthday TIMESTAMP;
ALTER TABLE person DROP COLUMN age;
ALTER TABLE person DROP COLUMN float;
ALTER TABLE person DROP COLUMN nicknames;
ALTER TABLE person DROP COLUMN obj;
License
pydal2sql-core
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_core-0.3.2.tar.gz
(143.3 kB
view details)
Built Distribution
File details
Details for the file pydal2sql_core-0.3.2.tar.gz
.
File metadata
- Download URL: pydal2sql_core-0.3.2.tar.gz
- Upload date:
- Size: 143.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df6e23bfad82e26f426851c6b9b46422d3b24104af22c293c0fb0b89645977d7 |
|
MD5 | 6a9effce44a8b277dc51c706e49c5824 |
|
BLAKE2b-256 | a3410923b4b2f8663bb28f43e6c5b1fd401cb400b6960ea2c15b4171c29dcad2 |
Provenance
File details
Details for the file pydal2sql_core-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: pydal2sql_core-0.3.2-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fd5fa055003d4c5a9a2820376d9fd3e353d9f1578fbe58c6c0625b9b640f06a |
|
MD5 | 90d62e71215f2202205f29093a9e4ea6 |
|
BLAKE2b-256 | 0a4a0a3390e7ff9277c3d842b34309ab0a66f1a67f47567c0ccd0a9f63cdf488 |