first commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
-- name: CreateUser :exec
|
||||
INSERT INTO users (email, password_hash)
|
||||
VALUES ($1, $2);
|
||||
|
||||
-- name: GetUserByEmail :one
|
||||
SELECT * FROM users
|
||||
WHERE email = $1
|
||||
LIMIT 1;
|
||||
|
||||
-- name: GetUserByID :one
|
||||
SELECT * FROM users
|
||||
WHERE id = $1
|
||||
LIMIT 1;
|
||||
|
||||
-- name: UpdateUserPassword :one
|
||||
UPDATE users
|
||||
SET password_hash = $2,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: CreateRefreshToken :one
|
||||
INSERT INTO refresh_tokens (user_id, token, expires_at)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetRefreshToken :one
|
||||
SELECT * FROM refresh_tokens
|
||||
WHERE token = $1
|
||||
LIMIT 1;
|
||||
|
||||
-- name: DeleteRefreshToken :exec
|
||||
DELETE FROM refresh_tokens
|
||||
WHERE token = $1;
|
||||
|
||||
-- name: DeleteUserRefreshTokens :exec
|
||||
DELETE FROM refresh_tokens
|
||||
WHERE user_id = $1;
|
||||
|
||||
-- name: DeleteExpiredRefreshTokens :exec
|
||||
DELETE FROM refresh_tokens
|
||||
WHERE expires_at < now();
|
||||
@@ -0,0 +1,33 @@
|
||||
-- name: ListForms :many
|
||||
SELECT * FROM forms
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: GetFormByID :one
|
||||
SELECT * FROM forms
|
||||
WHERE id = $1
|
||||
LIMIT 1;
|
||||
|
||||
-- name: CreateForm :one
|
||||
INSERT INTO forms (user_id, title, description)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateForm :one
|
||||
UPDATE forms
|
||||
SET title = $2,
|
||||
description = $3,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteForm :exec
|
||||
DELETE FROM forms
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: IncrementResponseCount :one
|
||||
UPDATE forms
|
||||
SET response_count = response_count + 1,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
@@ -0,0 +1,18 @@
|
||||
-- name: CreateQuestionOption :one
|
||||
INSERT INTO question_options (form_id, question_id, label, position)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetOptionsByFormID :many
|
||||
SELECT * FROM question_options
|
||||
WHERE form_id = $1
|
||||
ORDER BY question_id, position ASC;
|
||||
|
||||
-- name: GetOptionsByQuestionID :many
|
||||
SELECT * FROM question_options
|
||||
WHERE form_id = $1 AND question_id = $2
|
||||
ORDER BY position ASC;
|
||||
|
||||
-- name: DeleteOptionsByFormID :exec
|
||||
DELETE FROM question_options
|
||||
WHERE form_id = $1;
|
||||
@@ -0,0 +1,13 @@
|
||||
-- name: CreateQuestion :one
|
||||
INSERT INTO questions (form_id, type, title, required, position)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetQuestionsByFormID :many
|
||||
SELECT * FROM questions
|
||||
WHERE form_id = $1
|
||||
ORDER BY position ASC;
|
||||
|
||||
-- name: DeleteQuestionsByFormID :exec
|
||||
DELETE FROM questions
|
||||
WHERE form_id = $1;
|
||||
Reference in New Issue
Block a user