diff --git a/bin/datastore.py b/bin/datastore.py index b907dff..2d1f9f2 100644 --- a/bin/datastore.py +++ b/bin/datastore.py @@ -544,3 +544,60 @@ class Datastore: self.maybe_commit() # We do not commit if we've been passed a cursor, instead # we assume that we are in the middle of a transaction + + + def add_info(self, key, value, cursor = None): + """ + Add an item of information to the project + """ + if cursor is None: + cur = self.conn.cursor() + else: + cur = cursor + + qry = """ + INSERT INTO info (key, value) + VALUES(%s, %s) + ON CONFLICT (key) DO UPDATE + SET value = EXCLUDED.value; + """ + cur.execute(qry, (key, value)) + if cursor is None: + self.maybe_commit() + # We do not commit if we've been passed a cursor, instead + # we assume that we are in the middle of a transaction + + def get_info(self, key, cursor = None): + """ + Retrieve an item of information from the project + """ + if cursor is None: + cur = self.conn.cursor() + else: + cur = cursor + + qry = "SELECT value FROM info WHERE key = %s;" + cur.execute(qry, (key,)) + res = cur.fetchone() + if cursor is None: + self.maybe_commit() + # We do not commit if we've been passed a cursor, instead + # we assume that we are in the middle of a transaction + + return res + + def del_info(self, key, cursor = None): + """ + Remove a an item of information from the project + """ + if cursor is None: + cur = self.conn.cursor() + else: + cur = cursor + + qry = "DELETE FROM info WHERE key = %s;" + cur.execute(qry, (key,)) + if cursor is None: + self.maybe_commit() + # We do not commit if we've been passed a cursor, instead + # we assume that we are in the middle of a transaction