···11+package utils
22+33+// StreamArray turns a given array into a receive-only chan that can be used to
44+// stream data to client.
55+func StreamArray[T any](array []T) <-chan T {
66+ ch := make(chan T, len(array))
77+88+ go func() {
99+ defer close(ch)
1010+1111+ for _, element := range array {
1212+ ch <- element
1313+ }
1414+ }()
1515+1616+ return ch
1717+}
···11+-- alter posts table to have published field.
22+ALTER TABLE "posts"
33+ADD COLUMN "published" BOOLEAN;
44+55+-- set all published column values to false
66+UPDATE "posts"
77+SET
88+ "published" = 'f';
99+1010+-- require all published fields to be non-null (should be ensured by above)
1111+ALTER TABLE "posts"
1212+ALTER COLUMN "published"
1313+SET
1414+ NOT NULL;
1515+1616+-- set default value for future posts to be FALSE
1717+ALTER TABLE "posts"
1818+ALTER COLUMN "published"
1919+SET DEFAULT FALSE;
+3
queries/auth.sql
···44-- name: GetExpiredAuths :many
55SELECT * FROM "authorisations" WHERE "expiry" <= current_timestamp;
6677+-- name: GetAuthByToken :one
88+SELECT * FROM "authorisations" WHERE "id" = @id::uuid LIMIT 1;
99+710-- name: CheckAuthExists :one
811SELECT EXISTS (SELECT * FROM "authorisations" WHERE "id" = @id::uuid);
912
+9-3
queries/posts.sql
···11-- name: CreatePost :one
22-INSERT INTO "posts" (slug, content)
22+INSERT INTO "posts" (slug, content)
33VALUES (@slug::text, @content::json)
44RETURNING *;
5566--- name: GetPosts :many
77-SELECT * FROM "posts";66+-- name: GetPublishedPosts :many
77+SELECT * FROM "posts" WHERE published = TRUE;
88+99+-- name: GetPostByID :one
1010+SELECT * FROM "posts" WHERE id = @id::uuid LIMIT 1;
1111+1212+-- name: GetAllPosts :many
1313+SELECT * FROM "posts";