kinda working
This commit is contained in:
20
sql/queries/notes.sql
Normal file
20
sql/queries/notes.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- name: CreateNote :exec
|
||||
INSERT INTO notes (id, created_at, updated_at, note, user_id)
|
||||
VALUES (?, ?, ?, ?, ?);
|
||||
--
|
||||
|
||||
-- name: GetNote :one
|
||||
SELECT * FROM notes WHERE id = ?;
|
||||
--
|
||||
|
||||
-- name: GetNotesForUser :many
|
||||
SELECT * FROM notes WHERE user_id = ?;
|
||||
--
|
||||
|
||||
-- name: UpdateNote :exec
|
||||
UPDATE notes SET updated_at = ?, note = ? WHERE id = ?;
|
||||
--
|
||||
|
||||
-- name: DeleteNote :exec
|
||||
DELETE FROM notes WHERE id = ?;
|
||||
--
|
||||
14
sql/queries/users.sql
Normal file
14
sql/queries/users.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- name: CreateUser :exec
|
||||
INSERT INTO users (id, created_at, updated_at, name, api_key)
|
||||
VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
);
|
||||
--
|
||||
|
||||
-- name: GetUserByAPIKey :one
|
||||
SELECT * FROM users WHERE api_key = ?;
|
||||
--
|
||||
11
sql/schema/001_users.sql
Normal file
11
sql/schema/001_users.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE users (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
api_key VARCHAR(64) UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE users;
|
||||
11
sql/schema/002_notes.sql
Normal file
11
sql/schema/002_notes.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE notes (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
note TEXT NOT NULL,
|
||||
user_id VARCHAR(36) NOT NULL REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE notes;
|
||||
Reference in New Issue
Block a user