From 36c839a276efd0cc20cabaf75c844ba46c6dc082 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 30 Aug 2016 18:59:55 -0500 Subject: [PATCH] Finished up saving/loading content to rethinkdb --- cogs/utils/config.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cogs/utils/config.py b/cogs/utils/config.py index 00de296..d8cc588 100644 --- a/cogs/utils/config.py +++ b/cogs/utils/config.py @@ -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