Skip to content

Instantly share code, notes, and snippets.

@szastupov
Created April 18, 2017 01:11
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 szastupov/e74213a3def0afa26caa7c0c92c6b2f6 to your computer and use it in GitHub Desktop.
Save szastupov/e74213a3def0afa26caa7c0c92c6b2f6 to your computer and use it in GitHub Desktop.
import sqlalchemy as sa
from sqlalchemy.ext.declarative import as_declarative, declared_attr
from sqlalchemy.orm import relationship, sessionmaker
engine = sa.create_engine('sqlite://')
Session = sessionmaker(bind=engine)
@as_declarative()
class Base(object):
@declared_attr
def __tablename__(cls):
return cls.__name__.lower() + 's'
id = sa.Column(sa.Integer, primary_key=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment