-- name: CreateEntryWithKindName :one
INSERT INTO entries (title, kind, url, description) 
SELECT ?, kinds.id, ?, ?
FROM kinds
WHERE kinds.name = ?
RETURNING *;

-- name: UpdateEntryKind :one
UPDATE entries
SET kind = (SELECT id FROM kinds WHERE kinds.name = ?)
WHERE entries.id = ? 
RETURNING *;

-- name: DeleteEntry :execrows
DELETE FROM entries
WHERE id = ?;

-- name: GetEntries :many
SELECT title, url, description, timestamp, kinds.name as kind_name, kinds.emoji as kind_emoji FROM entries
JOIN kinds ON entries.kind == kinds.id
ORDER BY timestamp DESC;

-- name: GetEntriesByKind :many
SELECT title, url, description, timestamp, kinds.name as kind_name, kinds.emoji as kind_emoji FROM entries
JOIN kinds ON entries.kind == kinds.id
WHERE kinds.name = ?
ORDER BY timestamp DESC;

-- name: GetEntryURLs :many
SELECT url FROM entries
ORDER BY timestamp DESC;

-- name: GetEntryByUrl :one
SELECT entries.id, title, url, description, timestamp, kinds.name as kind_name, kinds.emoji as kind_emoji FROM entries
JOIN kinds ON entries.kind == kinds.id
WHERE url = ?
LIMIT 1;
