Files
History_Api/internal/gen/sqlc/revision.sql.go
AzenKain ac90236022
All checks were successful
Build and Release / release (push) Successful in 1m15s
UPDATE: Project Module
2026-04-25 14:05:15 +07:00

183 lines
4.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: revision.sql
package sqlc
import (
"context"
"encoding/json"
"github.com/jackc/pgx/v5/pgtype"
)
const createRevision = `-- name: CreateRevision :one
INSERT INTO revisions (
project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary
) VALUES (
$1, $2, $3, $4, $5, $6, $7
)
RETURNING id, project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary, is_deleted, created_at
`
type CreateRevisionParams struct {
ProjectID pgtype.UUID `json:"project_id"`
VersionNo int32 `json:"version_no"`
SnapshotJson json.RawMessage `json:"snapshot_json"`
SnapshotHash pgtype.Text `json:"snapshot_hash"`
ParentID pgtype.UUID `json:"parent_id"`
UserID pgtype.UUID `json:"user_id"`
EditSummary pgtype.Text `json:"edit_summary"`
}
func (q *Queries) CreateRevision(ctx context.Context, arg CreateRevisionParams) (Revision, error) {
row := q.db.QueryRow(ctx, createRevision,
arg.ProjectID,
arg.VersionNo,
arg.SnapshotJson,
arg.SnapshotHash,
arg.ParentID,
arg.UserID,
arg.EditSummary,
)
var i Revision
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.VersionNo,
&i.SnapshotJson,
&i.SnapshotHash,
&i.ParentID,
&i.UserID,
&i.EditSummary,
&i.IsDeleted,
&i.CreatedAt,
)
return i, err
}
const deleteRevision = `-- name: DeleteRevision :exec
UPDATE revisions
SET is_deleted = true
WHERE id = $1
`
func (q *Queries) DeleteRevision(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteRevision, id)
return err
}
const getRevisionById = `-- name: GetRevisionById :one
SELECT id, project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary, is_deleted, created_at
FROM revisions
WHERE id = $1 AND is_deleted = false
`
func (q *Queries) GetRevisionById(ctx context.Context, id pgtype.UUID) (Revision, error) {
row := q.db.QueryRow(ctx, getRevisionById, id)
var i Revision
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.VersionNo,
&i.SnapshotJson,
&i.SnapshotHash,
&i.ParentID,
&i.UserID,
&i.EditSummary,
&i.IsDeleted,
&i.CreatedAt,
)
return i, err
}
const getRevisionsByIDs = `-- name: GetRevisionsByIDs :many
SELECT id, project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary, is_deleted, created_at FROM revisions WHERE id = ANY($1::uuid[]) AND is_deleted = false
`
func (q *Queries) GetRevisionsByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]Revision, error) {
rows, err := q.db.Query(ctx, getRevisionsByIDs, dollar_1)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Revision{}
for rows.Next() {
var i Revision
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.VersionNo,
&i.SnapshotJson,
&i.SnapshotHash,
&i.ParentID,
&i.UserID,
&i.EditSummary,
&i.IsDeleted,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const searchRevisions = `-- name: SearchRevisions :many
SELECT id, project_id, version_no, snapshot_json, snapshot_hash, parent_id, user_id, edit_summary, is_deleted, created_at
FROM revisions
WHERE is_deleted = false
AND ($1::uuid IS NULL OR project_id = $1)
AND ($2::uuid IS NULL OR user_id = $2)
AND ($3::uuid IS NULL OR id < $3::uuid)
ORDER BY version_no DESC
LIMIT $4
`
type SearchRevisionsParams struct {
ProjectID pgtype.UUID `json:"project_id"`
UserID pgtype.UUID `json:"user_id"`
CursorID pgtype.UUID `json:"cursor_id"`
Limit int32 `json:"limit"`
}
func (q *Queries) SearchRevisions(ctx context.Context, arg SearchRevisionsParams) ([]Revision, error) {
rows, err := q.db.Query(ctx, searchRevisions,
arg.ProjectID,
arg.UserID,
arg.CursorID,
arg.Limit,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Revision{}
for rows.Next() {
var i Revision
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.VersionNo,
&i.SnapshotJson,
&i.SnapshotHash,
&i.ParentID,
&i.UserID,
&i.EditSummary,
&i.IsDeleted,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}