当前位置: 首页>>代码示例>>Python>>正文


Python Model.execute方法代码示例

本文整理汇总了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"
开发者ID:mrrainwater,项目名称:CookieMonster,代码行数:56,代码来源:views.py

示例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)
开发者ID:mrrainwater,项目名称:CookieMonster,代码行数:20,代码来源:views.py

示例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'])
开发者ID:perryhau,项目名称:taobao-abc,代码行数:5,代码来源:shop.py


注:本文中的model.Model.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。