mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
104 lines
2.5 KiB
Go
104 lines
2.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: versions.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const getVersionSnapshotID = `-- name: GetVersionSnapshotID :one
|
|
SELECT snapshot_id FROM container_versions WHERE container_id = $1 AND version = $2
|
|
`
|
|
|
|
type GetVersionSnapshotIDParams struct {
|
|
ContainerID string `json:"container_id"`
|
|
Version int32 `json:"version"`
|
|
}
|
|
|
|
func (q *Queries) GetVersionSnapshotID(ctx context.Context, arg GetVersionSnapshotIDParams) (string, error) {
|
|
row := q.db.QueryRow(ctx, getVersionSnapshotID, arg.ContainerID, arg.Version)
|
|
var snapshot_id string
|
|
err := row.Scan(&snapshot_id)
|
|
return snapshot_id, err
|
|
}
|
|
|
|
const insertVersion = `-- name: InsertVersion :one
|
|
INSERT INTO container_versions (id, container_id, snapshot_id, version)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4
|
|
)
|
|
RETURNING id, container_id, snapshot_id, version, created_at
|
|
`
|
|
|
|
type InsertVersionParams struct {
|
|
ID string `json:"id"`
|
|
ContainerID string `json:"container_id"`
|
|
SnapshotID string `json:"snapshot_id"`
|
|
Version int32 `json:"version"`
|
|
}
|
|
|
|
func (q *Queries) InsertVersion(ctx context.Context, arg InsertVersionParams) (ContainerVersion, error) {
|
|
row := q.db.QueryRow(ctx, insertVersion,
|
|
arg.ID,
|
|
arg.ContainerID,
|
|
arg.SnapshotID,
|
|
arg.Version,
|
|
)
|
|
var i ContainerVersion
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ContainerID,
|
|
&i.SnapshotID,
|
|
&i.Version,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listVersionsByContainerID = `-- name: ListVersionsByContainerID :many
|
|
SELECT id, container_id, snapshot_id, version, created_at FROM container_versions WHERE container_id = $1 ORDER BY version ASC
|
|
`
|
|
|
|
func (q *Queries) ListVersionsByContainerID(ctx context.Context, containerID string) ([]ContainerVersion, error) {
|
|
rows, err := q.db.Query(ctx, listVersionsByContainerID, containerID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ContainerVersion
|
|
for rows.Next() {
|
|
var i ContainerVersion
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ContainerID,
|
|
&i.SnapshotID,
|
|
&i.Version,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const nextVersion = `-- name: NextVersion :one
|
|
SELECT COALESCE(MAX(version), 0) + 1 FROM container_versions WHERE container_id = $1
|
|
`
|
|
|
|
func (q *Queries) NextVersion(ctx context.Context, containerID string) (int32, error) {
|
|
row := q.db.QueryRow(ctx, nextVersion, containerID)
|
|
var column_1 int32
|
|
err := row.Scan(&column_1)
|
|
return column_1, err
|
|
}
|