本文整理汇总了Python中model.Model.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Model.execute方法的具体用法?Python Model.execute怎么用?Python Model.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Model
的用法示例。
在下文中一共展示了Model.execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import execute [as 别名]
def show(buyer_id):
#find buyer with buyer_id
if request.method == 'GET':
buyer = Model.execute('SELECT first, last, id FROM buyers WHERE id={}'.format(buyer_id)).fetchone()
print("GET BUYER:", buyer)
buyer = {
"name": "{} {}".format(buyer[0], buyer[1]),
"id": buyer[2]
}
orders = []
for order in Model.execute('SELECT id, buyer, description, total FROM buyer_orders WHERE buyer={}'.format(buyer_id)):
print("ORDER:", order)
oid = order[0]
order = {
"id": order[0],
"description": order[2],
"total": order[3]
}
purchases = []
for p in Model.execute('SELECT cookie, warehouse, buyer_order, amount FROM purchases WHERE buyer_order={}'.format(oid)):
p = {
"cookie": p[0],
"warehouse": p[1],
"amount": p[3]
}
purchases.append(p)
order["purchases"] = purchases
orders.append(order)
buyer["orders"] = orders
return jsonify(**buyer)
if request.method == 'PUT':
update = request.get_json()
first, last = update["name"].split(" ")
#update buyer with this information
conn, cur = Model.make_cursor()
cur.execute('''
UPDATE buyers
SET first="{}", last="{}"
WHERE id={}
'''.format(first, last, buyer_id))
conn.commit()
return "OK"
if request.method == 'DELETE':
#delete buyer with id = buyer_id
conn, cur = Model.make_cursor()
cur.execute('DELETE FROM buyers WHERE id={}'.format(buyer_id))
conn.commit()
return "OK"
示例2: index
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import execute [as 别名]
def index():
if request.method == 'GET':
buyers = []
for buyer in Model.execute('SELECT first, last, id FROM buyers'):
buyer = {
"name": "{} {}".format(buyer[0], buyer[1]),
"id": buyer[2]
}
buyers.append(buyer)
print("INDEX BUYER:", buyer)
return render_template('buyers/index.html', buyers=buyers)
if request.method == 'POST':
buyer = request.get_json()
first, last = buyer["name"].split()
Model.insert_in("buyers", first=first, last=last)
#create buyer
return jsonify(**buyer)
示例3: create
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import execute [as 别名]
def create(shop):
stmt = "INSERT INTO shop(user_id, nick, sid, cid, title) VALUES(%s, %s, %s, %s, %s)"
Model.execute(stmt, shop['user_id'], shop['nick'], shop['sid'], shop['cid'], shop['title'])