feat: add support for creating users and chirps

This commit is contained in:
Stevan Freeborn
2026-08-06 19:31:58 -05:00
parent d3811aa1b9
commit 5c5a126d88
14 changed files with 389 additions and 23 deletions
+10
View File
@@ -0,0 +1,10 @@
-- name: CreateChirp :one
INSERT INTO chirps (id, created_at, updated_at, body, user_id)
VALUES (
gen_random_uuid(),
NOW(),
NOW(),
$1,
$2
)
RETURNING *;
+17
View File
@@ -0,0 +1,17 @@
-- name: CreateUser :one
INSERT INTO users (id, created_at, updated_at, email)
VALUES (
gen_random_uuid(),
NOW(),
NOW(),
$1
)
RETURNING *;
-- name: DeleteAllUsers :exec
DELETE FROM users;
-- name: GetUserById :one
SELECT id, created_at, updated_at, email FROM users
WHERE id = $1;
+10
View File
@@ -0,0 +1,10 @@
-- +goose Up
CREATE TABLE users (
id UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
email TEXT UNIQUE NOT NULL
);
-- +goose Down
DROP TABLE users;
+12
View File
@@ -0,0 +1,12 @@
-- +goose Up
CREATE TABLE chirps (
id UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
body TEXT NOT NULL,
user_id UUID NOT NULL,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
);
-- +goose Down
DROP TABLE chirps;