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
| #!/usr/bin/env python | |
| #-*- coding:utf8 -*- | |
| from datetime import datetime | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import scoped_session, sessionmaker | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy import Column, Integer, Date | |
| from sqlalchemy.dialects.mysql import TIMESTAMP | |
| from sqlalchemy.types import TypeDecorator |
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
| #!/bin/sh | |
| ######################################## | |
| # easy install lokka on heroku for MacOS | |
| # | |
| # filename: herokka1.sh | |
| # | |
| # dependencies | |
| # - heroku account | |
| # - bash |
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
| #!/bin/sh | |
| ######################################## | |
| # easy install lokka on heroku for MacOS | |
| # | |
| # filename: herokka2.sh | |
| # | |
| # dependencies | |
| # - heroku account | |
| # - bash |
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
| ######################################## | |
| # easy install Ricty Font for MacOSX(Lion) | |
| # | |
| # filename: install_ricty.sh | |
| # | |
| # dependencies | |
| # - homebrew | |
| # | |
| # see also | |
| # - http://knagayama.net/blog/2011/07/27/generate-ricty-font/ |
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
| #!/bin/sh | |
| ######################################## | |
| # Setup Flaskr on Heroku with Amazon RDS | |
| # | |
| # filename: setup_flaskr_on_heroku.sh | |
| # | |
| # dependencies: | |
| # - heroku account | |
| # - bash |
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
| import sys | |
| print sys.builtin_module_names | |
| #=> ('__builtin__', '__main__', '_ast', '_codecs', '_sre', '_symtable', '_warnings', '_weakref', 'errno', 'exceptions', 'gc', 'imp', 'marshal', 'posix', 'pwd', 'signal', 'sys', 'thread', 'xxsubtype', 'zipimport') |
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
| # テーブルを表現するオブジェクト | |
| entry_table = Table( | |
| 'entries', metadata, | |
| Column("id", Integer, primary_key=True), | |
| Column("text", String(200)), | |
| Column("created_at", DateTime, default=datetime.now, nullable=False) | |
| ) | |
| # Tableオブジェクトとマッピングされるクラス |
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
| 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) |
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
| db_session = scoped_session(sessionmaker(bind=engine)) | |
| db_session.add(Entry(id=1, text="entrytext")) # <= Insert | |
| db_session.add(Entry(id=2, text="entrytext")) # <= Insert | |
| db_session.flush() # <= このタイミングでDBに反映 |
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
| # Batch Insert | |
| INSERT INTO entries (id, text, created_at) VALUES (%s, %s, %s) | |
| ((1, 'entrytext', datetime.datetime(2012, 9, 13, 23, 8, 38, 370579)), (2, 'entrytext', datetime.datetime(2012, 9, 13, 23, 8, 38, 370587))) |
OlderNewer