Something went wrong. Try again.
A mapping language to compose SQL for Go.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031-- Code generated by stitchql schema generate. DO NOT EDIT.
CREATE TABLE authors ( id bigint PRIMARY KEY, name text NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now(), CHECK (updated_at >= created_at));
CREATE TYPE book_status AS ENUM ('draft', 'published', 'out_of_print');
CREATE TABLE books ( id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, title text NOT NULL, author_id bigint NOT NULL REFERENCES authors(id), status book_status NOT NULL DEFAULT 'draft', created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now(), CHECK (updated_at >= created_at));
CREATE MATERIALIZED VIEW author_book_counts ASSELECT author_id, count(*) AS book_countFROM booksGROUP BY author_idWITH NO DATA;
CREATE UNIQUE INDEX author_book_counts_author_idxON author_book_counts(author_id);