<s> '''<STR_LIT>''' <EOL> import datetime <EOL> from sqlalchemy import Column , ForeignKey , MetaData , Table , create_engine <EOL> from sqlalchemy . ext . declarative import declarative_base <EOL> from sqlalchemy . orm import mapper , relationship , sessionmaker <EOL> from sqlalchemy . types import INTEGER , BigInteger , DateTime , Float , String <EOL> engine = create_engine ( '<STR_LIT>' , echo = False ) <EOL> Base = declarative_base ( ) <EOL> Session = sessionmaker ( bind = engine ) <EOL> Session . configure ( bind = engine ) <EOL> metadata = MetaData ( ) <EOL> cls_test = Table ( '<STR_LIT>' , metadata , <EOL> Column ( u'<STR_LIT>' , INTEGER ( ) , primary_key = True ) , <EOL> Column ( u'<STR_LIT>' , String ) <EOL> ) <EOL> class ChildModel ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> childmodel_id = Column ( INTEGER , primary_key = True ) <EOL> parent_id = Column ( INTEGER , <EOL> ForeignKey ( "<STR_LIT>" ) , <EOL> primary_key = True , ) <EOL> class DeclarativeModel ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> declarativemodel_id = Column ( INTEGER , primary_key = True ) <EOL> field = Column ( String ) <EOL> datetime = Column ( DateTime , default = datetime . datetime . utcnow ) <EOL> floatfield = Column ( Float ) <EOL> bigintfield = Column ( BigInteger ) <EOL> child_model = relationship ( ChildModel , uselist = False , <EOL> primaryjoin = ( declarativemodel_id == ChildModel . parent_id ) ) <EOL> class CompositeKeysModel ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> pk1 = Column ( String , primary_key = True ) <EOL> pk2 = Column ( String , primary_key = True ) <EOL> compositekeysmodel_id = Column ( INTEGER , primary_key = True ) <EOL> field = Column ( String ) <EOL> class ClassicalModel ( object ) : <EOL> pass <EOL> mapper ( ClassicalModel , cls_test ) <EOL> Base . metadata . create_all ( bind = engine ) <EOL> metadata . create_all ( bind = engine ) <EOL> t = DeclarativeModel ( ) <EOL> t . declarativemodel_id = <NUM_LIT:1> <EOL> t . field = "<STR_LIT:test>" <EOL> t . floatfield = <NUM_LIT> <EOL> t . bigintfield = <NUM_LIT> <EOL> t . child_model = ChildModel ( ) <EOL> t . child_model . childmodel_id = <NUM_LIT:2> <EOL> t . child_model . parent_id = <NUM_LIT:1> <EOL> session = Session ( ) <EOL> session . add ( t ) <EOL> session . commit ( ) <EOL> c = CompositeKeysModel ( ) <EOL> c . compositekeysmodel_id = <NUM_LIT:1> <EOL> c . pk1 = '<STR_LIT>' <EOL> c . pk2 = '<STR_LIT>' <EOL> session . add ( c ) <EOL> session . commit ( ) <EOL> cl = ClassicalModel ( ) <EOL> cl . classicalmodel_id = <NUM_LIT:1> <EOL> cl . field = '<STR_LIT:test>' <EOL> session . add ( cl ) <EOL> session . commit ( ) <EOL> class SessionMixin ( object ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . session = Session ( ) <EOL> super ( SessionMixin , self ) . __init__ ( * args , ** kwargs ) </s>
