lightning-terminal/db/sqlc/kvstores.sql.go
Elle Mouton e8d72f7276
db/sqlc: kvstores schemas & queries
In this commit, we define the schemas and queries that are needed to
implement the firewalldb's KVStores in SQL.
2025-04-10 13:03:20 +02:00

345 lines
7.5 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.25.0
// source: kvstores.sql
package sqlc
import (
"context"
"database/sql"
)
const deleteAllTempKVStores = `-- name: DeleteAllTempKVStores :exec
DELETE FROM kvstores
WHERE perm = false
`
func (q *Queries) DeleteAllTempKVStores(ctx context.Context) error {
_, err := q.db.ExecContext(ctx, deleteAllTempKVStores)
return err
}
const deleteFeatureKVStoreRecord = `-- name: DeleteFeatureKVStoreRecord :exec
DELETE FROM kvstores
WHERE entry_key = $1
AND rule_id = $2
AND perm = $3
AND session_id = $4
AND feature_id = $5
`
type DeleteFeatureKVStoreRecordParams struct {
Key string
RuleID int64
Perm bool
SessionID sql.NullInt64
FeatureID sql.NullInt64
}
func (q *Queries) DeleteFeatureKVStoreRecord(ctx context.Context, arg DeleteFeatureKVStoreRecordParams) error {
_, err := q.db.ExecContext(ctx, deleteFeatureKVStoreRecord,
arg.Key,
arg.RuleID,
arg.Perm,
arg.SessionID,
arg.FeatureID,
)
return err
}
const deleteGlobalKVStoreRecord = `-- name: DeleteGlobalKVStoreRecord :exec
DELETE FROM kvstores
WHERE entry_key = $1
AND rule_id = $2
AND perm = $3
AND session_id IS NULL
AND feature_id IS NULL
`
type DeleteGlobalKVStoreRecordParams struct {
Key string
RuleID int64
Perm bool
}
func (q *Queries) DeleteGlobalKVStoreRecord(ctx context.Context, arg DeleteGlobalKVStoreRecordParams) error {
_, err := q.db.ExecContext(ctx, deleteGlobalKVStoreRecord, arg.Key, arg.RuleID, arg.Perm)
return err
}
const deleteSessionKVStoreRecord = `-- name: DeleteSessionKVStoreRecord :exec
DELETE FROM kvstores
WHERE entry_key = $1
AND rule_id = $2
AND perm = $3
AND session_id = $4
AND feature_id IS NULL
`
type DeleteSessionKVStoreRecordParams struct {
Key string
RuleID int64
Perm bool
SessionID sql.NullInt64
}
func (q *Queries) DeleteSessionKVStoreRecord(ctx context.Context, arg DeleteSessionKVStoreRecordParams) error {
_, err := q.db.ExecContext(ctx, deleteSessionKVStoreRecord,
arg.Key,
arg.RuleID,
arg.Perm,
arg.SessionID,
)
return err
}
const getFeatureID = `-- name: GetFeatureID :one
SELECT id
FROM features
WHERE name = $1
`
func (q *Queries) GetFeatureID(ctx context.Context, name string) (int64, error) {
row := q.db.QueryRowContext(ctx, getFeatureID, name)
var id int64
err := row.Scan(&id)
return id, err
}
const getFeatureKVStoreRecord = `-- name: GetFeatureKVStoreRecord :one
SELECT value
FROM kvstores
WHERE entry_key = $1
AND rule_id = $2
AND perm = $3
AND session_id = $4
AND feature_id = $5
`
type GetFeatureKVStoreRecordParams struct {
Key string
RuleID int64
Perm bool
SessionID sql.NullInt64
FeatureID sql.NullInt64
}
func (q *Queries) GetFeatureKVStoreRecord(ctx context.Context, arg GetFeatureKVStoreRecordParams) ([]byte, error) {
row := q.db.QueryRowContext(ctx, getFeatureKVStoreRecord,
arg.Key,
arg.RuleID,
arg.Perm,
arg.SessionID,
arg.FeatureID,
)
var value []byte
err := row.Scan(&value)
return value, err
}
const getGlobalKVStoreRecord = `-- name: GetGlobalKVStoreRecord :one
SELECT value
FROM kvstores
WHERE entry_key = $1
AND rule_id = $2
AND perm = $3
AND session_id IS NULL
AND feature_id IS NULL
`
type GetGlobalKVStoreRecordParams struct {
Key string
RuleID int64
Perm bool
}
func (q *Queries) GetGlobalKVStoreRecord(ctx context.Context, arg GetGlobalKVStoreRecordParams) ([]byte, error) {
row := q.db.QueryRowContext(ctx, getGlobalKVStoreRecord, arg.Key, arg.RuleID, arg.Perm)
var value []byte
err := row.Scan(&value)
return value, err
}
const getOrInsertFeatureID = `-- name: GetOrInsertFeatureID :one
INSERT INTO features (name)
VALUES ($1)
ON CONFLICT(name) DO UPDATE SET name = excluded.name
RETURNING id
`
func (q *Queries) GetOrInsertFeatureID(ctx context.Context, name string) (int64, error) {
row := q.db.QueryRowContext(ctx, getOrInsertFeatureID, name)
var id int64
err := row.Scan(&id)
return id, err
}
const getOrInsertRuleID = `-- name: GetOrInsertRuleID :one
INSERT INTO rules (name)
VALUES ($1)
ON CONFLICT(name) DO UPDATE SET name = excluded.name
RETURNING id
`
func (q *Queries) GetOrInsertRuleID(ctx context.Context, name string) (int64, error) {
row := q.db.QueryRowContext(ctx, getOrInsertRuleID, name)
var id int64
err := row.Scan(&id)
return id, err
}
const getRuleID = `-- name: GetRuleID :one
SELECT id
FROM rules
WHERE name = $1
`
func (q *Queries) GetRuleID(ctx context.Context, name string) (int64, error) {
row := q.db.QueryRowContext(ctx, getRuleID, name)
var id int64
err := row.Scan(&id)
return id, err
}
const getSessionKVStoreRecord = `-- name: GetSessionKVStoreRecord :one
SELECT value
FROM kvstores
WHERE entry_key = $1
AND rule_id = $2
AND perm = $3
AND session_id = $4
AND feature_id IS NULL
`
type GetSessionKVStoreRecordParams struct {
Key string
RuleID int64
Perm bool
SessionID sql.NullInt64
}
func (q *Queries) GetSessionKVStoreRecord(ctx context.Context, arg GetSessionKVStoreRecordParams) ([]byte, error) {
row := q.db.QueryRowContext(ctx, getSessionKVStoreRecord,
arg.Key,
arg.RuleID,
arg.Perm,
arg.SessionID,
)
var value []byte
err := row.Scan(&value)
return value, err
}
const insertKVStoreRecord = `-- name: InsertKVStoreRecord :exec
INSERT INTO kvstores (perm, rule_id, session_id, feature_id, entry_key, value)
VALUES ($1, $2, $3, $4, $5, $6)
`
type InsertKVStoreRecordParams struct {
Perm bool
RuleID int64
SessionID sql.NullInt64
FeatureID sql.NullInt64
EntryKey string
Value []byte
}
func (q *Queries) InsertKVStoreRecord(ctx context.Context, arg InsertKVStoreRecordParams) error {
_, err := q.db.ExecContext(ctx, insertKVStoreRecord,
arg.Perm,
arg.RuleID,
arg.SessionID,
arg.FeatureID,
arg.EntryKey,
arg.Value,
)
return err
}
const updateFeatureKVStoreRecord = `-- name: UpdateFeatureKVStoreRecord :exec
UPDATE kvstores
SET value = $1
WHERE entry_key = $2
AND rule_id = $3
AND perm = $4
AND session_id = $5
AND feature_id = $6
`
type UpdateFeatureKVStoreRecordParams struct {
Value []byte
Key string
RuleID int64
Perm bool
SessionID sql.NullInt64
FeatureID sql.NullInt64
}
func (q *Queries) UpdateFeatureKVStoreRecord(ctx context.Context, arg UpdateFeatureKVStoreRecordParams) error {
_, err := q.db.ExecContext(ctx, updateFeatureKVStoreRecord,
arg.Value,
arg.Key,
arg.RuleID,
arg.Perm,
arg.SessionID,
arg.FeatureID,
)
return err
}
const updateGlobalKVStoreRecord = `-- name: UpdateGlobalKVStoreRecord :exec
UPDATE kvstores
SET value = $1
WHERE entry_key = $2
AND rule_id = $3
AND perm = $4
AND session_id IS NULL
AND feature_id IS NULL
`
type UpdateGlobalKVStoreRecordParams struct {
Value []byte
Key string
RuleID int64
Perm bool
}
func (q *Queries) UpdateGlobalKVStoreRecord(ctx context.Context, arg UpdateGlobalKVStoreRecordParams) error {
_, err := q.db.ExecContext(ctx, updateGlobalKVStoreRecord,
arg.Value,
arg.Key,
arg.RuleID,
arg.Perm,
)
return err
}
const updateSessionKVStoreRecord = `-- name: UpdateSessionKVStoreRecord :exec
UPDATE kvstores
SET value = $1
WHERE entry_key = $2
AND rule_id = $3
AND perm = $4
AND session_id = $5
AND feature_id IS NULL
`
type UpdateSessionKVStoreRecordParams struct {
Value []byte
Key string
RuleID int64
Perm bool
SessionID sql.NullInt64
}
func (q *Queries) UpdateSessionKVStoreRecord(ctx context.Context, arg UpdateSessionKVStoreRecordParams) error {
_, err := q.db.ExecContext(ctx, updateSessionKVStoreRecord,
arg.Value,
arg.Key,
arg.RuleID,
arg.Perm,
arg.SessionID,
)
return err
}