yenu/resources/sql/queries.sql

114 lines
2.4 KiB
MySQL
Raw Normal View History

2017-03-04 00:43:17 +01:00
-- :name create-image! :i!
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
2017-03-29 22:48:29 +02:00
DELETE FROM images
WHERE id = :id
2017-03-04 00:43:17 +01:00
-- :name get-all-images :? :*
SELECT * FROM images
2017-03-17 00:23:13 +01:00
ORDER BY created_at DESC
2017-03-04 00:43:17 +01:00
LIMIT :count OFFSET :offset
2017-03-17 00:23:13 +01:00
-- :name get-image-count :? :1
SELECT COUNT(id) as count FROM images
-- :name get-next-image :? :1
SELECT * FROM images
WHERE created_at > :image-date
ORDER BY created_at ASC
LIMIT 1
-- :name get-prev-image :? :1
SELECT * FROM images
WHERE created_at < :image-date
ORDER BY created_at DESC
LIMIT 1
2017-04-03 21:50:41 +02:00
-- :name edit-image! :! :1
UPDATE images
SET title = :title, description = :description
WHERE id = :id
2017-04-15 22:45:43 +02:00
-- :name set-image-hash :! :1
UPDATE images
SET hash = :hash
WHERE id = :id
-- :name get-first-year :? :1
SELECT created_at FROM images
ORDER BY created_at ASC
LIMIT 1
-- :name get-recent-year :? :1
SELECT created_at FROM images
ORDER BY created_at DESC
LIMIT 1
2017-03-04 00:43:17 +01:00
-- :name create-tag! :i!
INSERT OR IGNORE INTO tags (tagname)
VALUES (:tagname)
2017-03-04 00:43:17 +01:00
-- :name add-tag-to-image! :!
INSERT OR IGNORE INTO image_tags (image_id, tag_id)
VALUES (:imageid, :tagid)
2017-03-29 22:48:29 +02:00
-- :name delete-image-tags! :!
DELETE FROM image_tags
WHERE image_id = :id
2017-03-04 00:43:17 +01:00
-- :name get-tag :? :1
SELECT * FROM tags
WHERE tagname = :tagname
-- :name get-tags-for-image :? :*
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
2017-03-04 00:43:17 +01:00
-- :name get-images-for-tagname :? :*
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)
2017-03-04 00:43:17 +01:00
-- :name get-comments-for-image :? :*
SELECT * FROM comments
WHERE image_id = :image_id
2017-04-03 21:21:48 +02:00
ORDER BY created_at ASC
2017-04-15 23:08:11 +02:00
-- :name get-comment :? :1
SELECT * FROM comments
WHERE id = :id
LIMIT 1
-- :name delete-comment! :! :1
DELETE FROM comments
WHERE id = :id
2017-03-04 00:43:17 +01:00
-- :name get-recent-comments :? :*
2017-04-03 21:21:48 +02:00
SELECT comments.*, images.title FROM comments
LEFT JOIN images ON images.id = comments.image_id
ORDER BY created_at DESC
LIMIT :num-comments
2017-03-29 22:48:29 +02:00
-- :name delete-image-comments! :!
DELETE FROM comments
WHERE image_id = :id