forked from narenaryan/Falcon-REST-API-Pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_client.py
29 lines (21 loc) · 745 Bytes
/
db_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import rethinkdb as r
from rethinkdb.errors import RqlRuntimeError, RqlDriverError
RDB_HOST = os.environ.get('RDB_HOST') or 'localhost'
RDB_PORT = os.environ.get('RDB_PORT') or 28015
PROJECT_DB = 'todo'
PROJECT_TABLE = 'notes'
db_connection = r.connect(RDB_HOST,RDB_PORT)
#This is just for cross-checking database and table exists
def dbSetup():
print PROJECT_DB,db_connection
try:
r.db_create(PROJECT_DB).run(db_connection)
print 'Database setup completed.'
except RqlRuntimeError:
try:
r.db(PROJECT_DB).table_create(PROJECT_TABLE).run(db_connection)
print 'Table creation completed'
except:
print 'Table already exists.Nothing to do'
dbSetup()