133 lines
3.3 KiB
Go
133 lines
3.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: note_versions.sql
|
|
|
|
package data
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createNoteVersion = `-- name: CreateNoteVersion :one
|
|
INSERT INTO note_versions (note_id, title, content, version_number, content_hash)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
(SELECT COALESCE(MAX(version_number), 0) + 1 FROM note_versions WHERE note_id = $1),
|
|
encode(sha256($2::bytea || '\n'::bytea || $3::bytea), 'hex')
|
|
)
|
|
RETURNING id, note_id, title, content, version_number, content_hash, created_at
|
|
`
|
|
|
|
type CreateNoteVersionParams struct {
|
|
NoteID uuid.UUID `json:"note_id"`
|
|
Title string `json:"title"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
func (q *Queries) CreateNoteVersion(ctx context.Context, arg CreateNoteVersionParams) (NoteVersion, error) {
|
|
row := q.db.QueryRow(ctx, createNoteVersion, arg.NoteID, arg.Title, arg.Content)
|
|
var i NoteVersion
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.NoteID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.VersionNumber,
|
|
&i.ContentHash,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const findDuplicateContent = `-- name: FindDuplicateContent :one
|
|
SELECT EXISTS(
|
|
SELECT 1 FROM note_versions
|
|
WHERE note_id = $1
|
|
AND content_hash = encode(sha256($2::bytea || '\n'::bytea || $3::bytea), 'hex')
|
|
)
|
|
`
|
|
|
|
type FindDuplicateContentParams struct {
|
|
NoteID uuid.UUID `json:"note_id"`
|
|
Column2 []byte `json:"column_2"`
|
|
Column3 []byte `json:"column_3"`
|
|
}
|
|
|
|
func (q *Queries) FindDuplicateContent(ctx context.Context, arg FindDuplicateContentParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, findDuplicateContent, arg.NoteID, arg.Column2, arg.Column3)
|
|
var exists bool
|
|
err := row.Scan(&exists)
|
|
return exists, err
|
|
}
|
|
|
|
const getNoteVersion = `-- name: GetNoteVersion :one
|
|
SELECT id, note_id, title, content, version_number, content_hash, created_at FROM note_versions
|
|
WHERE note_id = $1 AND version_number = $2 LIMIT 1
|
|
`
|
|
|
|
type GetNoteVersionParams struct {
|
|
NoteID uuid.UUID `json:"note_id"`
|
|
VersionNumber int32 `json:"version_number"`
|
|
}
|
|
|
|
func (q *Queries) GetNoteVersion(ctx context.Context, arg GetNoteVersionParams) (NoteVersion, error) {
|
|
row := q.db.QueryRow(ctx, getNoteVersion, arg.NoteID, arg.VersionNumber)
|
|
var i NoteVersion
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.NoteID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.VersionNumber,
|
|
&i.ContentHash,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getNoteVersions = `-- name: GetNoteVersions :many
|
|
SELECT id, note_id, title, content, version_number, content_hash, created_at FROM note_versions
|
|
WHERE note_id = $1
|
|
ORDER BY version_number DESC
|
|
LIMIT $2 OFFSET $3
|
|
`
|
|
|
|
type GetNoteVersionsParams struct {
|
|
NoteID uuid.UUID `json:"note_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) GetNoteVersions(ctx context.Context, arg GetNoteVersionsParams) ([]NoteVersion, error) {
|
|
rows, err := q.db.Query(ctx, getNoteVersions, arg.NoteID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []NoteVersion
|
|
for rows.Next() {
|
|
var i NoteVersion
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.NoteID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.VersionNumber,
|
|
&i.ContentHash,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|