Created
September 12, 2014 16:35
-
-
Save fcofdez/283e672a7b3312a977ef to your computer and use it in GitHub Desktop.
sqlalcheym
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import * | |
from sqlalchemy.orm import * | |
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
class A(Base): | |
__tablename__ = 'a' | |
id = Column(Integer, primary_key=True) | |
data = Column(String, | |
server_default=FetchedValue()) | |
__mapper_args__ = { | |
"eager_defaults": True # should not be needed | |
} | |
# should work whether or not this is set | |
# __table_args__ = {"implicit_returning": False} | |
engine = create_engine("postgresql://scott:tiger@localhost/test", echo=True) | |
Base.metadata.drop_all(engine) | |
engine.execute("create table a (id serial primary key, data varchar)") | |
engine.execute("ALTER TABLE a ALTER COLUMN data SET DEFAULT concat(md5(CAST(random() AS TEXT)), '2')") | |
s = Session(engine) | |
a1 = A() | |
s.add(a1) | |
s.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment