Something went wrong. Try again.
the coolest token pot ever
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184// Code generated by sqlc. DO NOT EDIT.// versions:// sqlc v1.31.1// source: api_keys.sql
package store
import ( "context" "database/sql")
const addAPIKeySpend = `-- name: AddAPIKeySpend :execUPDATE api_keys SET spent_micros = spent_micros + ? WHERE id = ?`
type AddAPIKeySpendParams struct { SpentMicros int64 `json:"spent_micros"` ID string `json:"id"`}
func (q *Queries) AddAPIKeySpend(ctx context.Context, arg AddAPIKeySpendParams) error { _, err := q.db.ExecContext(ctx, addAPIKeySpend, arg.SpentMicros, arg.ID) return err}
const createAPIKey = `-- name: CreateAPIKey :oneINSERT INTO api_keys ( id, user_id, key_hash, key_word, key_last4, name, max_budget_micros, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)RETURNING id, user_id, key_hash, key_word, key_last4, name, max_budget_micros, spent_micros, last_used_at, created_at, revoked_at`
type CreateAPIKeyParams struct { ID string `json:"id"` UserID string `json:"user_id"` KeyHash string `json:"key_hash"` KeyWord string `json:"key_word"` KeyLast4 string `json:"key_last4"` Name string `json:"name"` MaxBudgetMicros sql.NullInt64 `json:"max_budget_micros"` CreatedAt int64 `json:"created_at"`}
func (q *Queries) CreateAPIKey(ctx context.Context, arg CreateAPIKeyParams) (ApiKey, error) { row := q.db.QueryRowContext(ctx, createAPIKey, arg.ID, arg.UserID, arg.KeyHash, arg.KeyWord, arg.KeyLast4, arg.Name, arg.MaxBudgetMicros, arg.CreatedAt, ) var i ApiKey err := row.Scan( &i.ID, &i.UserID, &i.KeyHash, &i.KeyWord, &i.KeyLast4, &i.Name, &i.MaxBudgetMicros, &i.SpentMicros, &i.LastUsedAt, &i.CreatedAt, &i.RevokedAt, ) return i, err}
const getAPIKeyByHash = `-- name: GetAPIKeyByHash :oneSELECT id, user_id, key_hash, key_word, key_last4, name, max_budget_micros, spent_micros, last_used_at, created_at, revoked_at FROM api_keys WHERE key_hash = ? AND revoked_at IS NULL`
func (q *Queries) GetAPIKeyByHash(ctx context.Context, keyHash string) (ApiKey, error) { row := q.db.QueryRowContext(ctx, getAPIKeyByHash, keyHash) var i ApiKey err := row.Scan( &i.ID, &i.UserID, &i.KeyHash, &i.KeyWord, &i.KeyLast4, &i.Name, &i.MaxBudgetMicros, &i.SpentMicros, &i.LastUsedAt, &i.CreatedAt, &i.RevokedAt, ) return i, err}
const listAPIKeysForUser = `-- name: ListAPIKeysForUser :manySELECT id, user_id, key_hash, key_word, key_last4, name, max_budget_micros, spent_micros, last_used_at, created_at, revoked_at FROM api_keysWHERE user_id = ?ORDER BY created_at DESC`
func (q *Queries) ListAPIKeysForUser(ctx context.Context, userID string) ([]ApiKey, error) { rows, err := q.db.QueryContext(ctx, listAPIKeysForUser, userID) if err != nil { return nil, err } defer rows.Close() items := []ApiKey{} for rows.Next() { var i ApiKey if err := rows.Scan( &i.ID, &i.UserID, &i.KeyHash, &i.KeyWord, &i.KeyLast4, &i.Name, &i.MaxBudgetMicros, &i.SpentMicros, &i.LastUsedAt, &i.CreatedAt, &i.RevokedAt, ); 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 renameAPIKey = `-- name: RenameAPIKey :execUPDATE api_keys SET name = ?WHERE id = ? AND user_id = ?`
type RenameAPIKeyParams struct { Name string `json:"name"` ID string `json:"id"` UserID string `json:"user_id"`}
func (q *Queries) RenameAPIKey(ctx context.Context, arg RenameAPIKeyParams) error { _, err := q.db.ExecContext(ctx, renameAPIKey, arg.Name, arg.ID, arg.UserID) return err}
const revokeAPIKey = `-- name: RevokeAPIKey :execUPDATE api_keys SET revoked_at = ?WHERE id = ? AND user_id = ? AND revoked_at IS NULL`
type RevokeAPIKeyParams struct { RevokedAt sql.NullInt64 `json:"revoked_at"` ID string `json:"id"` UserID string `json:"user_id"`}
func (q *Queries) RevokeAPIKey(ctx context.Context, arg RevokeAPIKeyParams) error { _, err := q.db.ExecContext(ctx, revokeAPIKey, arg.RevokedAt, arg.ID, arg.UserID) return err}
const touchAPIKey = `-- name: TouchAPIKey :execUPDATE api_keys SET last_used_at = ? WHERE id = ?`
type TouchAPIKeyParams struct { LastUsedAt sql.NullInt64 `json:"last_used_at"` ID string `json:"id"`}
// Debounced caller: only call when last_used_at is older than 60s.func (q *Queries) TouchAPIKey(ctx context.Context, arg TouchAPIKeyParams) error { _, err := q.db.ExecContext(ctx, touchAPIKey, arg.LastUsedAt, arg.ID) return err}