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


Python rethinkdb.db方法代码示例

本文整理汇总了Python中rethinkdb.db方法的典型用法代码示例。如果您正苦于以下问题:Python rethinkdb.db方法的具体用法?Python rethinkdb.db怎么用?Python rethinkdb.db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rethinkdb的用法示例。


在下文中一共展示了rethinkdb.db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: drop_fork

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def drop_fork(self, block_num):
        """Deletes all resources from a particular block_num
        """
        block_results = r.db(self._name).table('blocks')\
            .filter(lambda rsc: rsc['block_num'].ge(block_num))\
            .delete()\
            .run(self._conn)

        resource_results = r.db(self._name).table_list()\
            .for_each(
                lambda table_name: r.branch(
                    r.eq(table_name, 'blocks'),
                    [],
                    r.eq(table_name, 'auth'),
                    [],
                    r.db(self._name).table(table_name)
                    .filter(lambda rsc: rsc['start_block_num'].ge(block_num))
                    .delete()))\
            .run(self._conn)

        return {k: v + resource_results[k] for k, v in block_results.items()} 
开发者ID:hyperledger,项目名称:sawtooth-marketplace,代码行数:23,代码来源:database.py

示例2: setUp

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def setUp(self):
        try:
            g.rdb_conn = r.connect(
                host=app.config['DBHOST'], port=app.config['DBPORT'],
                auth_key=app.config['DBAUTHKEY'], db=app.config['DATABASE'])

            userdata = {
                'username': 'test@tester.com',
                'email': 'test@tester.com',
                'password': 'password456',
                'company': 'company',
                'contact': 'tester'
            }

            # Create test user
            user = User()
            user.config = app.config
            user.createUser(userdata, g.rdb_conn)

        except RqlDriverError:
            # If no connection possible throw 503 error
            abort(503, "No Database Connection Could be Established.") 
开发者ID:Runbook,项目名称:runbook,代码行数:24,代码来源:base.py

示例3: rethink_make_tables

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def rethink_make_tables(request, rethink_module_db):
    """ Module-scoped fixture that creates all tables specified in the test
        module attribute FIXTURE_TABLES.

    """
    reqd_table_list = getattr(request.module, 'FIXTURE_TABLES')
    log.debug("Do stuff before all module tests with {0}".format(reqd_table_list))
    conn = rethink_module_db
    for table_name, primary_key in reqd_table_list:
        try:
            rethinkdb.db(conn.db).table_create(table_name,
                                               primary_key=primary_key,
                                               ).run(conn)
            log.info('Made table "{0}" with key "{1}"'
                     .format(table_name, primary_key))
        except rethinkdb.errors.RqlRuntimeError as err:
            log.debug('Table "{0}" not made: {1}'.format(table_name, err.message)) 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:19,代码来源:rethink.py

示例4: start

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def start(self, scheduler, alias):
        super(RethinkDBJobStore, self).start(scheduler, alias)

        if self.client:
            self.conn = maybe_ref(self.client)
        else:
            self.conn = r.connect(db=self.database, **self.connect_args)

        if self.database not in r.db_list().run(self.conn):
            r.db_create(self.database).run(self.conn)

        if self.table not in r.table_list().run(self.conn):
            r.table_create(self.table).run(self.conn)

        if 'next_run_time' not in r.table(self.table).index_list().run(self.conn):
            r.table(self.table).index_create('next_run_time').run(self.conn)

        self.table = r.db(self.database).table(self.table) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:20,代码来源:rethinkdb.py

示例5: __init__

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def __init__(self, db, table_name=None, connection=None, host=None, port=None, user=None, password=None,
                 timeout=0.3):
        if not r:
            raise ImproperlyConfigured('You need to install the rethinkdb library to use the RethinkDB backend.')
        if connection:
            self.connection = connection
        elif host and port:
            if user and password:
                self.connection = r.connect(host=host, port=port, db=db, user=user, password=password, timeout=timeout)
            else:
                self.connection = r.connect(host=host, port=port, db=db, timeout=timeout)
        self.db = db
        self.table_name = table_name
        if self.connection is None:
            self.connection = r.connect(db=db, timeout=timeout)
        self._create_database() 
