Skip to content

Instantly share code, notes, and snippets.

@bbinet
Created September 24, 2012 14:10
Show Gist options
  • Save bbinet/3776134 to your computer and use it in GitHub Desktop.
Save bbinet/3776134 to your computer and use it in GitHub Desktop.
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Index
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.types import Integer, String
Base = declarative_base()
Base.metadata.bind = "postgres://user:pass@localhost/sqla_test"
meta = Base.metadata
session = scoped_session(sessionmaker(bind=meta.bind))()
class Test(Base):
__tablename__ = 'test'
__table_args__ = {
'schema': 'app'
}
id = Column(Integer, primary_key=True)
name = Column(String(20))
meta.drop_all()
meta.create_all()
i = Index('my_idx', Test.__table__.c.name)
i.create()
i.drop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment