mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 08:27:08 +00:00
Add CRUD operations for project info table
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user