Have got post creation working.

This commit is contained in:
Leon Mika 2025-01-27 14:23:54 +11:00
parent 63b19a249a
commit 8e0ffb6c24
20 changed files with 479 additions and 11 deletions

14
sql/queries/posts.sql Normal file
View file

@ -0,0 +1,14 @@
-- name: ListPosts :many
SELECT * FROM post WHERE site_id = $1 ORDER BY post_date DESC LIMIT 25;
-- name: InsertPost :one
INSERT INTO post (
site_id,
title,
body,
state,
props,
post_date,
created_at
) VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id;

View file

@ -1,8 +1,26 @@
CREATE TYPE post_state AS ENUM (
'draft',
'published'
);
CREATE TABLE site (
id BIGSERIAL NOT NULL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
title TEXT NOT NULL,
url TEXT NOT NULL,
theme TEXT NOT NULL,
props JSON NOT NULL
name TEXT NOT NULL UNIQUE,
title TEXT NOT NULL,
url TEXT NOT NULL,
theme TEXT NOT NULL,
props JSON NOT NULL
);
CREATE TABLE post (
id BIGSERIAL NOT NULL PRIMARY KEY,
site_id BIGINT NOT NULL,
title TEXT,
body TEXT NOT NULL,
state post_state NOT NULL,
props JSON NOT NULL,
post_date TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP NOT NULL,
FOREIGN KEY (site_id) REFERENCES site(id)
);