-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cf6af5
commit af5567d
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Quart-Peewee | ||
|
||
Integration between the [Quart](https://github.com/pallets/quart) web framework and the [Peewee ORM](https://github.com/coleifer/peewee) through the [Peewee-AIO](https://github.com/klen/peewee-aio) | ||
|
||
## Usage | ||
|
||
```python | ||
from peewee_aio.fields import CharField | ||
from quart import Quart, request | ||
|
||
from quart_peewee import QuartPeewee | ||
|
||
app = Quart(__name__) | ||
db = QuartPeewee("aiosqlite:///app.db") | ||
db.init_app(app) | ||
|
||
|
||
class User(db.Model): | ||
name = CharField(unique=True) | ||
|
||
|
||
@app.before_serving | ||
async def before_serving(): | ||
await db.create_tables() | ||
|
||
|
||
@app.route("/create_user", methods=["POST"]) | ||
async def create_user(): | ||
data = await request.get_json(force=True) | ||
await User.create(name=data["name"]) | ||
return "" | ||
|
||
|
||
@app.route("/get_users", methods=["GET"]) | ||
async def get_users(): | ||
return await User.select().dicts() | ||
|
||
|
||
@app.route("/delete_user", methods=["DELETE"]) | ||
async def delete_user(): | ||
data = await request.get_json(force=True) | ||
await User.delete().where(User.name == data["name"]) | ||
return "" | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run() | ||
``` |