def update(self, g_id, dbid, head, conn):
params, body, obj_type, js_func, event_stream = p_b_ot()
if obj_type + 's' in acceptable_types:
obj_id, uid, id_quote = id_or_uid(obj_type, params['obj_id'])
update = body['update']
msg = errors['Nonexistence'][obj_type](g_id, obj_id)
qu = r.db(dbid).table(obj_type + 's')
if not uid:
try:
dd = auto_reql(qu.get(obj_id).update(update), conn)
except r.ReqlNonExistenceError:
return json.dumps({'error': msg})
else:
dd = auto_reql(qu.get_all(obj_id, index='uid').update(update), conn)
return json.dumps(dd)
elif obj_type in acceptable_types:
update = body['update']
def literalize(d):
for k, v in d.iteritems():
if isinstance(v, dict):
literalize(v)
else:
m = literal_check.search(v)
if m:
d[k] = r.literal(json.loads(m.group('json_doc')))
literalize(update)
qu = r.db(dbid).table(obj_type)
if 'get_all' in body:
if 'index' in body:
qu = qu.get_all(*body['get_all'], index=body['index'])
else:
qu = qu.get_all(*body['get_all'])
if 'filter' in body:
filt_func = body['filter']
if js_func:
filt_func = r.js(filt_func)
qu = qu.filter(filt_func)
d = auto_reql(qu.update(update), conn)
return json.dumps(d)
评论列表
文章目录