Generate SQLModel code from SQL
Project description
sqlmodelgen
sqlmodelgen is a library to convert CREATE TABLE statements from SQL to classes inheriting SQLModel from the famous sqlmodel library.
Example
from sqlmodelgen import gen_code_from_sql
sql_code = '''
CREATE TABLE Hero (
id INTEGER NOT NULL,
name VARCHAR NOT NULL,
secret_name VARCHAR NOT NULL,
age INTEGER,
PRIMARY KEY (id)
);
print(gen_code_from_sql(sql_code))
'''
generates:
from sqlmodel import SQLModel, Field
class Hero(SQLModel, table = True):
__tablename__ = 'Hero'
id: int = Field(primary_key=True)
name: str
secret_name: str
age: int | None
Internal functioning
The library relies on sqloxide to parse SQL code, then generates sqlmodel classes accordingly
Possible improvements
- Support for more SQL data types
- Possibility to acquire in input actual database connections (like Postgres) or files (SQLite) and generate sqlmodel code accordingly
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
sqlmodelgen-0.0.4.tar.gz
(17.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlmodelgen-0.0.4.tar.gz.
File metadata
- Download URL: sqlmodelgen-0.0.4.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7b29fa328c8a9e1d0560699492bdd5dd14a19ea8ea746193b06249e7157fb0a
|
|
| MD5 |
2b6525188bcfb1cf79a2c6bc77b0dcc9
|
|
| BLAKE2b-256 |
4a85174bd819e284397919bb433a26d01043bb7f9028e8a8419696cf1bac6205
|
File details
Details for the file sqlmodelgen-0.0.4-py3-none-any.whl.
File metadata
- Download URL: sqlmodelgen-0.0.4-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae8b5a8435b0d54fa8d6f36d1498e4f56382c72e223c33b0dcfe83cd8894d4b1
|
|
| MD5 |
29216b705e2bf59b3009d83d68d20585
|
|
| BLAKE2b-256 |
e4b003d8f73b3282d89d1d676c5587b9b73cb5077d56968f946f11234ada5fc1
|