O! My Models (omymodels) is a library to generate from SQL DDL Python Models for GinoORM.
Project description
O! My Models
O! My Models (omymodels) is a library to generate from SQL DDL Python Models for GinoORM (I hope to add several more ORMs in future).
You provide an input like:
CREATE TABLE "users" (
"id" SERIAL PRIMARY KEY,
"name" varchar,
"created_at" timestamp,
"updated_at" timestamp,
"country_code" int,
"default_language" int
);
CREATE TABLE "languages" (
"id" int PRIMARY KEY,
"code" varchar(2) NOT NULL,
"name" varchar NOT NULL
);
and you will get output:
from gino import Gino
db = Gino()
class Users(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer(), autoincrement=True, primary_key=True)
name = db.Column(db.String())
created_at = db.Column(db.TIMESTAMP())
updated_at = db.Column(db.TIMESTAMP())
country_code = db.Column(db.Integer())
default_language = db.Column(db.Integer())
class Languages(db.Model):
__tablename__ = 'languages'
id = db.Column(db.Integer(), primary_key=True)
code = db.Column(db.String(2))
name = db.Column(db.String())
How to install
pip install omymodels
How to use
From cli
omm path/to/your.ddl
# for example
omm tests/test_two_tables.sql
You can define target path where to save models with -t, –target flag:
# for example
omm tests/test_two_tables.sql -t test_path/test_models.py
Small library is used for parse DDL- https://github.com/xnuinside/simple-ddl-parser.
What to do if types not supported in O! My Models and you cannot wait until PR will be approved
First of all, to parse types correct from DDL to models - they must be in types mypping, for Gino it exitst in this file:
omymodels/gino/types.py types_mapping
If you need to use fast type that not exist in mapping - just do a path before call code with types_mapping.update()
for example:
from omymodels.gino import types types_mapping
from omymodels import create_gino_models
types.types_mapping.update({'your_type_from_ddl': 'db.TypeInGino'})
ddl = "YOUR DDL with your custom your_type_from_ddl"
models = create_gino_models(ddl)
How to contribute
Please describe issue that you want to solve and open the PR, I will review it as soon as possible.
Any questions? Ping me in Telegram: https://t.me/xnuinside
Changelog
v0.2.0
Valid generating columns in models: autoincrement, default, type, arrays, unique, primary key and etc.
Added creating table_args for indexes
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
Built Distribution
File details
Details for the file omymodels-0.2.0a0.tar.gz
.
File metadata
- Download URL: omymodels-0.2.0a0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.7 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28c44ae991e37d6241a5b3fe5277b608798f6ab0ba7c4f252c5a4637b1dc1779 |
|
MD5 | 5f56f49996c2f24fcd38d025c0bfd51f |
|
BLAKE2b-256 | dd100089da39df6c1efc9ca92f05d787a01aaa8eb934837b384ae37f38b60bba |
File details
Details for the file omymodels-0.2.0a0-py3-none-any.whl
.
File metadata
- Download URL: omymodels-0.2.0a0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.7 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b68e47dd975eef22a2bc926787439a3c9f6e81d7df321bb373e8de1803f19a1a |
|
MD5 | dc72484b47ec5ca93c5d9c2540f4987c |
|
BLAKE2b-256 | e931c1ae95cd65d8034d8eb78fc1951e4655c5c39f6e862affc6a483fe423ba6 |