Created
June 15, 2017 04:45
-
-
Save khanhicetea/fd849cc67c41fe49299116037825af94 to your computer and use it in GitHub Desktop.
Flash and SQLAlchemy test
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 flask import Flask, request | |
from sqlalchemy import create_engine | |
from sqlalchemy.orm import sessionmaker | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, String, ForeignKey | |
import time | |
app = Flask(__name__) | |
Session = sessionmaker(bind=create_engine("mysql://root:[email protected]/test")) | |
session = Session() | |
Base = declarative_base() | |
class Person(Base): | |
__tablename__ = 'person' | |
id = Column(Integer, primary_key=True) | |
name = Column(String) | |
@app.route("/request1") | |
def request1(): | |
result = session.query(Person).all() | |
result[0].name = "HOGE HOGE :))" | |
time.sleep(20) # delays for 20 seconds like a heavy task | |
session.commit() | |
return "Request 1 is done" | |
@app.route("/request2") | |
def request2(): | |
session.commit() | |
return "Request 2 is done" | |
if __name__ == "__main__": | |
app.run() |
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
click==6.7 | |
Flask==0.12.2 | |
gunicorn==19.7.1 | |
itsdangerous==0.24 | |
Jinja2==2.9.6 | |
MarkupSafe==1.0 | |
MySQL-python==1.2.5 | |
pkg-resources==0.0.0 | |
SQLAlchemy==1.1.10 | |
Werkzeug==0.12.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HOGEHOGE