This is an automated email from the ASF dual-hosted git repository.

gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit b9d87a332e9c3fe1750edaf8bce4dbe2bef2a2bc
Author: Greg Stein <[email protected]>
AuthorDate: Sun May 29 21:36:56 2022 -0500

    add "upserts" for issues/participants
---
 v3/steve/election.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/v3/steve/election.py b/v3/steve/election.py
index b06de88..e818a6f 100644
--- a/v3/steve/election.py
+++ b/v3/steve/election.py
@@ -41,6 +41,20 @@ class Election:
             'UPDATE METADATA SET salt = ?, opened_key = ?')
         self.c_close = self.db.add_statement(
             'UPDATE METADATA SET closed = 1')
+        self.c_add_issue = self.db.add_statement(
+            '''INSERT INTO ISSUES VALUES (?, ?, ?, ?, ?, ?)
+               ON CONFLICT DO UPDATE SET
+                 title=excluded.title,
+                 description=excluded.description,
+                 type=excluded.type,
+                 kv=excluded.kv
+            ''')
+        self.c_add_record = self.db.add_statement(
+            '''INSERT INTO RECORD VALUES (?, ?, ?, ?)
+               ON CONFLICT DO UPDATE SET
+                 name=excluded.name,
+                 email=excluded.email
+            ''')
 
         # Cursors for running queries.
         self.q_metadata = self.db.add_query('metadata',
@@ -136,6 +150,14 @@ class Election:
         issue = self.q_get_issue.first_row((iid,))
         return issue.title, issue.description, issue.type, issue.kv
 
+    def add_issue(self, iid, title, description, type, kv):
+        "Add or update an issue designated by IID."
+        assert self.is_editable()
+
+        # If we ADD, then SALT will be NULL. If we UPDATE, then it will not
+        # be touched (it should be NULL).
+        self.c_add_issue.perform((iid, title, description, type, kv, None))
+
     def get_participant(self, rid):
         "Return NAME, EMAIL for Participant on record RID."
 
@@ -143,6 +165,14 @@ class Election:
         record = self.q_get_record.first_row((rid,))
         return record.name, record.email
 
+    def add_participant(self, rid, name, email):
+        "Add or update a Participant (voter of record) designated by RID."
+        assert self.is_editable()
+
+        # If we ADD, then SALT will be NULL. If we UPDATE, then it will not
+        # be touched (it should be NULL).
+        self.c_add_record.perform((rid, name, email, None))
+
     def is_tampered(self):
 
         # The Election should be open.

Reply via email to