lightning-terminal/db/sqlcmig6/sessions.sql.go
Viktor Torstensson 46449aa835
sqlcmig6: add sqlcmig6 package
This commit introduces the `sqlcmig6` package, which at the time of this
commit contains the same queries and models as `sqlc` package.
Importantly though, once the kvdb to sql migration is made available in
production, the `sqlcmig6` package will not change, as it is intended
to represent the sql db as it was at the time of the migration.

The sqlcmig6 package is therefore intended to be used in the kvdb to sql
migration code, as it is will always be compatible with the sql database
when all sql migrations prior to the kvdb to sql migration are applied.

When additional sql migrations are added in the future, they may effect
the `sqlc` package in such a way that the standard `sqlc` queries and
models aren't compatible with kvdb to sql migration code any longer.

By preserving the `sqlcmig6` package, we ensure that the kvdb to sql
migration code can always use the same queries and models that were
available at the time of the migration, even if the `sqlc` package
changes in the future.

Note that the `sqlcmig6` package have not been generated by `sqlc` (the
queries and models are copied from the `sqlc` package), as it is not
intended to be changed in the future.
2026-05-14 11:37:55 +02:00

685 lines
17 KiB
Go

package sqlcmig6
import (
"context"
"database/sql"
"time"
)
const deleteSession = `-- name: DeleteSession :exec
DELETE FROM sessions
WHERE id = $1
`
func (q *Queries) DeleteSession(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteSession, id)
return err
}
const deleteSessionsWithState = `-- name: DeleteSessionsWithState :exec
DELETE FROM sessions
WHERE state = $1
`
func (q *Queries) DeleteSessionsWithState(ctx context.Context, state int16) error {
_, err := q.db.ExecContext(ctx, deleteSessionsWithState, state)
return err
}
const getAliasBySessionID = `-- name: GetAliasBySessionID :one
SELECT alias FROM sessions
WHERE id = $1
`
func (q *Queries) GetAliasBySessionID(ctx context.Context, id int64) ([]byte, error) {
row := q.db.QueryRowContext(ctx, getAliasBySessionID, id)
var alias []byte
err := row.Scan(&alias)
return alias, err
}
const getSessionAliasesInGroup = `-- name: GetSessionAliasesInGroup :many
SELECT alias FROM sessions
WHERE group_id = $1
`
func (q *Queries) GetSessionAliasesInGroup(ctx context.Context, groupID sql.NullInt64) ([][]byte, error) {
rows, err := q.db.QueryContext(ctx, getSessionAliasesInGroup, groupID)
if err != nil {
return nil, err
}
defer rows.Close()
var items [][]byte
for rows.Next() {
var alias []byte
if err := rows.Scan(&alias); err != nil {
return nil, err
}
items = append(items, alias)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getSessionByAlias = `-- name: GetSessionByAlias :one
SELECT id, alias, label, state, type, expiry, created_at, revoked_at, server_address, dev_server, macaroon_root_key, pairing_secret, local_private_key, local_public_key, remote_public_key, privacy, account_id, group_id FROM sessions
WHERE alias = $1
`
func (q *Queries) GetSessionByAlias(ctx context.Context, alias []byte) (Session, error) {
row := q.db.QueryRowContext(ctx, getSessionByAlias, alias)
var i Session
err := row.Scan(
&i.ID,
&i.Alias,
&i.Label,
&i.State,
&i.Type,
&i.Expiry,
&i.CreatedAt,
&i.RevokedAt,
&i.ServerAddress,
&i.DevServer,
&i.MacaroonRootKey,
&i.PairingSecret,
&i.LocalPrivateKey,
&i.LocalPublicKey,
&i.RemotePublicKey,
&i.Privacy,
&i.AccountID,
&i.GroupID,
)
return i, err
}
const getSessionByID = `-- name: GetSessionByID :one
SELECT id, alias, label, state, type, expiry, created_at, revoked_at, server_address, dev_server, macaroon_root_key, pairing_secret, local_private_key, local_public_key, remote_public_key, privacy, account_id, group_id FROM sessions
WHERE id = $1
`
func (q *Queries) GetSessionByID(ctx context.Context, id int64) (Session, error) {
row := q.db.QueryRowContext(ctx, getSessionByID, id)
var i Session
err := row.Scan(
&i.ID,
&i.Alias,
&i.Label,
&i.State,
&i.Type,
&i.Expiry,
&i.CreatedAt,
&i.RevokedAt,
&i.ServerAddress,
&i.DevServer,
&i.MacaroonRootKey,
&i.PairingSecret,
&i.LocalPrivateKey,
&i.LocalPublicKey,
&i.RemotePublicKey,
&i.Privacy,
&i.AccountID,
&i.GroupID,
)
return i, err
}
const getSessionByLocalPublicKey = `-- name: GetSessionByLocalPublicKey :one
SELECT id, alias, label, state, type, expiry, created_at, revoked_at, server_address, dev_server, macaroon_root_key, pairing_secret, local_private_key, local_public_key, remote_public_key, privacy, account_id, group_id FROM sessions
WHERE local_public_key = $1
`
func (q *Queries) GetSessionByLocalPublicKey(ctx context.Context, localPublicKey []byte) (Session, error) {
row := q.db.QueryRowContext(ctx, getSessionByLocalPublicKey, localPublicKey)
var i Session
err := row.Scan(
&i.ID,
&i.Alias,
&i.Label,
&i.State,
&i.Type,
&i.Expiry,
&i.CreatedAt,
&i.RevokedAt,
&i.ServerAddress,
&i.DevServer,
&i.MacaroonRootKey,
&i.PairingSecret,
&i.LocalPrivateKey,
&i.LocalPublicKey,
&i.RemotePublicKey,
&i.Privacy,
&i.AccountID,
&i.GroupID,
)
return i, err
}
const getSessionFeatureConfigs = `-- name: GetSessionFeatureConfigs :many
SELECT session_id, feature_name, config FROM session_feature_configs
WHERE session_id = $1
`
func (q *Queries) GetSessionFeatureConfigs(ctx context.Context, sessionID int64) ([]SessionFeatureConfig, error) {
rows, err := q.db.QueryContext(ctx, getSessionFeatureConfigs, sessionID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SessionFeatureConfig
for rows.Next() {
var i SessionFeatureConfig
if err := rows.Scan(&i.SessionID, &i.FeatureName, &i.Config); 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 getSessionIDByAlias = `-- name: GetSessionIDByAlias :one
SELECT id FROM sessions
WHERE alias = $1
`
func (q *Queries) GetSessionIDByAlias(ctx context.Context, alias []byte) (int64, error) {
row := q.db.QueryRowContext(ctx, getSessionIDByAlias, alias)
var id int64
err := row.Scan(&id)
return id, err
}
const getSessionMacaroonCaveats = `-- name: GetSessionMacaroonCaveats :many
SELECT id, session_id, caveat_id, verification_id, location FROM session_macaroon_caveats
WHERE session_id = $1
`
func (q *Queries) GetSessionMacaroonCaveats(ctx context.Context, sessionID int64) ([]SessionMacaroonCaveat, error) {
rows, err := q.db.QueryContext(ctx, getSessionMacaroonCaveats, sessionID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SessionMacaroonCaveat
for rows.Next() {
var i SessionMacaroonCaveat
if err := rows.Scan(
&i.ID,
&i.SessionID,
&i.CaveatID,
&i.VerificationID,
&i.Location,
); 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 getSessionMacaroonPermissions = `-- name: GetSessionMacaroonPermissions :many
SELECT id, session_id, entity, action FROM session_macaroon_permissions
WHERE session_id = $1
`
func (q *Queries) GetSessionMacaroonPermissions(ctx context.Context, sessionID int64) ([]SessionMacaroonPermission, error) {
rows, err := q.db.QueryContext(ctx, getSessionMacaroonPermissions, sessionID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SessionMacaroonPermission
for rows.Next() {
var i SessionMacaroonPermission
if err := rows.Scan(
&i.ID,
&i.SessionID,
&i.Entity,
&i.Action,
); 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 getSessionPrivacyFlags = `-- name: GetSessionPrivacyFlags :many
SELECT session_id, flag FROM session_privacy_flags
WHERE session_id = $1
`
func (q *Queries) GetSessionPrivacyFlags(ctx context.Context, sessionID int64) ([]SessionPrivacyFlag, error) {
rows, err := q.db.QueryContext(ctx, getSessionPrivacyFlags, sessionID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SessionPrivacyFlag
for rows.Next() {
var i SessionPrivacyFlag
if err := rows.Scan(&i.SessionID, &i.Flag); 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 getSessionsInGroup = `-- name: GetSessionsInGroup :many
SELECT id, alias, label, state, type, expiry, created_at, revoked_at, server_address, dev_server, macaroon_root_key, pairing_secret, local_private_key, local_public_key, remote_public_key, privacy, account_id, group_id FROM sessions
WHERE group_id = $1
`
func (q *Queries) GetSessionsInGroup(ctx context.Context, groupID sql.NullInt64) ([]Session, error) {
rows, err := q.db.QueryContext(ctx, getSessionsInGroup, groupID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Session
for rows.Next() {
var i Session
if err := rows.Scan(
&i.ID,
&i.Alias,
&i.Label,
&i.State,
&i.Type,
&i.Expiry,
&i.CreatedAt,
&i.RevokedAt,
&i.ServerAddress,
&i.DevServer,
&i.MacaroonRootKey,
&i.PairingSecret,
&i.LocalPrivateKey,
&i.LocalPublicKey,
&i.RemotePublicKey,
&i.Privacy,
&i.AccountID,
&i.GroupID,
); 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 insertSession = `-- name: InsertSession :one
INSERT INTO sessions (
alias, label, state, type, expiry, created_at,
server_address, dev_server, macaroon_root_key, pairing_secret,
local_private_key, local_public_key, remote_public_key, privacy, group_id, account_id
) VALUES (
$1, $2, $3, $4, $5, $6, $7,
$8, $9, $10, $11, $12,
$13, $14, $15, $16
) RETURNING id
`
type InsertSessionParams struct {
Alias []byte
Label string
State int16
Type int16
Expiry time.Time
CreatedAt time.Time
ServerAddress string
DevServer bool
MacaroonRootKey int64
PairingSecret []byte
LocalPrivateKey []byte
LocalPublicKey []byte
RemotePublicKey []byte
Privacy bool
GroupID sql.NullInt64
AccountID sql.NullInt64
}
func (q *Queries) InsertSession(ctx context.Context, arg InsertSessionParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertSession,
arg.Alias,
arg.Label,
arg.State,
arg.Type,
arg.Expiry,
arg.CreatedAt,
arg.ServerAddress,
arg.DevServer,
arg.MacaroonRootKey,
arg.PairingSecret,
arg.LocalPrivateKey,
arg.LocalPublicKey,
arg.RemotePublicKey,
arg.Privacy,
arg.GroupID,
arg.AccountID,
)
var id int64
err := row.Scan(&id)
return id, err
}
const insertSessionFeatureConfig = `-- name: InsertSessionFeatureConfig :exec
INSERT INTO session_feature_configs (
session_id, feature_name, config
) VALUES (
$1, $2, $3
)
`
type InsertSessionFeatureConfigParams struct {
SessionID int64
FeatureName string
Config []byte
}
func (q *Queries) InsertSessionFeatureConfig(ctx context.Context, arg InsertSessionFeatureConfigParams) error {
_, err := q.db.ExecContext(ctx, insertSessionFeatureConfig, arg.SessionID, arg.FeatureName, arg.Config)
return err
}
const insertSessionMacaroonCaveat = `-- name: InsertSessionMacaroonCaveat :exec
INSERT INTO session_macaroon_caveats (
session_id, caveat_id, verification_id, location
) VALUES (
$1, $2, $3, $4
)
`
type InsertSessionMacaroonCaveatParams struct {
SessionID int64
CaveatID []byte
VerificationID []byte
Location sql.NullString
}
func (q *Queries) InsertSessionMacaroonCaveat(ctx context.Context, arg InsertSessionMacaroonCaveatParams) error {
_, err := q.db.ExecContext(ctx, insertSessionMacaroonCaveat,
arg.SessionID,
arg.CaveatID,
arg.VerificationID,
arg.Location,
)
return err
}
const insertSessionMacaroonPermission = `-- name: InsertSessionMacaroonPermission :exec
INSERT INTO session_macaroon_permissions (
session_id, entity, action
) VALUES (
$1, $2, $3
)
`
type InsertSessionMacaroonPermissionParams struct {
SessionID int64
Entity string
Action string
}
func (q *Queries) InsertSessionMacaroonPermission(ctx context.Context, arg InsertSessionMacaroonPermissionParams) error {
_, err := q.db.ExecContext(ctx, insertSessionMacaroonPermission, arg.SessionID, arg.Entity, arg.Action)
return err
}
const insertSessionPrivacyFlag = `-- name: InsertSessionPrivacyFlag :exec
INSERT INTO session_privacy_flags (
session_id, flag
) VALUES (
$1, $2
)
`
type InsertSessionPrivacyFlagParams struct {
SessionID int64
Flag int32
}
func (q *Queries) InsertSessionPrivacyFlag(ctx context.Context, arg InsertSessionPrivacyFlagParams) error {
_, err := q.db.ExecContext(ctx, insertSessionPrivacyFlag, arg.SessionID, arg.Flag)
return err
}
const listSessions = `-- name: ListSessions :many
SELECT id, alias, label, state, type, expiry, created_at, revoked_at, server_address, dev_server, macaroon_root_key, pairing_secret, local_private_key, local_public_key, remote_public_key, privacy, account_id, group_id FROM sessions
ORDER BY created_at
`
func (q *Queries) ListSessions(ctx context.Context) ([]Session, error) {
rows, err := q.db.QueryContext(ctx, listSessions)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Session
for rows.Next() {
var i Session
if err := rows.Scan(
&i.ID,
&i.Alias,
&i.Label,
&i.State,
&i.Type,
&i.Expiry,
&i.CreatedAt,
&i.RevokedAt,
&i.ServerAddress,
&i.DevServer,
&i.MacaroonRootKey,
&i.PairingSecret,
&i.LocalPrivateKey,
&i.LocalPublicKey,
&i.RemotePublicKey,
&i.Privacy,
&i.AccountID,
&i.GroupID,
); 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 listSessionsByState = `-- name: ListSessionsByState :many
SELECT id, alias, label, state, type, expiry, created_at, revoked_at, server_address, dev_server, macaroon_root_key, pairing_secret, local_private_key, local_public_key, remote_public_key, privacy, account_id, group_id FROM sessions
WHERE state = $1
ORDER BY created_at
`
func (q *Queries) ListSessionsByState(ctx context.Context, state int16) ([]Session, error) {
rows, err := q.db.QueryContext(ctx, listSessionsByState, state)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Session
for rows.Next() {
var i Session
if err := rows.Scan(
&i.ID,
&i.Alias,
&i.Label,
&i.State,
&i.Type,
&i.Expiry,
&i.CreatedAt,
&i.RevokedAt,
&i.ServerAddress,
&i.DevServer,
&i.MacaroonRootKey,
&i.PairingSecret,
&i.LocalPrivateKey,
&i.LocalPublicKey,
&i.RemotePublicKey,
&i.Privacy,
&i.AccountID,
&i.GroupID,
); 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 listSessionsByType = `-- name: ListSessionsByType :many
SELECT id, alias, label, state, type, expiry, created_at, revoked_at, server_address, dev_server, macaroon_root_key, pairing_secret, local_private_key, local_public_key, remote_public_key, privacy, account_id, group_id FROM sessions
WHERE type = $1
ORDER BY created_at
`
func (q *Queries) ListSessionsByType(ctx context.Context, type_ int16) ([]Session, error) {
rows, err := q.db.QueryContext(ctx, listSessionsByType, type_)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Session
for rows.Next() {
var i Session
if err := rows.Scan(
&i.ID,
&i.Alias,
&i.Label,
&i.State,
&i.Type,
&i.Expiry,
&i.CreatedAt,
&i.RevokedAt,
&i.ServerAddress,
&i.DevServer,
&i.MacaroonRootKey,
&i.PairingSecret,
&i.LocalPrivateKey,
&i.LocalPublicKey,
&i.RemotePublicKey,
&i.Privacy,
&i.AccountID,
&i.GroupID,
); 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 setSessionGroupID = `-- name: SetSessionGroupID :exec
UPDATE sessions
SET group_id = $1
WHERE id = $2
`
type SetSessionGroupIDParams struct {
GroupID sql.NullInt64
ID int64
}
func (q *Queries) SetSessionGroupID(ctx context.Context, arg SetSessionGroupIDParams) error {
_, err := q.db.ExecContext(ctx, setSessionGroupID, arg.GroupID, arg.ID)
return err
}
const setSessionRemotePublicKey = `-- name: SetSessionRemotePublicKey :exec
UPDATE sessions
SET remote_public_key = $1
WHERE id = $2
`
type SetSessionRemotePublicKeyParams struct {
RemotePublicKey []byte
ID int64
}
func (q *Queries) SetSessionRemotePublicKey(ctx context.Context, arg SetSessionRemotePublicKeyParams) error {
_, err := q.db.ExecContext(ctx, setSessionRemotePublicKey, arg.RemotePublicKey, arg.ID)
return err
}
const setSessionRevokedAt = `-- name: SetSessionRevokedAt :exec
UPDATE sessions
SET revoked_at = $1
WHERE id = $2
`
type SetSessionRevokedAtParams struct {
RevokedAt sql.NullTime
ID int64
}
func (q *Queries) SetSessionRevokedAt(ctx context.Context, arg SetSessionRevokedAtParams) error {
_, err := q.db.ExecContext(ctx, setSessionRevokedAt, arg.RevokedAt, arg.ID)
return err
}
const updateSessionState = `-- name: UpdateSessionState :exec
UPDATE sessions
SET state = $1
WHERE id = $2
`
type UpdateSessionStateParams struct {
State int16
ID int64
}
func (q *Queries) UpdateSessionState(ctx context.Context, arg UpdateSessionStateParams) error {
_, err := q.db.ExecContext(ctx, updateSessionState, arg.State, arg.ID)
return err
}