ae 62b1a58e56
feat!: trimming & logic/schema improvements
- build: somewhat polished dockerization setup
- build: io/fs migrations with `golang-migrate`
- feat: automatic init. admin account creation (.env creds)
- feat(routers): combined user & token routers into single auth router
- feat(routers): improved route layouts (`Routes`)
- feat(middlewares): removed redundant `userCtx` middleware
- fix(schema): note <-> note_versions relation (versioning)
- feat(queries): removed redundant rollback functionality
- feat(queries): combined duplicate version check & insertion/creation
- tests: decreased redundancy by removing 'unnecessary' unit tests
- refactor: hid internal packages behind `server/internal`
- docs: notes & auth handler comments
2025-04-09 01:58:38 +03:00

37 lines
812 B
SQL

-- name: CreateNote :one
INSERT INTO notes (user_id)
VALUES ($1)
RETURNING *;
-- name: ListNotes :many
SELECT
n.id AS note_id,
n.user_id AS owner_id,
nv.title,
n.updated_at
FROM notes n
JOIN note_versions nv
ON n.id = nv.note_id AND n.current_version = nv.version_number
WHERE n.user_id = $1
ORDER BY n.updated_at DESC
LIMIT $2 OFFSET $3;
-- name: GetFullNote :one
SELECT
n.id AS note_id,
n.user_id AS owner_id,
nv.title,
nv.content,
nv.version_number,
nv.created_at AS version_created_at,
n.created_at AS note_created_at,
n.updated_at AS note_updated_at
FROM notes n
JOIN note_versions nv
ON n.id = nv.note_id AND n.current_version = nv.version_number
WHERE n.id = $1;
-- name: DeleteNote :exec
DELETE FROM notes
WHERE id = $1 AND user_id = $2;