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.5.tar.gz
(24.0 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.5.tar.gz.
File metadata
- Download URL: sqlmodelgen-0.0.5.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.30
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90b2adc9becd0fbf9fdc67a87a3cb19b082244882f4f693a021c136666605562
|
|
| MD5 |
0571ba13fa2449cbbe5b9c227116d58c
|
|
| BLAKE2b-256 |
f079cf39a0920977948ba65cf3c2b17f22838c6829042468f6ae4b6bcac7b441
|
File details
Details for the file sqlmodelgen-0.0.5-py3-none-any.whl.
File metadata
- Download URL: sqlmodelgen-0.0.5-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.30
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aee8da1f317f702eb2d3338225698f1e6527c641d20f033f49e968274aedc19e
|
|
| MD5 |
a69b08186289c33c5623e8239634d341
|
|
| BLAKE2b-256 |
3c311bbac87fc20495475cb4d1453e5a935bb14af5c68e679bcffca82c8846f8
|