Skip to content

Instantly share code, notes, and snippets.

@joefutrelle
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save joefutrelle/fe4e361fc0f668e390bf to your computer and use it in GitHub Desktop.

Select an option

Save joefutrelle/fe4e361fc0f668e390bf to your computer and use it in GitHub Desktop.
SQLAlchemy ORM template
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, Numeric
from sqlalchemy.orm import backref, relationship
Base = declarative_base()
class Thing(Base):
__tablename__ = 'things'
id = Column(Integer, primary_key=True)
name = Column(String)
class Part(Base):
__tablename__ = 'parts'
id = Column(Integer, primary_key=True)
name = Column(String)
some_property = Column(Numeric)
thing = relationship('Thing',
backref=backref('parts', cascade='all, delete-orphan'))
# ...
engine = # ... get dbengine
Base.metadata.create_all(engine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment