Files
ristek-task-be/internal/db/sqlc/repository/forms.sql.go
2026-02-22 00:15:25 +07:00

159 lines
3.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: forms.sql
package repository
import (
"context"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
const createForm = `-- name: CreateForm :one
INSERT INTO forms (user_id, title, description)
VALUES ($1, $2, $3)
RETURNING id, user_id, title, description, response_count, created_at, updated_at
`
type CreateFormParams struct {
UserID uuid.UUID
Title string
Description pgtype.Text
}
func (q *Queries) CreateForm(ctx context.Context, arg CreateFormParams) (Form, error) {
row := q.db.QueryRow(ctx, createForm, arg.UserID, arg.Title, arg.Description)
var i Form
err := row.Scan(
&i.ID,
&i.UserID,
&i.Title,
&i.Description,
&i.ResponseCount,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteForm = `-- name: DeleteForm :exec
DELETE FROM forms
WHERE id = $1
`
func (q *Queries) DeleteForm(ctx context.Context, id uuid.UUID) error {
_, err := q.db.Exec(ctx, deleteForm, id)
return err
}
const getFormByID = `-- name: GetFormByID :one
SELECT id, user_id, title, description, response_count, created_at, updated_at FROM forms
WHERE id = $1
LIMIT 1
`
func (q *Queries) GetFormByID(ctx context.Context, id uuid.UUID) (Form, error) {
row := q.db.QueryRow(ctx, getFormByID, id)
var i Form
err := row.Scan(
&i.ID,
&i.UserID,
&i.Title,
&i.Description,
&i.ResponseCount,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const incrementResponseCount = `-- name: IncrementResponseCount :one
UPDATE forms
SET response_count = response_count + 1,
updated_at = now()
WHERE id = $1
RETURNING id, user_id, title, description, response_count, created_at, updated_at
`
func (q *Queries) IncrementResponseCount(ctx context.Context, id uuid.UUID) (Form, error) {
row := q.db.QueryRow(ctx, incrementResponseCount, id)
var i Form
err := row.Scan(
&i.ID,
&i.UserID,
&i.Title,
&i.Description,
&i.ResponseCount,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listForms = `-- name: ListForms :many
SELECT id, user_id, title, description, response_count, created_at, updated_at FROM forms
WHERE user_id = $1
ORDER BY created_at DESC
`
func (q *Queries) ListForms(ctx context.Context, userID uuid.UUID) ([]Form, error) {
rows, err := q.db.Query(ctx, listForms, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Form
for rows.Next() {
var i Form
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Title,
&i.Description,
&i.ResponseCount,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateForm = `-- name: UpdateForm :one
UPDATE forms
SET title = $2,
description = $3,
updated_at = now()
WHERE id = $1
RETURNING id, user_id, title, description, response_count, created_at, updated_at
`
type UpdateFormParams struct {
ID uuid.UUID
Title string
Description pgtype.Text
}
func (q *Queries) UpdateForm(ctx context.Context, arg UpdateFormParams) (Form, error) {
row := q.db.QueryRow(ctx, updateForm, arg.ID, arg.Title, arg.Description)
var i Form
err := row.Scan(
&i.ID,
&i.UserID,
&i.Title,
&i.Description,
&i.ResponseCount,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}