Skip to content

Instantly share code, notes, and snippets.

@khanhicetea
Created June 15, 2017 04:45
Show Gist options
  • Save khanhicetea/fd849cc67c41fe49299116037825af94 to your computer and use it in GitHub Desktop.
Save khanhicetea/fd849cc67c41fe49299116037825af94 to your computer and use it in GitHub Desktop.
Flash and SQLAlchemy test
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:passwd@127.0.0.1/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()
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
@her0e1c1
Copy link

HOGEHOGE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment