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.
Metadata
Release files for pydal2sql-core 0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydal2sql_core-0.7.2.tar.gz | 118.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydal2sql_core-0.7.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 144.0 kB
Release files / pydal2sql_core-0.7.2.tar.gz
| Download URL | pydal2sql_core-0.7.2.tar.gz |
|---|---|
| Size | 118.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6462ec8c8dedfeddbeda8a8eb93a921947590398141a565315bbe114605d8a0
|
|
BLAKE2b-256 checksum How to use checksums |
e194aa1cba830e5bf4ba1f908dc3e766ee93eeb3989b91364a616aec1618666a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / pydal2sql_core-0.7.2-py3-none-any.whl
| Download URL | pydal2sql_core-0.7.2-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6d3afd695a7acdd55166637ea509fa82031029b4861d95e2c8316432b81737f
|
|
BLAKE2b-256 checksum How to use checksums |
4c1e26fde706adfee0690fca134b0cb3aa7c6a092a793126dc9c2fd6a90fa04e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|