本文整理汇总了Python中rethinkdb.row方法的典型用法代码示例。如果您正苦于以下问题:Python rethinkdb.row方法的具体用法?Python rethinkdb.row怎么用?Python rethinkdb.row使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rethinkdb
的用法示例。
在下文中一共展示了rethinkdb.row方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def execute(self, quals, columns):
log_to_postgres('Query Columns: %s' % columns, DEBUG)
log_to_postgres('Query Filters: %s' % quals, DEBUG)
myQuery = r.table(self.table)\
.pluck(self.columns.keys())
for qual in quals:
try:
operatorFunction = getOperatorFunction(qual.operator)
except unknownOperatorException, e:
log_to_postgres(e, ERROR)
myQuery = myQuery.filter(operatorFunction(r.row[qual.field_name], qual.value))
示例2: fetch_account_resource
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def fetch_account_resource(conn, public_key, auth_key):
try:
return await r.table('accounts')\
.get_all(public_key, index='public_key')\
.max('start_block_num')\
.merge({'publicKey': r.row['public_key']})\
.merge({'holdings': fetch_holdings(r.row['holdings'])})\
.do(lambda account: (r.expr(auth_key).eq(public_key)).branch(
account.merge(_fetch_email(public_key)), account))\
.do(lambda account: (account['label'] == "").branch(
account.without('label'), account))\
.do(lambda account: (account['description'] == "").branch(
account.without('description'), account))\
.without('public_key', 'delta_id',
'start_block_num', 'end_block_num')\
.run(conn)
except ReqlNonExistenceError:
raise ApiBadRequest(
"No account with the public key {} exists".format(public_key))
示例3: fetch_all_offer_resources
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def fetch_all_offer_resources(conn, query_params):
return await r.table('offers')\
.filter((fetch_latest_block_num() >= r.row['start_block_num'])
& (fetch_latest_block_num() < r.row['end_block_num']))\
.filter(query_params)\
.map(lambda offer: (offer['label'] == "").branch(
offer.without('label'), offer))\
.map(lambda offer: (offer['description'] == "").branch(
offer.without('description'), offer))\
.map(lambda offer: offer.merge(
{'sourceQuantity': offer['source_quantity']}))\
.map(lambda offer: (offer['target'] == "").branch(
offer.without('target'), offer))\
.map(lambda offer: (offer['target_quantity'] == "").branch(
offer,
offer.merge({'targetQuantity': offer['target_quantity']})))\
.map(lambda offer: (offer['rules'] == []).branch(
offer, offer.merge(parse_rules(offer['rules']))))\
.without('delta_id', 'start_block_num', 'end_block_num',
'source_quantity', 'target_quantity')\
.coerce_to('array').run(conn)
示例4: fetch_offer_resource
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def fetch_offer_resource(conn, offer_id):
try:
return await r.table('offers')\
.get_all(offer_id, index='id')\
.max('start_block_num')\
.do(lambda offer: (offer['label'] == "").branch(
offer.without('label'), offer))\
.do(lambda offer: (offer['description'] == "").branch(
offer.without('description'), offer))\
.merge({'sourceQuantity': r.row['source_quantity']})\
.do(lambda offer: (offer['target'] == "").branch(
offer.without('target'), offer))\
.do(lambda offer: (offer['target_quantity'] == "").branch(
offer,
offer.merge({'targetQuantity': offer['target_quantity']})))\
.do(lambda offer: (offer['rules'] == []).branch(
offer, offer.merge(parse_rules(offer['rules']))))\
.without('delta_id', 'start_block_num', 'end_block_num',
'source_quantity', 'target_quantity')\
.run(conn)
except ReqlNonExistenceError:
raise ApiBadRequest("No offer with the id {} exists".format(offer_id))
示例5: _get_jobs
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def _get_jobs(self, predicate=None):
jobs = []
failed_job_ids = []
query = (self.table.filter(r.row['next_run_time'] != None).filter(predicate) if
predicate else self.table)
query = query.order_by('next_run_time', 'id').pluck('id', 'job_state')
for document in query.run(self.conn):
try:
jobs.append(self._reconstitute_job(document['job_state']))
except:
self._logger.exception('Unable to restore job "%s" -- removing it', document['id'])
failed_job_ids.append(document['id'])
# Remove all the jobs we failed to restore
if failed_job_ids:
r.expr(failed_job_ids).for_each(
lambda job_id: self.table.get_all(job_id).delete()).run(self.conn)
return jobs
示例6: _ensure_db
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def _ensure_db(self):
dbs = self.rr.db_list().run()
if not self.rr.dbname in dbs:
self.logger.info("creating rethinkdb database %r", self.rr.dbname)
self.rr.db_create(self.rr.dbname).run()
tables = self.rr.table_list().run()
if not "sites" in tables:
self.logger.info(
"creating rethinkdb table 'sites' in database %r",
self.rr.dbname)
self.rr.table_create(
"sites", shards=self.shards, replicas=self.replicas).run()
self.rr.table("sites").index_create("sites_last_disclaimed", [
r.row["status"], r.row["last_disclaimed"]]).run()
self.rr.table("sites").index_create("job_id").run()
if not "pages" in tables:
self.logger.info(
"creating rethinkdb table 'pages' in database %r",
self.rr.dbname)
self.rr.table_create(
"pages", shards=self.shards, replicas=self.replicas).run()
self.rr.table("pages").index_create("priority_by_site", [
r.row["site_id"], r.row["brozzle_count"],
r.row["claimed"], r.row["priority"]]).run()
# this index is for displaying pages in a sensible order in the web
# console
self.rr.table("pages").index_create("least_hops", [
r.row["site_id"], r.row["brozzle_count"],
r.row["hops_from_seed"]]).run()
if not "jobs" in tables:
self.logger.info(
"creating rethinkdb table 'jobs' in database %r",
self.rr.dbname)
self.rr.table_create(
"jobs", shards=self.shards, replicas=self.replicas).run()
示例7: fetch_all_account_resources
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def fetch_all_account_resources(conn):
return await r.table('accounts')\
.filter((fetch_latest_block_num() >= r.row['start_block_num'])
& (fetch_latest_block_num() < r.row['end_block_num']))\
.map(lambda account: account.merge(
{'publicKey': account['public_key']}))\
.map(lambda account: account.merge(
{'holdings': fetch_holdings(account['holdings'])}))\
.map(lambda account: (account['label'] == "").branch(
account.without('label'), account))\
.map(lambda account: (account['description'] == "").branch(
account.without('description'), account))\
.without('public_key', 'delta_id',
'start_block_num', 'end_block_num')\
.coerce_to('array').run(conn)
示例8: fetch_all_asset_resources
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def fetch_all_asset_resources(conn):
return await r.table('assets')\
.filter((fetch_latest_block_num() >= r.row['start_block_num'])
& (fetch_latest_block_num() < r.row['end_block_num']))\
.map(lambda asset: (asset['description'] == "").branch(
asset.without('description'), asset))\
.map(lambda asset: (asset['rules'] == []).branch(
asset, asset.merge(parse_rules(asset['rules']))))\
.without('start_block_num', 'end_block_num', 'delta_id')\
.coerce_to('array').run(conn)
示例9: getUID
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def getUID(self, username, rdb):
''' Lookup a users uid by username '''
results = r.table('users').filter(
r.row['username'] == username).run(rdb)
xdata = {}
for x in results:
key = x['username']
value = x['id']
xdata[key] = value
if username in xdata:
return xdata[username]
else:
return False
示例10: history
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def history(
self, method=None, hid=None,
time=None, start=None, limit=None, rdb=None):
''' This will pull a monitors history from rethinkDB '''
retdata = False
if method == "mon-history":
retdata = []
monitors = r.table('history').filter(
(r.row['cid'] == self.cid) & (r.row['starttime'] >= time) & (r.row['type'] == "monitor")).order_by(
r.desc('starttime')).pluck('starttime', 'id', 'cid', 'zone', 'status', 'failcount', 'method', 'name').skip(start).limit(limit).run(rdb)
for mon in monitors:
mon['starttime'] = datetime.datetime.fromtimestamp(
mon['starttime']).strftime('%Y-%m-%d %H:%M:%S')
retdata.append(mon)
elif method == "detail-history":
retdata = []
mon = r.table('history').get(hid).pluck(
'starttime', 'cid', 'zone', 'status',
'failcount', 'method', 'name').run(rdb)
mon['reactions'] = []
reactions = r.table('history').filter(
(r.row['cid'] == self.cid) & (r.row['starttime'] == mon['starttime']) & (r.row['zone'] == mon['zone']) & (r.row['type'] == "reaction")).pluck('name', 'rstatus', 'time', 'starttime').run(rdb)
for react in reactions:
react['starttime'] = datetime.datetime.fromtimestamp(
react['starttime']).strftime('%Y-%m-%d %H:%M:%S')
react['time'] = datetime.datetime.fromtimestamp(
react['time']).strftime('%Y-%m-%d %H:%M:%S')
mon['reactions'].append(react)
mon['starttime'] = datetime.datetime.fromtimestamp(
mon['starttime']).strftime('%Y-%m-%d %H:%M:%S')
retdata.append(mon)
elif method == "count":
retdata = r.table('history').filter(
(r.row['cid'] == self.cid) & (r.row['starttime'] >= time) & (r.row['type'] == "monitor")).count().run(rdb)
return retdata
示例11: purge_old_history
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def purge_old_history():
chktime = time.time() - config['history_retention']
results = r.table('history').filter(
(r.row['starttime'] < chktime)).delete().run(conn)
示例12: get_due_jobs
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def get_due_jobs(self, now):
return self._get_jobs(r.row['next_run_time'] <= datetime_to_utc_timestamp(now))
示例13: get_next_run_time
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def get_next_run_time(self):
results = list(
self.table
.filter(r.row['next_run_time'] != None) # flake8: noqa
.order_by(r.asc('next_run_time'))
.map(lambda x: x['next_run_time'])
.limit(1)
.run(self.conn)
)
return utc_timestamp_to_datetime(results[0]) if results else None
示例14: get_accessions
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def get_accessions(self, database, table):
'''
Return documents from the table.database for which accession numbers are from genbank
'''
print("Getting accession numbers for sequences obtained from Genbank")
accessions = list(r.db(database).table(table).filter((r.row["source"] == 'genbank') | (r.row["source"] == 'vipr')).get_field('accession').run())
return accessions
示例15: update_groupings
# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import row [as 别名]
def update_groupings(self, viruses_table, sequences_table, database, update_keyword='tbd', preview=False, optimal_upload=50, **kwargs):
'''
Get viruses that have not had virus groupings determined, signaled by update_keyword
Align HA sequences to outgroups to determine the closest grouping
'''
print("Updating grouping fields")
print("Getting viruses from " + database + "." + viruses_table + " with grouping fields (vtype, subtype, or lineage) equal to ", update_keyword)
viruses = list(r.db(database).table(viruses_table).filter((r.row["vtype"] == update_keyword) | (r.row["subtype"] == update_keyword) | (r.row["lineage"] == update_keyword)).run())
ha_sequences = list(r.db(database).table(sequences_table).filter((r.row["locus"] == 'ha')).run())
accession_to_sequence_doc = {doc['accession']:doc for doc in ha_sequences}
# split updating of groups into groups of 50 viruses
if len(viruses) > optimal_upload:
list_viruses = [viruses[x:x+optimal_upload] for x in range(0, len(viruses), optimal_upload)]
else:
list_viruses = [viruses]
print("Determining groupings for " + str(len(viruses)) + " viruses in " + str(len(list_viruses)) + " batches of " + str(optimal_upload) + " viruses at a time")
for group_num, virus_group in enumerate(list_viruses):
print("Group " + str(group_num+1)) + " out of " + str(len(list_viruses)) + " groupings"
for virus in virus_group:
for acc in virus['sequences']:
if acc in accession_to_sequence_doc:
# try determining grouping information from one HA sequence
result = self.align_flu(accession_to_sequence_doc[acc])
if result is not None:
virus['vtype'], virus['subtype'], virus['lineage'] = result
else:
virus['vtype'], virus['subtype'], virus['lineage'] = "undetermined", "undetermined", "undetermined"
break
if not preview:
print("Updating " + str(len(virus_group)) + " virus groupings in " + self.database + "." + self.viruses_table)
self.upload_to_rethinkdb(self.database, self.viruses_table, virus_group, overwrite=True, optimal_upload=optimal_upload, index='strain')
else:
print("Preview of updates to be made, remove --preview to make updates to database")