Try using SQLACodeGen. Just point it at your database, and it'll generate all the SQLA models for you, then you can tweak it as required— it's a big time saver.
SQLAlchemy can also reflect existing tables if you prefer the discovery route at runtime.
Here's a quick example for using SQLACodeGen:
sqlacodegen postgresql:///example_database --tables car
Outputs:
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class Car(Base):
__tablename__ = 'car'
id = Column(Integer, primary_key=True)
price = Column(Integer)
color_id = Column(ForeignKey('color.id'))
color = relationship(u'Color')
class Color(Base):
__tablename__ = 'color'
id = Column(Integer, primary_key=True)
name = Column(String(50))
Try using SQLACodeGen. Just point it at your database, and it'll generate all the SQLA models for you, then you can tweak it as required— it's a big time saver.
SQLAlchemy can also reflect existing tables if you prefer the discovery route at runtime.
Try using SQLACodeGen. Just point it at your database, and it'll generate all the SQLA models for you, then you can tweak it as required— it's a big time saver.
SQLAlchemy can also reflect existing tables if you prefer the discovery route at runtime.
Here's a quick example for using SQLACodeGen:
sqlacodegen postgresql:///example_database --tables car
Outputs:
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class Car(Base):
__tablename__ = 'car'
id = Column(Integer, primary_key=True)
price = Column(Integer)
color_id = Column(ForeignKey('color.id'))
color = relationship(u'Color')
class Color(Base):
__tablename__ = 'color'
id = Column(Integer, primary_key=True)
name = Column(String(50))
Try using SQLAutoCode SQLACodeGen. Just point it at your database, and it'll generate all the SQLA models for you, then you can tweak it as required— it's a big time saver.
SQLAlchemy can also reflect existing tables if you prefer the discovery route at runtime.
Try using SQLAutoCode. Just point it at your database, and it'll generate all the SQLA models for you, then you can tweak it as required— it's a big time saver.
SQLAlchemy can also reflect existing tables if you prefer the discovery route at runtime.
Try using SQLACodeGen. Just point it at your database, and it'll generate all the SQLA models for you, then you can tweak it as required— it's a big time saver.
SQLAlchemy can also reflect existing tables if you prefer the discovery route at runtime.
Try using SQLAutoCode. Just point it at your database, and it'll generate all the SQLA models for you, then you can tweak it as required— it's a big time saver.
SQLAlchemy can also reflect existing tables if you prefer the discovery route at runtime.