开发者ID:APSL,项目名称:kaneda,代码行数:18,代码来源:rethink.py

示例6: connect_rethink

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def connect_rethink(self, db, rethink_host='localhost', auth_key=None, **kwargs):
        '''
        Connect to rethink database,
        '''
        if rethink_host == 'localhost':
            try:
                conn = r.connect(host=rethink_host, port=28015, db=db).repl()
                print("Connected to the \"" + db + "\" database")
                return conn
            except:
                raise Exception("Failed to connect to the database, " + db)
        else:
            try:
                conn = r.connect(host=rethink_host, port=28015, db=db, auth_key=auth_key).repl()
                print("Connected to the \"" + db + "\" database")
                return conn
            except:
                raise Exception("Failed to connect to the database, " + db) 
开发者ID:nextstrain,项目名称:fauna,代码行数:20,代码来源:rethink_io.py

示例7: backup_s3

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def backup_s3(self, database, path='', delete_expired=False, **kwargs):
        '''
        make backup of every table in database, upload to s3 bucket
        '''
        print("Backing up " + database + " on " + self.rethink_io.get_upload_date())
        if not os.path.isdir(path):
            os.makedirs(path)
        tables = r.db(database).table_list().run()
        bucket = self.connect_S3(**kwargs)
        for table in tables:
            dump_file = self.rethink_io.get_upload_date() + '_' + database + '_' + table + '.tar.gz'
            self.dump(database=database, dump_table=table, dump_file=dump_file, **kwargs)
            shutil.move(dump_file, path+'/'+dump_file)
            bucket.upload_file(path+'/'+dump_file, dump_file)
        print("Successfully backed up")
        if delete_expired:
            self.delete_expired_s3_backups(bucket, **kwargs) 
开发者ID:nextstrain,项目名称:fauna,代码行数:19,代码来源:rethink_interact.py

示例8: get_parser

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def get_parser():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('-db', '--database', default='tdb', help="database to download from")
    parser.add_argument('--rethink_host', default=None, help="rethink host url")
    parser.add_argument('--auth_key', default=None, help="auth_key for rethink database")
    parser.add_argument('--local', default=False, action="store_true",  help ="connect to local instance of rethinkdb database")
    parser.add_argument('-v', '--virus', default='dengue', help="virus name")
    parser.add_argument('--subtype', help="subtype to be included in download")
    parser.add_argument('--ftype', default='tsv', help="output file format, default \"tsv\", options are \"json\" and \"tsv\"")
    parser.add_argument('--fstem', default=None, help="default output file name is \"VirusName_Year_Month_Date\"")
    parser.add_argument('--path', default='data', help="path to dump output files to")

    parser.add_argument('--select', nargs='+', type=str, default=[], help="Select specific fields ie \'--select field1:value1 field2:value1,value2\'")
    parser.add_argument('--present', nargs='+', type=str, default=[], help="Select specific fields to be non-null ie \'--present field1 field2\'")
    parser.add_argument('--interval', nargs='+', type=str, default=[], help="Select interval of values for fields \'--interval field1:value1,value2 field2:value1,value2\'")
    parser.add_argument('--years_back', type=str, default=None, help='number of past years to sample sequences from \'--years_back field:value\'')
    parser.add_argument('--relaxed_interval', default=False, action="store_true", help="Relaxed comparison to date interval, 2016-XX-XX in 2016-01-01 - 2016-03-01")
    return parser 
开发者ID:nextstrain,项目名称:fauna,代码行数:21,代码来源:dengue_download.py

