diff options
Diffstat (limited to 'src/sqlite.cr')
-rw-r--r-- | src/sqlite.cr | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/src/sqlite.cr b/src/sqlite.cr index 2975031..0032694 100644 --- a/src/sqlite.cr +++ b/src/sqlite.cr @@ -75,6 +75,8 @@ class Database INSERT_APPLICANT = "INSERT INTO applicant (nick, opennic, icann) VALUES (%Q, %Q, %Q)" + alias UpdateAction = SQLite::UpdateAction + class Statement def initialize(db, query) Database.check SQLite.prepare db, query, LibC.strlen(query), @@ -160,30 +162,10 @@ class Database self.finalize raise ex end - SQLite.update_hook @ref, ->(arg, action, db, table, rowid) { - return unless db == "main" - obj = arg.as Database - case table - when "member" - case action - in .delete? - obj.members.delete rowid - in .insert?, .update? - obj.exec SELECT_MEMBER_ROW, rowid do |row| - obj.members[rowid] = {row[0].text, row[1].text, row[2].text} - end - end - when "applicant" - case action - in .delete? - obj.applicants.delete rowid - in .insert?, .update? - obj.exec SELECT_APPLICANT_ROW, rowid do |row| - obj.applicants[rowid] = {row[0].text, row[1].text, row[2].text} - end - end - end - }, self.as Void* + end + + def update_hook(callback, arg) + SQLite.update_hook @ref, callback, arg end def exec(query : String, *values) @@ -212,6 +194,18 @@ class Database getter members getter applicants + def update_member(rowid) + self.exec SELECT_MEMBER_ROW, rowid do |row| + self.members[rowid] = {row[0].text, row[1].text, row[2].text} + end + end + + def update_applicant(rowid) + self.exec SELECT_APPLICANT_ROW, rowid do |row| + self.applicants[rowid] = {row[0].text, row[1].text, row[2].text} + end + end + def add_applicant(nick, opennic, icann) self.exec INSERT_APPLICANT, nick, opennic, icann do end end |