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


Python rethinkdb.db_create方法代码示例

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


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

示例1: start

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db_create [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

示例2: rethink_unique_db

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db_create [as 别名]
def rethink_unique_db(rethink_server_sess):
    """ Starts up a session-scoped server, and returns a connection to
        a unique database for the life of a single test, and drops it after
    """
    dbid = uuid.uuid4().hex
    conn = rethink_server_sess.conn
    rethinkdb.db_create(dbid).run(conn)
    conn.use(dbid)
    yield conn
    rethinkdb.db_drop(dbid).run(conn) 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:12,代码来源:rethink.py

示例3: rethink_module_db

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db_create [as 别名]
def rethink_module_db(rethink_server_sess):
    """ Starts up a module-scoped server, and returns a connection to
        a unique database for all the tests in one module.
        Drops the database after module tests are complete.
    """
    dbid = uuid.uuid4().hex
    conn = rethink_server_sess.conn
    log.info("Making database")
    rethinkdb.db_create(dbid).run(conn)
    conn.use(dbid)
    yield conn
    log.info("Dropping database")
    rethinkdb.db_drop(dbid).run(conn) 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:15,代码来源:rethink.py

示例4: _create_database

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db_create [as 别名]
def _create_database(self):
        if self.db not in r.db_list().run(self.connection):
            r.db_create(self.db).run(self.connection) 
开发者ID:APSL,项目名称:kaneda,代码行数:5,代码来源:rethink.py

示例5: jumbo_write_json

# 需要导入模块: import rethinkdb [as 别名]
# 或者: from rethinkdb import db_create [as 别名]
def jumbo_write_json(data, db_name, table_name, chunk_size=5000, silent=True):

    '''Write big JSON lists to RethinkDB.

    Essential for datasets that are larger than 100,000 docs (ReQL max write).
    Often necessary even for smaller ones.

    data [list]: a list of dicts in JSON format.
    db_name [str]: a RethinkDB database, existing or not.
    table_name [str]: a RethinkDB table, existing or not.
    chunk_size [int or float of form BASEeEXP]: input list will be broken into
        chunks of this size. If you encounter memory use issues, reduce this
        value.
    silent [bool]: if True, does not print reports.

    Must be connected to a RethinkDB instance before using this.'''

    if chunk_size > 1e5:
        raise(Exception('Maximum JSON chunk_size is 100,000.'))

    #determine list length, number of chunks, and remainder
    list_length = len(data)
    chunk_size = int(chunk_size) #max array length for a ReQL write is 100k; but that uses too much mem
    nchunks = math.ceil(list_length / chunk_size)
    rem = list_length % chunk_size

    #create database if it doesn't already exist
    if db_name not in r.db_list().run():
        print('Creating database "' + db_name + '".')
        r.db_create(db_name).run()

    #create table if it doesn't already exist
    if table_name not in r.db(db_name).table_list().run():
        print('Creating table "' + table_name + '" in database "' \
            + db_name + '".')
        r.db(db_name).table_create(table_name).run()

    if silent == False:
        print('Writing list of ' + str(list_length) + ' trips to table "' \
            + table_name + '".')

    #digest data and write to RethinkDB
    for i in range(nchunks):
        s = i * chunk_size #chunk_start

        if i == nchunks - 1 and rem != 0:
            e = s + rem + 1
        else:
            e = (i+1) * chunk_size

        if silent == False:
            print('Writing trips ' + str(s) + '-' + str(e - 1) + '.')

        #write chunk to rethink (some data may be lost in case of power failure)
        r.db(db_name).table(table_name).insert(data[s:e]).run(durability='soft',
            noreply=False)

    if silent == False:
        ndocs = r.db(db_name).table(table_name).count().run()
        print('Table "' + table_name + '" now contains ' + str(ndocs) \
            + ' trips.') 
开发者ID:uwescience,项目名称:TrafficCruising-DSSG2017,代码行数:63,代码来源:jumbo.py


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