summaryrefslogtreecommitdiff
path: root/src/pyssg/db/queries.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/pyssg/db/queries.py')
-rw-r--r--src/pyssg/db/queries.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/pyssg/db/queries.py b/src/pyssg/db/queries.py
new file mode 100644
index 0000000..a5a4c32
--- /dev/null
+++ b/src/pyssg/db/queries.py
@@ -0,0 +1,44 @@
+CREATE_FILES_TABLE = """
+CREATE TABLE IF NOT EXISTS files(
+ file_name TEXT NOT NULL PRIMARY KEY,
+ create_time REAL NOT NULL,
+ modify_time REAL NOT NULL DEFAULT 0.0,
+ checksum TEXT NOT NULL,
+ tags TUPLE NULL
+)
+"""
+
+SELECT_FILE = """
+SELECT * FROM files WHERE file_name = ?
+"""
+
+SELECT_FILE_ALL = """
+SELECT * FROM files
+"""
+
+# when inserting, it is because the file is "just created",
+# no need to add modify_time
+INSERT_FILE = """
+INSERT INTO files(file_name, create_time, checksum, tags)
+VALUES (?, ?, ?, ?)
+RETURNING *
+"""
+
+# the create_time shouldn't be updated
+UPDATE_FILE = """
+UPDATE files
+SET modify_time = ?,
+ checksum = ?,
+ tags = ?
+WHERE file_name = ?
+RETURNING *
+"""
+
+# the create_time shouldn't be updated
+UPDATE_FILE_TAGS = """
+UPDATE files
+SET tags = ?
+WHERE file_name = ?
+RETURNING *
+"""
+