notatest/server/pkg/data/notes.sql.go

106 lines
2.1 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: notes.sql
package data
import (
"context"
"github.com/google/uuid"
)
const createNote = `-- name: CreateNote :one
INSERT INTO notes (user_id)
VALUES ($1)
RETURNING id, user_id, created_at, updated_at
`
func (q *Queries) CreateNote(ctx context.Context, userID uuid.UUID) (Note, error) {
row := q.db.QueryRow(ctx, createNote, userID)
var i Note
err := row.Scan(
&i.ID,
&i.UserID,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteNote = `-- name: DeleteNote :exec
DELETE FROM notes
WHERE id = $1 AND user_id = $2
`
type DeleteNoteParams struct {
ID uuid.UUID `json:"id"`
UserID uuid.UUID `json:"user_id"`
}
func (q *Queries) DeleteNote(ctx context.Context, arg DeleteNoteParams) error {
_, err := q.db.Exec(ctx, deleteNote, arg.ID, arg.UserID)
return err
}
const getNote = `-- name: GetNote :one
SELECT id, user_id, created_at, updated_at FROM notes
WHERE id = $1 AND user_id = $2 LIMIT 1
`
type GetNoteParams struct {
ID uuid.UUID `json:"id"`
UserID uuid.UUID `json:"user_id"`
}
func (q *Queries) GetNote(ctx context.Context, arg GetNoteParams) (Note, error) {
row := q.db.QueryRow(ctx, getNote, arg.ID, arg.UserID)
var i Note
err := row.Scan(
&i.ID,
&i.UserID,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listNotes = `-- name: ListNotes :many
SELECT id, user_id, created_at, updated_at FROM notes
WHERE user_id = $1
ORDER BY created_at DESC
LIMIT $2 OFFSET $3
`
type ListNotesParams struct {
UserID uuid.UUID `json:"user_id"`
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
func (q *Queries) ListNotes(ctx context.Context, arg ListNotesParams) ([]Note, error) {
rows, err := q.db.Query(ctx, listNotes, arg.UserID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Note
for rows.Next() {
var i Note
if err := rows.Scan(
&i.ID,
&i.UserID,
&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
}