Created
September 13, 2012 10:59
-
-
Save tell-k/3713577 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
Base = declarative_base() # <= これ | |
Base.query = db_session.query_property() | |
Base.metadata = metadata | |
# 宣言的にテーブルを定義 | |
class Entry(Base): | |
__tablename__ = 'entries' | |
id = Column(Integer, primary_key=True) | |
text = Column(String(200)) | |
created_at = Column(DateTime, default=datetime.now, nullable=False) | |
# テーブル作成 | |
Base.metadata.create_all() | |
entry = Entry(id=1, text="entrytext") # オブジェクト生成 | |
db_session.add(entry) # DBにインサート | |
db_session.commit() | |
entry = Entry.query.first() # データの取得 | |
print entry.text # => "entrytext" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment