yenu/resources/sql/queries.sql

49 lines
1.1 KiB
SQL

-- :name create-image! :! :n
INSERT INTO images (hash, title, description)
VALUES (:hash, :title, :description)
-- :name update-image! :! :n
UPDATE images
SET hash = :hash, title = :title, description = :description
WHERE id = :id
-- :name get-image :? :1
SELECT * FROM images WHERE id = :id
-- :name delete-image! :! :n
DELETE FROM image
WHERE id = :id
-- :name create-tag! :! :n
INSERT OR IGNORE INTO tags (tagname)
VALUES (:tagname)
-- :name get-tags-for-image :? :n
SELECT tags.tagname FROM image_tags
INNER JOIN tags ON tags.id = image_tags.tag_id
WHERE image_id = :id
ORDER BY tags.tagname ASC
-- :name get-images-for-tagname :? :n
SELECT images.* FROM image_tags
INNER JOIN images ON images.id = image_tags.image_id
INNER JOIN tags on tags.id = image_tags.tag_id
WHERE tags.tagname = :tagname
ORDER BY images.created_at DESC
-- :name create-comment! :! :n
INSERT INTO comments (image_id, author, comment)
VALUES (:image_id, :author, :comment)
-- :name get-comments-for-image :? :n
SELECT * FROM comments
WHERE image_id = :image_id
ORDER BY created_at DESC
-- :name get-recent-comments
SELECT * FROM comments
ORDER BY created_at DESC
LIMIT :num-comments