mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-12-06 07:24:19 +00:00
235 lines
6.0 KiB
Go
235 lines
6.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: user_atlas.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const bumpUserAtlas = `-- name: BumpUserAtlas :one
|
|
UPDATE user_atlas SET range = $2, revision = revision + 1, updated_at = now() WHERE user_id = $1 RETURNING revision
|
|
`
|
|
|
|
type BumpUserAtlasParams struct {
|
|
UserID uuid.UUID `json:"user_id"`
|
|
Range string `json:"range"`
|
|
}
|
|
|
|
func (q *Queries) BumpUserAtlas(ctx context.Context, arg BumpUserAtlasParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, bumpUserAtlas, arg.UserID, arg.Range)
|
|
var revision int64
|
|
err := row.Scan(&revision)
|
|
return revision, err
|
|
}
|
|
|
|
const deleteUserAtlasPins = `-- name: DeleteUserAtlasPins :exec
|
|
DELETE FROM user_atlas_pins WHERE user_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteUserAtlasPins(ctx context.Context, userID uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteUserAtlasPins, userID)
|
|
return err
|
|
}
|
|
|
|
const ensureUserAtlas = `-- name: EnsureUserAtlas :exec
|
|
INSERT INTO user_atlas (user_id) VALUES ($1) ON CONFLICT (user_id) DO NOTHING
|
|
`
|
|
|
|
// Creates the empty Atlas row (revision 0) so a first write has a row to lock.
|
|
func (q *Queries) EnsureUserAtlas(ctx context.Context, userID uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, ensureUserAtlas, userID)
|
|
return err
|
|
}
|
|
|
|
const getUserAtlas = `-- name: GetUserAtlas :one
|
|
SELECT range, revision FROM user_atlas WHERE user_id = $1
|
|
`
|
|
|
|
type GetUserAtlasRow struct {
|
|
Range string `json:"range"`
|
|
Revision int64 `json:"revision"`
|
|
}
|
|
|
|
func (q *Queries) GetUserAtlas(ctx context.Context, userID uuid.UUID) (GetUserAtlasRow, error) {
|
|
row := q.db.QueryRow(ctx, getUserAtlas, userID)
|
|
var i GetUserAtlasRow
|
|
err := row.Scan(&i.Range, &i.Revision)
|
|
return i, err
|
|
}
|
|
|
|
const insertUserAtlasPin = `-- name: InsertUserAtlasPin :exec
|
|
INSERT INTO user_atlas_pins (user_id, position, kind, public_key, name, tiles, view)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
`
|
|
|
|
type InsertUserAtlasPinParams struct {
|
|
UserID uuid.UUID `json:"user_id"`
|
|
Position int16 `json:"position"`
|
|
Kind string `json:"kind"`
|
|
PublicKey []byte `json:"public_key"`
|
|
Name string `json:"name"`
|
|
Tiles []string `json:"tiles"`
|
|
View *string `json:"view"`
|
|
}
|
|
|
|
func (q *Queries) InsertUserAtlasPin(ctx context.Context, arg InsertUserAtlasPinParams) error {
|
|
_, err := q.db.Exec(ctx, insertUserAtlasPin,
|
|
arg.UserID,
|
|
arg.Position,
|
|
arg.Kind,
|
|
arg.PublicKey,
|
|
arg.Name,
|
|
arg.Tiles,
|
|
arg.View,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const listUserAtlasPins = `-- name: ListUserAtlasPins :many
|
|
SELECT position, kind, public_key, name, tiles, view FROM user_atlas_pins WHERE user_id = $1 ORDER BY position
|
|
`
|
|
|
|
type ListUserAtlasPinsRow struct {
|
|
Position int16 `json:"position"`
|
|
Kind string `json:"kind"`
|
|
PublicKey []byte `json:"public_key"`
|
|
Name string `json:"name"`
|
|
Tiles []string `json:"tiles"`
|
|
View *string `json:"view"`
|
|
}
|
|
|
|
func (q *Queries) ListUserAtlasPins(ctx context.Context, userID uuid.UUID) ([]ListUserAtlasPinsRow, error) {
|
|
rows, err := q.db.Query(ctx, listUserAtlasPins, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListUserAtlasPinsRow{}
|
|
for rows.Next() {
|
|
var i ListUserAtlasPinsRow
|
|
if err := rows.Scan(
|
|
&i.Position,
|
|
&i.Kind,
|
|
&i.PublicKey,
|
|
&i.Name,
|
|
&i.Tiles,
|
|
&i.View,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const lockUserAtlas = `-- name: LockUserAtlas :one
|
|
SELECT range, revision FROM user_atlas WHERE user_id = $1 FOR UPDATE
|
|
`
|
|
|
|
type LockUserAtlasRow struct {
|
|
Range string `json:"range"`
|
|
Revision int64 `json:"revision"`
|
|
}
|
|
|
|
func (q *Queries) LockUserAtlas(ctx context.Context, userID uuid.UUID) (LockUserAtlasRow, error) {
|
|
row := q.db.QueryRow(ctx, lockUserAtlas, userID)
|
|
var i LockUserAtlasRow
|
|
err := row.Scan(&i.Range, &i.Revision)
|
|
return i, err
|
|
}
|
|
|
|
const nodeIDsByKeys = `-- name: NodeIDsByKeys :many
|
|
SELECT id, public_key FROM nodes WHERE public_key = ANY($1::bytea[])
|
|
`
|
|
|
|
type NodeIDsByKeysRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
PublicKey []byte `json:"public_key"`
|
|
}
|
|
|
|
func (q *Queries) NodeIDsByKeys(ctx context.Context, dollar_1 [][]byte) ([]NodeIDsByKeysRow, error) {
|
|
rows, err := q.db.Query(ctx, nodeIDsByKeys, dollar_1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []NodeIDsByKeysRow{}
|
|
for rows.Next() {
|
|
var i NodeIDsByKeysRow
|
|
if err := rows.Scan(&i.ID, &i.PublicKey); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const observerIDsByKeys = `-- name: ObserverIDsByKeys :many
|
|
SELECT id, public_key FROM observers WHERE public_key = ANY($1::bytea[])
|
|
`
|
|
|
|
type ObserverIDsByKeysRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
PublicKey []byte `json:"public_key"`
|
|
}
|
|
|
|
func (q *Queries) ObserverIDsByKeys(ctx context.Context, dollar_1 [][]byte) ([]ObserverIDsByKeysRow, error) {
|
|
rows, err := q.db.Query(ctx, observerIDsByKeys, dollar_1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ObserverIDsByKeysRow{}
|
|
for rows.Next() {
|
|
var i ObserverIDsByKeysRow
|
|
if err := rows.Scan(&i.ID, &i.PublicKey); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const observerKeysByIDs = `-- name: ObserverKeysByIDs :many
|
|
SELECT id, public_key FROM observers WHERE id = ANY($1::uuid[])
|
|
`
|
|
|
|
type ObserverKeysByIDsRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
PublicKey []byte `json:"public_key"`
|
|
}
|
|
|
|
func (q *Queries) ObserverKeysByIDs(ctx context.Context, dollar_1 []uuid.UUID) ([]ObserverKeysByIDsRow, error) {
|
|
rows, err := q.db.Query(ctx, observerKeysByIDs, dollar_1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ObserverKeysByIDsRow{}
|
|
for rows.Next() {
|
|
var i ObserverKeysByIDsRow
|
|
if err := rows.Scan(&i.ID, &i.PublicKey); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|