Skip to content

Instantly share code, notes, and snippets.

@tell-k
Created September 13, 2012 10:59
Show Gist options
  • Save tell-k/3713577 to your computer and use it in GitHub Desktop.
Save tell-k/3713577 to your computer and use it in GitHub Desktop.
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