-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
41 lines (33 loc) · 991 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Copyright Fauna, Inc.
# SPDX-License-Identifier: MIT-0
from flask import Flask
import os, json
from fauna import fql
from fauna.client import Client
from fauna.encoding import QuerySuccess
import utils
client = Client(secret=os.getenv("FAUNA_SECRET_KEY", "unknown"))
app = Flask(__name__)
@app.route("/")
def index():
return json.dumps({"greeting": "Hello python-fly-io-starter"})
@app.route("/read", methods=["GET"])
def read():
try:
q = fql(
"""
order.all() {
orderName: .name,
customer: .customer.firstName + " " + .customer.lastName,
orderProducts {
product: .product.name,
price,
quantity
}
}
"""
)
res: QuerySuccess = client.query(q)
return utils.generate_response(res)
except Exception as e:
return utils.generate_error_response(e)