Created
January 10, 2014 01:31
-
-
Save irskep/8345460 to your computer and use it in GitHub Desktop.
This file contains 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.ext.declarative import declarative_base | |
from sqlalchemy.orm.session import Session | |
from sqlalchemy import ( | |
create_engine, | |
Column, | |
Integer, | |
UnicodeText, | |
) | |
Base = declarative_base() | |
class DemoTable(Base): | |
__tablename__ = 'demo_table' | |
id = Column(Integer(), primary_key=True) | |
unicode_text = Column(UnicodeText()) | |
# there's probably a simpler way to configure all this | |
engine = create_engine( | |
'mysql://root:@blah/the_database?charset=utf8', | |
encoding='utf8') | |
Base.metadata.create_all(bind=engine) | |
session = Session(bind=engine) | |
### THE MEAT ### | |
session.add(DemoTable(unicode_text=u"What a lovely day")) | |
session.flush() | |
session.expire_all() | |
print type(session.query(DemoTable).first().unicode_text) | |
# <type 'str'> | |
engine.dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment