本文整理汇总了Python中rethinkdb.db_create函数的典型用法代码示例。如果您正苦于以下问题:Python db_create函数的具体用法?Python db_create怎么用?Python db_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dbSetup
def dbSetup():
connection = r.connect(host=RDB_HOST, port=RDB_PORT)
try:
r.db_create(resultsdb).run(connection)
r.db(resultsdb).table_create('results').run(connection)
r.db(resultsdb).table_create('gpa').run(connection)
r.db(resultsdb).table_create('students', primary_key='regno').run(connection)
r.db(resultsdb).table('gpa').index_create(
'semester_',
[
r.row["regno"],
r.row["semester"]
]
).run(connection)
r.db(resultsdb).table('results').index_create(
'subject',
[
r.row["regno"],
r.row["code"],
r.row["subject_name"]
]
).run(connection)
print ('Database setup completed. Now run the app without --setup: '
'`python downloaddb.py`')
except r.RqlRuntimeError, e:
print e
示例2: rethinkdb
def rethinkdb():
"""Prepare database and table in RethinkDB"""
from rethinkdb.errors import ReqlOpFailedError, ReqlRuntimeError
conn = r.connect(host=conf.RethinkDBConf.HOST)
# Create database
try:
r.db_create(conf.RethinkDBConf.DB).run(conn)
click.secho('Created database {}'.format(conf.RethinkDBConf.DB),
fg='yellow')
except ReqlOpFailedError:
click.secho('Database {} already exists'.format(conf.RethinkDBConf.DB),
fg='green')
# Create table 'domains'
conn = r.connect(host=conf.RethinkDBConf.HOST,
db=conf.RethinkDBConf.DB)
try:
r.table_create('domains', durability=conf.RethinkDBConf.DURABILITY).\
run(conn)
click.secho('Created table domains', fg='yellow')
except ReqlOpFailedError:
click.secho('Table domains already exists', fg='green')
# Create index on domains.name
try:
r.table('domains').index_create('name').run(conn)
click.secho('Created index domains.name', fg='yellow')
except ReqlRuntimeError:
click.secho('Index domains.name already exists', fg='green')
示例3: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--rethinkdb-host", default="localhost:28015")
parser.add_argument("-m", "--machine-id", default=socket.gethostname())
args = parser.parse_args()
host, port = args.rethinkdb_host.split(":")
r.connect(host, port).repl()
try:
r.db("logcentral")
except r.ReqlOpFailedError:
r.db_create("logcentral").run()
db = r.db("logcentral")
if 'cursor_state' not in db.table_list().run():
r.db("logcentral").table_create("cursor_state").run()
if 'log' not in db.table_list().run():
r.db("logcentral").table_create("log").run()
cursor_table = r.db("logcentral").table('cursor_state')
log_table = r.db("logcentral").table('log')
c = cursor_table.get(args.machine_id).run()
c = None if c is None else c['cursor']
for line in yield_log_lines(c):
cursor, data = prepare_for_table(line, args.machine_id)
log_table.insert(data).run()
cursor_table.insert({"id": args.machine_id, "cursor": cursor}, durability="soft", conflict="replace").run()
示例4: 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)
示例5: setUp
def setUp(self):
self.db_name = 'radiowcs_test'
assert self.db_name != 'radiowcs'
self.table_name = 'test'
self.db = database.Database()
self.db.database_name = self.db_name
self.db.table_name = self.table_name
self.db.connect()
self.connection = r.connect(
host='localhost',
port=28015,
db=self.db_name,
auth_key='',
timeout=30
)
try:
r.db_create(self.db_name).run(self.connection)
r.table_create(self.table_name).run(self.connection)
except r.RqlRuntimeError:
print 'unittest setup: Drop table'
r.table_drop(self.table_name).run(self.connection)
r.table_create(self.table_name).run(self.connection)
r.db(self.db_name).table(self.table_name).index_create( 'title').run(self.connection)
r.db(self.db_name).table(self.table_name).index_create('artist').run(self.connection)
r.db(self.db_name).table(self.table_name).index_create( 'date').run(self.connection)
# 'out of order' insertions
r.db(self.db_name).table(self.table_name).insert({'title':'foobar', 'artist': 'Selena', 'date': '1430183323'}).run(self.connection)
r.db(self.db_name).table(self.table_name).insert({'title':'hello world', 'artist': 'John', 'date': '1430082566'}).run(self.connection)
r.db(self.db_name).table(self.table_name).insert({'title':'zombie apoc', 'artist': 'xxJANExx', 'date': '1430385845'}).run(self.connection)
r.db(self.db_name).table(self.table_name).insert({'title':'Black', 'artist': 'Kettle', 'date': '1430284300'}).run(self.connection)
示例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: index
def index():
import rethinkdb as r
r.connect('localhost', 28015).repl()
try:
r.db_create('wlps').run()
except RqlRuntimeError:
pass
try:
r.db('wlps').table_create('episode').run()
except RqlRuntimeError:
pass
try:
r.db('wlps').table_create('show').run()
except RqlRuntimeError:
pass
try:
r.db('wlps').table_create('notifications').run()
except RqlRuntimeError:
pass
try:
r.db('wlps').table_create('queue').run()
except RqlRuntimeError:
pass
示例8: rethink
def rethink(request):
"""
Set up a test database in Rethink and return a piper.db.rethink.RethinkDB
instance.
Tears down the database once done.
"""
conn = rdb.connect(
host=os.getenv('RETHINKDB_TEST_HOST', "localhost"),
port=os.getenv('RETHINKDB_TEST_PORT', 28015),
)
db_name = 'piper_test_{0}'.format(str(time.time()).replace('.', '_'))
rdb.db_create(db_name).run(conn)
conn.use(db_name)
rethink = RethinkDB()
rethink.conn = conn # Ugly faking to make the manager creation roll.
rethink.create_tables(conn)
def fin():
rdb.db_drop(db_name).run(conn)
request.addfinalizer(fin)
return rethink
示例9: __init__
def __init__(self, config):
self.config = config
print(self.config)
self.name = self.config['name']
self.id = self.config['id']
self.db_name = self.config['db_name']
self.rdb = r.connect(
host=self.config['db_host'],
port=self.config['db_port']
)
try:
r.db_create(self.db_name).run(self.rdb)
r.db(self.db_name)\
.table_create('incidents', primary_key='slack_channel')\
.run(self.rdb)
print('Database setup completed.')
except RqlRuntimeError:
print('App database already exists.')
self.rdb.close()
self.pool = ConnectionPool(
host=self.config['db_host'],
port=self.config['db_port'],
db=self.db_name
)
示例10: init_database
def init_database():
try:
connection = r.connect(host=RDB_HOST, port=RDB_PORT, db=RDB_DB)
except RqlDriverError:
debug("Could not connect to the database %s:%d, exiting..." % (RDB_HOST, RDB_PORT), True)
exit(1)
try:
r.db_create("tomatoesfridge").run( connection )
except r.errors.RqlRuntimeError as e:
# We could parse the error... later...
debug("Database `tomatoesfridge` not created. Reason:")
debug(str(e))
else:
debug("Database `tomatoesfridge` created")
try:
r.table_create("movie").run( connection )
except r.errors.RqlRuntimeError as e:
# We could parse the error... later...
debug("Table `movie` in `tomatoesfridge` not created. Reason")
debug(str(e))
else:
debug("Table `movie` in `tomatoesfridge` created")
try:
connection.close()
except AttributeError:
debug("Could not close a connection", True)
pass
示例11: dbSetup
def dbSetup():
connection = r.connect(host="localhost", port=28015)
try:
r.db_create(RCRDKEEPER_DB).run(connection)
r.db(RCRDKEEPER_DB).table_create("records").run(connection)
r.db(RCRDKEEPER_DB).table_create("users").run(connection)
r.db(RCRDKEEPER_DB).table_create("record_condition").run(connection)
r.db(RCRDKEEPER_DB).table_create("record_size").run(connection)
r.db(RCRDKEEPER_DB).table_create("contact").run(connection)
r.db("rcrdkeeper").table("record_condition").insert({"abbr": "M", "condition": "Mint", "order": 1}).run(
connection
)
r.db("rcrdkeeper").table("record_condition").insert({"abbr": "VG", "condition": "Very Good", "order": 2}).run(
connection
)
r.db("rcrdkeeper").table("record_condition").insert({"abbr": "G", "condition": "Good", "order": 3}).run(
connection
)
r.db("rcrdkeeper").table("record_condition").insert({"abbr": "AV", "condition": "Average", "order": 4}).run(
connection
)
r.db("rcrdkeeper").table("record_condition").insert({"abbr": "P", "condition": "Poor", "order": 5}).run(
connection
)
r.db("rcrdkeeper").table("record_condition").insert({"abbr": "VP", "condition": "Very Poor", "order": 6}).run(
connection
)
r.db("rcrdkeeper").table("record_size").insert({"size": "12 inch", "order": 1}).run(connection)
r.db("rcrdkeeper").table("record_size").insert({"size": "10 inch", "order": 2}).run(connection)
r.db("rcrdkeeper").table("record_size").insert({"size": "7 inch", "order": 3}).run(connection)
print "Database setup completed. Now run the app without --setup."
except RqlRuntimeError:
print "App database already exists. Run the app without --setup."
finally:
connection.close()
示例12: 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)
示例13: init_database_with_default_tables
def init_database_with_default_tables(args):
"""
Create a new RethinkDB database and initialise (default) tables
:param args: an argparse argument (force)
"""
# Add additional (default) tables here...
def_tables = ['determined_variants', 'strains_under_investigation',
'references', 'reference_features', 'strain_features']
with database.make_connection() as connection:
try:
r.db_create(connection.db).run(connection)
for atable in def_tables:
r.db(connection.db).table_create(atable).run(connection)
except RqlRuntimeError:
print ("Database %s already exists. Use '--force' option to "
"reinitialise the database." % (connection.db))
if args.force:
print "Reinitialising %s" % (connection.db)
r.db_drop(connection.db).run(connection)
r.db_create(connection.db).run(connection)
for atable in def_tables:
r.db(connection.db).table_create(atable).run(connection)
else:
sys.exit(1)
print ("Initalised database %s. %s contains the following tables: "
"%s" % (connection.db, connection.db, ', '.join(def_tables)))
示例14: create_db
def create_db(db_name):
try:
r.db_create(db_name).run()
except RqlRuntimeError as rql:
print 'Failed to create the database ', rql
except Exception as ex:
print 'Exception occurred ', ex
示例15: 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()