aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2021-07-25 14:20:38 -0400
committerGravatar - 2021-07-26 22:55:43 -0400
commit874feb8833d2d1d278205c38289fe25f84d9a123 (patch)
tree7489b8d1799a48adcfda4d28ddfde71b7e0ab480
parentadd list tags and list cards (diff)
move SQL schema setup to variable
-rwxr-xr-xunderwriter18
1 files changed, 9 insertions, 9 deletions
diff --git a/underwriter b/underwriter
index 0aa1f2a..f54b1fd 100755
--- a/underwriter
+++ b/underwriter
@@ -47,12 +47,8 @@ class Cursor(sqlite3.Cursor):
""", pairs
)
-class Context:
- @staticmethod
- def initdb(dbname):
- con = sqlite3.connect(dbname)
- con.executescript("""
-CREATE TABLE cards (id INTEGER PRIMARY KEY,
+initscript = \
+"""CREATE TABLE cards (id INTEGER PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
created INTEGER NOT NULL
);
@@ -74,8 +70,13 @@ CREATE TRIGGER tagmap_unique AFTER INSERT ON tagmap
WHEN (SELECT COUNT(*) FROM tagmap WHERE
NEW.tag = tag AND NEW.card = card LIMIT 2) > 1
BEGIN DELETE FROM tagmap WHERE NEW.rowid = rowid;
-END;
-""")
+END;"""
+
+class Context:
+ @staticmethod
+ def initdb(dbname):
+ con = sqlite3.connect(dbname)
+ con.executescript(initscript)
return con
def make_cursor(self):
@@ -133,7 +134,6 @@ untag file [tags...]: remove tags from a file
list [tags | cards]: list all tags or cards in the database
"""
-
if __name__ == "__main__":
args = sys.argv[1:]
db = "underwriter.db"