1
0
Fork 0
mirror of synced 2024-06-28 03:00:55 +12:00

Finished up saving/loading content to rethinkdb

This commit is contained in:
phxntxm 2016-08-30 18:59:55 -05:00
parent 5b8fc913b8
commit 36c839a276

View file

@ -74,11 +74,17 @@ async def save_content(table: str, content):
async def get_content(key: str):
# We need to make sure we're using asyncio
r.set_loop_type("asyncio")
# Just connect to the database
opts = {'host': db_host, 'db': db_name, 'port': db_port, 'ssl': {'ca_certs': db_cert}}
conn = await r.connect(**opts)
cursor = await r.table(key).run(conn)
# We should only ever get one result, so use it if it exists, otherwise return none
try:
return list(cursor)[0]
items = list(cursor.items)[0]
except IndexError:
return None
# Rethink db stores an internal id per table, delete this and return the rest
del items['id']
return items