示例9: match_database_duplicate_strains

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def match_database_duplicate_strains(self, viruses, sequences, virus, database='vdb', **kwargs):
        '''
        Compare measurement strain names to database strain names to matching to existing viruses sequences
        '''
        table = virus + "_viruses"
        print("Using " + database + "." + table + " to adjust strain names to match strains already in " + database + "." + table)
        vdb_strains = self.relaxed_keys(set(list(r.db(database).table(table).get_field('strain').run())), self.relax_name)
        adjusted_virus_strains = 0
        adjusted_sequence_strains = 0
        for doc in viruses:
            doc['strain'], adjusted_virus_strains = self.adjust_name(doc['strain'], vdb_strains, adjusted_virus_strains)
        for doc in sequences:
            doc['strain'], adjusted_sequence_strains = self.adjust_name(doc['strain'], vdb_strains, adjusted_sequence_strains)
        if adjusted_virus_strains > 0 or adjusted_sequence_strains > 0:
            print(str(adjusted_virus_strains) + " out of " + str(len(viruses)) + " virus strains were adjusted to match a virus in " + database + "." + table)
            print(str(adjusted_sequence_strains) + " out of " + str(len(sequences)) + " sequence strains were adjusted to match a virus in " + database + "." + table) 
开发者ID:nextstrain,项目名称:fauna,代码行数:18,代码来源:upload.py

示例10: setup

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def setup(self):
        self.conn = rt.connect(self.host, self.port)
        # rt.db(self.db_name).table_drop(self.TABLE_NAME).run(self.conn)
        self.create_table() 
开发者ID:smartsdk,项目名称:ngsi-timeseries-api,代码行数:6,代码来源:rethink.py

示例11: dispose

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def dispose(self):
        rt.db(self.db_name).table_drop(self.TABLE_NAME).run(self.conn)
        self.conn.close() 
开发者ID:smartsdk,项目名称:ngsi-timeseries-api,代码行数:5,代码来源:rethink.py

示例12: create_table

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def create_table(self):
        res = rt.db(self.db_name).table_create(self.TABLE_NAME).run(self.conn)
        if res['tables_created'] != 1:
            raise RuntimeError("Could not create table '{}'".format(self.TABLE_NAME)) 
开发者ID:smartsdk,项目名称:ngsi-timeseries-api,代码行数:6,代码来源:rethink.py

示例13: remove_old_days

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def remove_old_days(db_name, older_than=8, silent=True):

    """Deletes old days (tables) from a database.

    db_name [str]: an existing RethinkDB database.
    older_than [int]: delete days before this number of days ago.
        Defaults to 8, which will keep one week of data in the database
        (remember, no data are collected for the current day).
    silent [bool]: if True, does not print reports.

    Returns nothing."""

    #get today's date and the last date to keep
    today_date = datetime.datetime.today()
    delete_before = (today_date - datetime.timedelta(days=older_than-1)).date()

    #get all dates in db and convert to date objects
    days_in_db = r.db(db_name).table_list().run()
    dts_in_db = [datetime.datetime.strptime(d, '%Y_%m_%d').date() \
        for d in days_in_db]

    #find out which ones need to go
    inds_to_delete = [d < delete_before for d in dts_in_db]
    days_to_delete = list(itt.compress(days_in_db, inds_to_delete))

    #delete them
    if days_to_delete:
        for d in days_to_delete:
            r.db(db_name).table_drop(d).run()

    if silent == False:
        delete_before_str = delete_before.strftime('%Y-%m-%d')
        print('Removed ' + str(len(days_to_delete)) \
            + ' days prior to ' + delete_before_str + '.') 
开发者ID:uwescience,项目名称:TrafficCruising-DSSG2017,代码行数:36,代码来源:remove_old_days.py

示例14: fetch

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def fetch(self, table_name, primary_id):
        """Fetches a single resource by its primary id
        """
        return r.db(self._name).table(table_name)\
            .get(primary_id).run(self._conn) 
开发者ID:hyperledger,项目名称:sawtooth-marketplace,代码行数:7,代码来源:database.py

示例15: insert

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db [as 别名]
def insert(self, table_name, docs):
        """Inserts a document or a list of documents into the specified table
        in the database
        """
        return r.db(self._name).table(table_name).insert(docs).run(self._conn) 
开发者ID:hyperledger,项目名称:sawtooth-marketplace,代码行数:7,代码来源:database.py


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