V3 version with backward comp
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: sync_queue.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createSyncQueueItem = `-- name: CreateSyncQueueItem :one
|
||||
INSERT INTO sync_queue (resource_id, storage_location_id, operation, status, attempts)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, resource_id, storage_location_id, operation, status, attempts, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateSyncQueueItemParams struct {
|
||||
ResourceID uuid.UUID `json:"resource_id"`
|
||||
StorageLocationID uuid.UUID `json:"storage_location_id"`
|
||||
Operation string `json:"operation"`
|
||||
Status string `json:"status"`
|
||||
Attempts int32 `json:"attempts"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateSyncQueueItem(ctx context.Context, arg CreateSyncQueueItemParams) (SyncQueue, error) {
|
||||
row := q.db.QueryRowContext(ctx, createSyncQueueItem,
|
||||
arg.ResourceID,
|
||||
arg.StorageLocationID,
|
||||
arg.Operation,
|
||||
arg.Status,
|
||||
arg.Attempts,
|
||||
)
|
||||
var i SyncQueue
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ResourceID,
|
||||
&i.StorageLocationID,
|
||||
&i.Operation,
|
||||
&i.Status,
|
||||
&i.Attempts,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteSyncQueueItem = `-- name: DeleteSyncQueueItem :exec
|
||||
DELETE FROM sync_queue
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteSyncQueueItem(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteSyncQueueItem, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getSyncQueueItem = `-- name: GetSyncQueueItem :one
|
||||
SELECT id, resource_id, storage_location_id, operation, status, attempts, created_at, updated_at FROM sync_queue
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSyncQueueItem(ctx context.Context, id uuid.UUID) (SyncQueue, error) {
|
||||
row := q.db.QueryRowContext(ctx, getSyncQueueItem, id)
|
||||
var i SyncQueue
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ResourceID,
|
||||
&i.StorageLocationID,
|
||||
&i.Operation,
|
||||
&i.Status,
|
||||
&i.Attempts,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listPendingSyncItems = `-- name: ListPendingSyncItems :many
|
||||
SELECT id, resource_id, storage_location_id, operation, status, attempts, created_at, updated_at FROM sync_queue
|
||||
WHERE status = 'pending'
|
||||
ORDER BY created_at ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListPendingSyncItems(ctx context.Context) ([]SyncQueue, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listPendingSyncItems)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SyncQueue
|
||||
for rows.Next() {
|
||||
var i SyncQueue
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ResourceID,
|
||||
&i.StorageLocationID,
|
||||
&i.Operation,
|
||||
&i.Status,
|
||||
&i.Attempts,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listPendingSyncItemsByLocation = `-- name: ListPendingSyncItemsByLocation :many
|
||||
SELECT id, resource_id, storage_location_id, operation, status, attempts, created_at, updated_at FROM sync_queue
|
||||
WHERE storage_location_id = $1 AND status = 'pending'
|
||||
ORDER BY created_at ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListPendingSyncItemsByLocation(ctx context.Context, storageLocationID uuid.UUID) ([]SyncQueue, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listPendingSyncItemsByLocation, storageLocationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SyncQueue
|
||||
for rows.Next() {
|
||||
var i SyncQueue
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ResourceID,
|
||||
&i.StorageLocationID,
|
||||
&i.Operation,
|
||||
&i.Status,
|
||||
&i.Attempts,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateSyncQueueStatus = `-- name: UpdateSyncQueueStatus :exec
|
||||
UPDATE sync_queue
|
||||
SET status = $1, attempts = $2, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $3
|
||||
`
|
||||
|
||||
type UpdateSyncQueueStatusParams struct {
|
||||
Status string `json:"status"`
|
||||
Attempts int32 `json:"attempts"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateSyncQueueStatus(ctx context.Context, arg UpdateSyncQueueStatusParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateSyncQueueStatus, arg.Status, arg.Attempts, arg.ID)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user