本文整理汇总了Python中rethinkdb.db_list函数的典型用法代码示例。如果您正苦于以下问题:Python db_list函数的具体用法?Python db_list怎么用?Python db_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_setup_db
def test_setup_db(self):
""" Test creation of a db and tables """
# test that the 'TEST' database doesn't exist
with rethinkdb.connect(host='localhost', port=28015) as conn:
db_list = rethinkdb.db_list().run(conn)
self.assertTrue('TEST' not in db_list)
creations = self.run_setup_db()
# confirm the correct tables were created
self.assertSetEqual(creations,
set(template.test_dataset.keys()+template.test_tables))
with rethinkdb.connect(host='localhost', port=28015) as conn:
# test that the 'TEST' database was created
db_list = rethinkdb.db_list().run(conn)
self.assertTrue('TEST' in db_list)
conn.use('TEST')
# test that the 'test' table was created
table_list = rethinkdb.table_list().run(conn)
self.assertEqual(len(table_list),
len(template.test_dataset.keys()+template.test_tables))
self.assertTrue(template.test_dataset.keys()[0] in table_list)
# test that the data is correct by checking columns
data = [row for row in rethinkdb.table(
template.test_dataset.keys()[0]).run(conn)]
with open(template.test_json) as f:
self.assertSetEqual(
set(data[0].keys())-set([u'id']),
set(json.loads(f.read())[0].keys()))
self.run_clear_test_db()
示例2: test_drop_programmatically_drops_the_database_when_assume_yes_is_true
def test_drop_programmatically_drops_the_database_when_assume_yes_is_true(monkeypatch):
conn = utils.get_conn()
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures
assert r.db_list().contains(dbname).run(conn) is True
utils.drop(assume_yes=True)
assert r.db_list().contains(dbname).run(conn) is False
示例3: test_drop_interactively_drops_the_database_when_user_says_yes
def test_drop_interactively_drops_the_database_when_user_says_yes(monkeypatch):
conn = utils.get_conn()
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures
assert r.db_list().contains(dbname).run(conn) is True
monkeypatch.setattr(builtins, 'input', lambda x: 'y')
utils.drop()
assert r.db_list().contains(dbname).run(conn) is False
示例4: test_run_query
async def test_run_query(db_conn, aiorethink_db_session):
cn = await db_conn
q1 = r.db_list()
q2 = r.db_list().run(cn)
for q in [q1, q2]:
res = await ar.db._run_query(q)
assert "testing" in res
with pytest.raises(TypeError):
await ar.db._run_query("Hello")
示例5: _rethinkdb
def _rethinkdb(request):
if request.config.getoption("--only-client"):
yield None
return
import rethinkdb as r
conn = r.connect("localhost", 28015)
# drop/create test database
if "test" in r.db_list().run(conn):
r.db_drop("test").run(conn)
r.db_create("test").run(conn)
# reconnect with db=test and repl
r.connect(db="test").repl()
r.table_create("ebooks", primary_key="ebook_id").run()
r.table_create("versions", primary_key="version_id").run()
r.table_create("formats", primary_key="file_hash").run()
r.table_create("sync_events").run()
def create_index(table, name, index=None):
if name not in r.table(table).index_list().run():
if index is None:
r.db("test").table(table).index_create(name).run()
else:
r.db("test").table(table).index_create(name, index).run()
r.db("test").table(table).index_wait(name).run()
# create FK indexes
create_index("ebooks", "authortitle", index=[r.row["author"].downcase(), r.row["title"].downcase()])
create_index("ebooks", "asin", index=r.row["meta"]["asin"])
create_index("ebooks", "isbn", index=r.row["meta"]["isbn"])
create_index("versions", "ebook_id")
create_index("versions", "original_filehash")
create_index("versions", "ebook_username", index=[r.row["ebook_id"], r.row["username"]])
create_index("formats", "version_id")
create_index("formats", "uploaded")
create_index("formats", "uploaded_by")
create_index("formats", "uploadedby_dedrm", index=[r.row["uploaded_by"], r.row["dedrm"]])
create_index("sync_events", "username")
create_index("sync_events", "timestamp")
create_index("sync_events", "user_new_books_count", index=[r.row["username"], r.row["new_books_count"]])
yield r
# remove test database
if "test" in r.db_list().run(conn):
r.db_drop("test").run(conn)
conn.close()
示例6: table_check
def table_check(progress, conn, db, table, create_args, force):
pkey = None
if db == "rethinkdb":
raise RuntimeError("Error: Cannot import a table into the system database: 'rethinkdb'")
if db not in r.db_list().run(conn):
r.db_create(db).run(conn)
if table in r.db(db).table_list().run(conn):
if not force:
raise RuntimeError("Error: Table already exists, run with --force if you want to import into the existing table")
if 'primary_key' in create_args:
pkey = r.db(db).table(table).info()["primary_key"].run(conn)
if create_args["primary_key"] != pkey:
raise RuntimeError("Error: Table already exists with a different primary key")
else:
if 'primary_key' in create_args:
pkey = create_args["primary_key"]
else:
if not options["quiet"]:
print("no primary key specified, using default primary key when creating table")
r.db(db).table_create(table, **create_args).run(conn)
return pkey
示例7: table_config_created_and_populated
def table_config_created_and_populated():
try:
r_conn_test = r.connect(RETHINK_HOST, RETHINK_PORT)
if not r.db_list().contains(RETHINK_DB).run(r_conn_test):
print(f'rethink host {RETHINK_HOST} and port {RETHINK_PORT} has connected but rethink database {RETHINK_DB} is not created')
return False
else:
r_conn = new_rethink_connection()
out = False
if r.table_list().contains('config').run(r_conn):
rtable = r.table('config')
out = rtable.get(1).run(r_conn)
close_rethink_connection(r_conn)
if out is not False:
if out is not None:
#print('table config populated in database')
return True
else:
print('table config not populated in database')
return False
else:
return False
except Exception as e:
print(f'rethink db connectin failed with hostname {RETHINK_HOST} and port {RETHINK_PORT}')
print(e)
print('Traceback: \n .{}'.format(traceback.format_exc()))
return False
示例8: get_tables
def get_tables(host, port, auth_key, tables):
try:
conn = r.connect(host, port, auth_key=auth_key)
except r.RqlDriverError as ex:
raise RuntimeError(ex.message)
dbs = r.db_list().run(conn)
res = []
if len(tables) == 0:
tables = [[db] for db in dbs]
for db_table in tables:
if db_table[0] not in dbs:
raise RuntimeError("Error: Database '%s' not found" % db_table[0])
if len(db_table) == 1: # This is just a db name
res.extend([(db_table[0], table) for table in r.db(db_table[0]).table_list().run(conn)])
else: # This is db and table name
if db_table[1] not in r.db(db_table[0]).table_list().run(conn):
raise RuntimeError("Error: Table not found: '%s.%s'" % tuple(db_table))
res.append(tuple(db_table))
# Remove duplicates by making results a set
return set(res)
示例9: create_db
def create_db(self):
db_list = r.db_list().run()
if self.db in db_list:
pass
else:
r.db_create(self.db).run()
示例10: __init__
def __init__(self, database='apscheduler', table='jobs', client=None,
pickle_protocol=pickle.HIGHEST_PROTOCOL, **connect_args):
super(RethinkDBJobStore, self).__init__()
self.pickle_protocol = pickle_protocol
if not database:
raise ValueError('The "database" parameter must not be empty')
if not table:
raise ValueError('The "table" parameter must not be empty')
if client:
self.conn = maybe_ref(client)
else:
self.conn = r.connect(db=database, **connect_args)
if database not in r.db_list().run(self.conn):
r.db_create(database).run(self.conn)
if table not in r.table_list().run(self.conn):
r.table_create(table).run(self.conn)
if 'next_run_time' not in r.table(table).index_list().run(self.conn):
r.table(table).index_create('next_run_time').run(self.conn)
self.table = r.db(database).table(table)
示例11: check_db
def check_db():
r.connect(properties.get('RETHINK_HOST'), properties.get('RETHINK_PORT')).repl()
if 'relayr' in r.db_list().run():
return True
return False
示例12: setUp
def setUp(self):
self.servers = test_util.RethinkDBTestServers(4, server_build_dir=server_build_dir)
self.servers.__enter__()
self.port = self.servers.driver_port()
conn = r.connect(port=self.port)
if 'test' not in r.db_list().run(conn):
r.db_create('test').run(conn)
示例13: initialSetup
def initialSetup():
print "Setting up database..."
dbs = rethinkdb.db_list().run()
if not con.general.databases["rethink"]["db"] in dbs:
print "Creating database in rethink"
rethinkdb.db_create(con.general.databases["rethink"]["db"]).run()
dbt = list(rethinkdb.table_list().run())
for db in c.general.flush["rethink"]:
if c.general.flush["rethink"][db]:
print "Flushing rethink "+db+" table..."
if db in dbt:
rethinkdb.table_drop(db).run()
dbt.pop(dbt.index(db))
print "Creating new rethink tables..."
for table in c.general.tables:
if not table in dbt:
print "Creating table {}".format(table)
rethinkdb.table_create(table).run()
for key in c.general.flush["redis"]:
if c.general.flush["redis"][key]:
print "Flushing redis "+key+" keys..."
keys = con.redis.keys(key+":*")
for key in keys: con.redis.delete(key)
示例14: create
def create(self):
conn = self.connect()
db_list = r.db_list().run(conn)
db_created = False
table_created = False
if not self.db_name in db_list:
r.db_create(self.db_name).run(conn)
db_created = True
table_list = r.db(self.db_name).table_list().run(conn)
if not self.config_table_name in table_list:
r.db(self.db_name).table_create(
self.config_table_name, primary_key=self.primary_key
).run(conn)
r.db(self.db_name).table(self.config_table_name)\
.index_create(self.secondary_index).run(conn)
table_created = True
return {"db": db_created, "table": table_created}
示例15: init_db
def init_db():
'Set up the database'
if 'ld33' not in r.db_list().run(rdb.conn):
r.db_create('ld33').run(rdb.conn)
if 'games' not in app.db.table_list().run(rdb.conn):
app.db.table_create('games',
primary_key='container_id').run(rdb.conn)