Forget-Me-Not/helpers/db.nim

36 lines
2.6 KiB
Nim

#[Copyright 2024 ITwrx.
This file is part of Simple Site Manager.
Simple Site Manager is released under the GNU Affero General Public License 3.0.
See COPYING or <https://www.gnu.org/licenses/> for details.]#
import sqliteral
#### Db1 ###
const RemindersSchema* = "CREATE TABLE IF NOT EXISTS Reminders(id INTEGER PRIMARY KEY, title TEXT, message TEXT, notify_via TEXT, repeats INTEGER, repeat_freq TEXT, weekly_on TEXT, monthly_on_day INTEGER, monthly_on_weekday TEXT, monthly_on_week TEXT, yearly_on_month TEXT, yearly_on_day INTEGER, yearly_on_week TEXT, yearly_on_weekday TEXT, yearly_on_month2 TEXT, send_date TEXT, send_time_hr INTEGER, send_time_min INTEGER, send_time_am_pm TEXT)"
const UsersSchema* = "CREATE TABLE IF NOT EXISTS Users(id INTEGER PRIMARY KEY, email TEXT NOT NULL, password TEXT NOT NULL)"
const SessionsSchema* = "CREATE TABLE IF NOT EXISTS Sessions(id INTEGER PRIMARY KEY, session_id TEXT, user_id INTEGER, csrf_token TEXT NOT NULL)"
type
Db1Sql* = enum
#Reminders
SelectAllReminders = "SELECT * FROM Reminders"
InsertReminder = """INSERT INTO Reminders (title, message, notify_via, repeats, repeat_freq, weekly_on, monthly_on_day, monthly_on_weekday, monthly_on_week, yearly_on_month, yearly_on_day, yearly_on_week, yearly_on_weekday, yearly_on_month2, send_date, send_time_hr, send_time_min, send_time_am_pm) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"""
UpdateReminder = """UPDATE Reminders SET title = ?, message = ?, notify_via = ?, repeats = ?, repeat_freq = ?, weekly_on = ?, monthly_on_day = ?, monthly_on_weekday = ?, monthly_on_week = ?, yearly_on_month = ?, yearly_on_day = ?, yearly_on_week = ?, yearly_on_weekday = ?, yearly_on_month2 = ?, send_date = ?, send_time_hr = ?, send_time_min = ?, send_time_am_pm = ? WHERE id = ?"""
UpdateReminderSendDate = """UPDATE Reminders SET send_date = ? WHERE id = ?"""
DeleteReminder = """DELETE FROM Reminders WHERE id = ?"""
#Users
SelectUsersByEmail = """SELECT * FROM Users WHERE email = ?"""
SelectUserById = """SELECT * FROM Users WHERE id = ? LIMIT 1"""
InsertUser = """INSERT INTO Users (email, password) VALUES (?,?)"""
#Sessions
SelectSessions = "SELECT * FROM Sessions"
SelectSessionBySessionId = "SELECT * FROM Sessions WHERE session_id = ?"
InsertUserSession = """INSERT INTO Sessions (session_id, user_id, csrf_token) VALUES (?,?,?)"""
DeleteSessionBySessionId = """DELETE FROM Sessions WHERE session_id = ?"""
DeleteSessions = """DELETE FROM Sessions"""
SelectSessionByCsrfToken = """SELECT * FROM Sessions WHERE csrf_token = ?"""
InsertVisitorSession = """INSERT INTO Sessions (csrf_token) VALUES (?)"""
var
db1*: SQLiteral