From 953bfc5fb083dae568580b0f2d5481761bf742d0 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 20 Sep 2022 19:21:54 +0100 Subject: [PATCH] implement the 'add and get' functionality for storage routes. --- src/nera.lisp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/nera.lisp b/src/nera.lisp index e5148cc..9f0fcad 100644 --- a/src/nera.lisp +++ b/src/nera.lisp @@ -8,6 +8,7 @@ #:utils #:user #:pages + #:files #:site-settings) (:export #:init-db #:update-user @@ -29,10 +30,13 @@ #:get-all-pages #:nav-menu-slugs #:update-nav-menu - #:system-data)) + #:system-data + #:add-storage-file + #:get-storage-file + #:get-all-storage-files)) (in-package #:nera-db) -(defparameter *tables* '(user site-settings page) +(defparameter *tables* '(user site-settings page storage-file) "List of the DB tables that need to be checked for migrations and DB setup.") (defun init-db (request) @@ -228,3 +232,22 @@ (defun system-data () "Gets the website's settings and nav-menu from database." (list (get-site-settings) (nav-menu-slugs))) + +(defun add-storage-file (filename slug file-type) + "Add a row to the 'storage_file' table in the database." + (with-connection (db) + (mito:create-dao 'storage-file + :name filename + :slug slug + :file-type file-type))) + +(defun get-storage-file (filename) + "Returns a `STORAGE-FILE' row from the database. `NIL' if nothing found." + (with-connection (db) + (mito:find-dao 'storage-file :name filename))) + +(defun get-all-storage-files () + "Returns a list of all `STORAGE-FILES' entries in the database." + (with-connection (db) + (mito:select-dao 'storage-file + (sxql:order-by (:asc :name)))))