Skip to main content

Objection Relation Model Maker for SQLAlchemy

Project description

ORM Maker

ORM Maker makes an Object Relational Model from a comma separated values (csv) file - see the example.csv file which is used to produce the example.py file.

Example Input

schema,table,column,type,enumeration,linked_field,key,repr,nullable,note
main,!,id,Uuid,,,1,0,0,all tables will have a field called 'id' that is a primary key
main,!,revby,Uuid,,people.id,0,1,0,all tables will have a field called 'revby' that is linked to the people table.
main,!,revdate,DateTime,,,0,1,0,all tables will have a field called 'revdate' that is a DateTime type
main,!,valid,String,valid|not valid|to validate,,0,1,1,test the enumeration capability in the base class
main,cars,make,String,,,0,1,1,
main,cars,model,String,,,0,1,1,
main,cars,year,Integer,,,0,1,1,
main,cars,made_on,DateTime,,,0,1,1,
main,cars,seats,List,,,0,0,1,
main,tires,rubber,String,,cars.name,0,1,1,
main,tires,position,String,left_front|right_front|left_back|right_back,,,1,1,
main,tires,made_on,DateTime,,,,1,1,
main,tires,car_id,String,,cars.id,0,0,0,which car does this tire belong to
main,people,first,String,,,,1,1,
main,people,relatives,Dictionary,,,,,1,

Example Output

'''
This module was made by shout on 2025-05-04 19:59:29.324568-04:00,
using orm-maker v0.1.17,
input file: <bound method Path.absolute of PosixPath('/Users/shout/Documents/Code/Python/orm_maker/example/example.csv')>
'''

from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy import Uuid
from sqlalchemy import create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
from typing import List, Optional, Dict, ClassVar
import datetime
import enum
import sqlalchemy
import uuid

class BASE_VALID(enum.Enum):
    VALID = 0
    NOT_VALID = 1
    TO_VALIDATE = 2

class TIRES_POSITION(enum.Enum):
    LEFT_FRONT = 0
    RIGHT_FRONT = 1
    LEFT_BACK = 2
    RIGHT_BACK = 3

class Base(DeclarativeBase):
    id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=lambda: uuid.uuid4())
    revby: Mapped[uuid.UUID] = mapped_column()
    revdate: Mapped[datetime.datetime] = mapped_column()
    valid: Mapped[Optional[BASE_VALID]] = mapped_column(sqlalchemy.Enum(BASE_VALID))

class CARS(Base):

    __tablename__ = 'cars'
    __table_args__ = {'schema': 'main'}
    made_on: Mapped[Optional[datetime.datetime]] = mapped_column()
    make: Mapped[Optional[str]] = mapped_column()
    model: Mapped[Optional[str]] = mapped_column()
    name: Mapped[str] = mapped_column()
    seats: ClassVar[Optional[list]]
    year: Mapped[Optional[int]] = mapped_column()

    def __repr__(self) -> str:
        return f'<CARS=(made_on={self.made_on}, make={self.make}, model={self.model}, year={self.year})>'

class PEOPLE(Base):

    __tablename__ = 'people'
    __table_args__ = {'schema': 'main'}
    first: Mapped[Optional[str]] = mapped_column()
    relatives: ClassVar[Optional[dict]]

    def __repr__(self) -> str:
        return f'<PEOPLE=(first={self.first})>'

class TIRES(Base):

    __tablename__ = 'tires'
    __table_args__ = {'schema': 'main'}
    car_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey('main.cars.id'))
    cars = relationship('CARS' , foreign_keys=[car_id])
    made_on: Mapped[Optional[datetime.datetime]] = mapped_column()
    position: Mapped[Optional[TIRES_POSITION]] = mapped_column(sqlalchemy.Enum(TIRES_POSITION))
    rubber: Mapped[Optional[str]] = mapped_column(String, ForeignKey('main.cars.name'))
    cars = relationship('CARS' , foreign_keys=[rubber])

    def __repr__(self) -> str:
        return f'<TIRES=(made_on={self.made_on}, position={self.position}, rubber={self.rubber})>'


def make_db():
    engine = create_engine('sqlite:////Users/shout/Documents/Code/Python/orm_maker/example/example.sqlite', echo=True)
    Base.metadata.create_all(engine)

def main():
    make_db()

if __name__ == '__main__':
    main()

Supported ORMs

  • SQL Alchemy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orm_maker-0.1.29.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orm_maker-0.1.29-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file orm_maker-0.1.29.tar.gz.

File metadata

  • Download URL: orm_maker-0.1.29.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.4.0

File hashes

Hashes for orm_maker-0.1.29.tar.gz
Algorithm Hash digest
SHA256 a8948beb40281886b59ba5f271b800ab78adef0a4c1db4479d9729ad6ea2f129
MD5 310fd579755b9c6e4f34e3f4dc014b94
BLAKE2b-256 8bc3506607ad8265a0225ea17c4e20fd482f72c3c2ba7825148e4f97857a2d84

See more details on using hashes here.

File details

Details for the file orm_maker-0.1.29-py3-none-any.whl.

File metadata

  • Download URL: orm_maker-0.1.29-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.4.0

File hashes

Hashes for orm_maker-0.1.29-py3-none-any.whl
Algorithm Hash digest
SHA256 a7d97bfacdf4d38dabc0f135a7069de4fbcd7915738b3e1144b8b44232de3c15
MD5 6a83ebaf3a91dec7e42e5c3210ac5a34
BLAKE2b-256 0ab452858c4e7e3d4611acdc1042da3ef56c13ec4076069f2ece0d22c94cf4cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page