Skip to content

Commit

Permalink
flask, sqlalchemy and locust
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Mar 14, 2022
1 parent 3ec34a5 commit 23b2b61
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
39 changes: 39 additions & 0 deletions python/flask_sqlalchemy/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sentry_sdk
from flask import Flask
from flask_sqlalchemy import SQLAlchemy


sentry_sdk.init(
traces_sample_rate=1.0,
send_default_pii=True,
debug=True
)


app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.sqlite"
db = SQLAlchemy(app)


class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String, unique=False, nullable=False)


@app.route("/insert")
def insert():
db.session.add(User(username="Flask"))
db.session.commit()
return "<p>inserted!</p>"


@app.route("/count")
def count():
count = User.query.count()
return f"<p>count: {count} </p>"



if __name__ == "__main__":
# db.create_all() # uncomment for first time
app.run()
Binary file added python/flask_sqlalchemy/example.sqlite
Binary file not shown.
7 changes: 7 additions & 0 deletions python/flask_sqlalchemy/locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from locust import HttpUser, task

class HelloWorldUser(HttpUser):
@task
def hello_world(self):
self.client.get("/insert")
self.client.get("/count")
16 changes: 16 additions & 0 deletions python/flask_sqlalchemy/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
blinker==1.4
certifi==2021.10.8
click==8.0.4
Flask==2.0.3
Flask-SQLAlchemy==2.5.1
greenlet==1.1.2
importlib-metadata==4.11.3
itsdangerous==2.1.1
Jinja2==3.0.3
MarkupSafe==2.1.0
-e git+git@github.com:getsentry/sentry-python.git@a6cec41a2f4889d54339d3249db1acbe0c680e46#egg=sentry_sdk
SQLAlchemy==1.4.32
typing-extensions==4.1.1
urllib3==1.26.8
Werkzeug==2.0.3
zipp==3.7.0

0 comments on commit 23b2b61

Please sign in to comment.