Skip to content

Instantly share code, notes, and snippets.

@Drvanon
Created May 6, 2013 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drvanon/5524876 to your computer and use it in GitHub Desktop.
Save Drvanon/5524876 to your computer and use it in GitHub Desktop.
Sqlalchemy template, because I hate repeating myself
from sqlalchemy import create_engine, Column, Integer, String # , ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker # , relationship, backref
engine = create_engine('sqlite://:memory:')
Base = declarative_base()
# Table classes here
# example:
# class Reaction(Base):
# __tablename__ = 'reactions'
#
# id = Column(Integer, primary_key=True)
# content = Column(String)
#
# def __init__(self, content):
# self.content = content
#
# def __repr__(self):
# return '<Reaction {0}'.format(self.content[:5]
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment