本文整理汇总了Python中db.Db.select方法的典型用法代码示例。如果您正苦于以下问题:Python Db.select方法的具体用法?Python Db.select怎么用?Python Db.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Db
的用法示例。
在下文中一共展示了Db.select方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prets_fetchall
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def prets_fetchall():
db = Db()
result = db.select("SELECT * FROM prets")
db.close()
resp = make_response(json.dumps(result))
resp.mimetype = 'application/json'
return resp
示例2: afficher_utilisateurs
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def afficher_utilisateurs():
db=Db()
result=db.select('SELECT * FROM utilisateurs')
db.close()
resp = make_response(json.dumps(result),200)
resp.mimetype = 'application/json'
return resp
示例3: prets_fetchone
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def prets_fetchone(id):
db = Db()
result = db.select("SELECT * FROM prets WHERE id = %(id)s", {
'id': id
})
db.close()
if len(result) < 1:
return make_response("Not found", 404)
resp = make_response(json.dumps(result))
resp.mimetype = 'application/json'
return resp
示例4: pret_fetch
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def pret_fetch(pret_id):
db = Db()
result = db.select("SELECT * FROM prets WHERE prets.pret_id = %(pret_id)s", {
'pret_id': pret_id
})
db.close()
if len(result) == 1:
resp = make_response(json.dumps(result[0]))
else:
resp = make_response(json.dumps({'error': 'Given pret_id not found in database.'}), 404)
resp.mimetype = 'application/json'
return resp
示例5: utilisateurs_id
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def utilisateurs_id(id):
db=Db()
result = db.select('SELECT * FROM utilisateurs WHERE id = %(id)s', {
'id' : id
})
db.close()
if (len(result) != 1):
resp = make_response('Not Found', 404)
return resp
resp = make_response(json.dumps(result),200)
resp.mimetype = 'application/json'
return resp
示例6: user_add
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def user_add():
try :
data = request.get_json()
db = Db()
result = db.select("INSERT INTO users (nom, prenom) VALUES (%(nom)s,%(prenom)s) RETURNING id",{
'nom' : data['nom'],
'prenom' : data['prenom']
})
resp = make_response('', 201)
resp.mimetype = 'application/json'
resp.headers['Location'] = "/users/%d" % result[0]['id']
db.close()
return resp
except:
resp = make_response('', 400)
return resp
示例7: pret_add
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def pret_add():
try :
data = request.get_json()
db = Db()
result = db.select("INSERT INTO prets (qui, quoi, statut) VALUES (%(qui)s,%(quoi)s, %(statut)s) RETURNING id",{
'qui' : data['qui'],
'quoi' : data['quoi'],
'statut' : data['statut']
})
resp = make_response('', 201)
resp.mimetype = 'application/json'
resp.headers['Location'] = "/prets/%d" % result[0]['id']
db.close()
return resp
except:
resp = make_response('', 400)
return resp
示例8: ajout_prets
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def ajout_prets():
data = request.get_json ()
try:
db = Db()
result = db.select("INSERT INTO prets (quoi, qui, status) VALUES (%(quoi)s, %(qui)s, %(status)s) RETURNING id", {
'quoi': data["quoi"],
'qui': data["qui"],
'status': data ["status"]
})
db.close()
resp = make_response("OK",201)
resp.mimetype = 'text/plain'
resp.headers['Location'] = "/prets/%d" %result[0]['id']
return resp
except:
resp = make_response('Bad Request', 400)
return resp
示例9: pret_update
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import select [as 别名]
def pret_update(pret_id):
data = request.get_json()
db = Db()
pret = db.select("SELECT * FROM prets WHERE prets.pret_id = %(pret_id)s", {
'pret_id': pret_id
})
if len(pret) != 1:
db.close()
resp = make_response(json.dumps({'error': 'Given pret_id not found in database.'}), 404)
resp.mimetype = 'application/json'
return resp
pret = pret[0]
try:
pret['pret_quoi'] = data['pret_quoi']
except KeyError:
pass
try:
pret['pret_qui'] = data['pret_qui']
except KeyError:
pass
try:
pret['pret_etat'] = data['pret_etat']
except KeyError:
pass
db.execute('UPDATE prets SET pret_quoi = %(pret_quoi)s, pret_qui = %(pret_qui)s, pret_etat = %(pret_etat)s WHERE prets.pret_id = %(pret_id)s', {
'pret_quoi': pret['pret_quoi'],
'pret_qui': pret['pret_qui'],
'pret_etat': pret['pret_etat'],
'pret_id': pret['pret_id'],
})
db.close()
return make_response('', 204)