// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: api_keys.sql package db import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const deleteAPIKey = `-- name: DeleteAPIKey :exec DELETE FROM team_api_keys WHERE id = $1 AND team_id = $2 ` type DeleteAPIKeyParams struct { ID pgtype.UUID `json:"id"` TeamID pgtype.UUID `json:"team_id"` } func (q *Queries) DeleteAPIKey(ctx context.Context, arg DeleteAPIKeyParams) error { _, err := q.db.Exec(ctx, deleteAPIKey, arg.ID, arg.TeamID) return err } const deleteAPIKeysByCreator = `-- name: DeleteAPIKeysByCreator :exec DELETE FROM team_api_keys WHERE created_by = $1 ` func (q *Queries) DeleteAPIKeysByCreator(ctx context.Context, createdBy pgtype.UUID) error { _, err := q.db.Exec(ctx, deleteAPIKeysByCreator, createdBy) return err } const deleteAPIKeysByTeam = `-- name: DeleteAPIKeysByTeam :exec DELETE FROM team_api_keys WHERE team_id = $1 ` func (q *Queries) DeleteAPIKeysByTeam(ctx context.Context, teamID pgtype.UUID) error { _, err := q.db.Exec(ctx, deleteAPIKeysByTeam, teamID) return err } const getAPIKeyByHash = `-- name: GetAPIKeyByHash :one SELECT id, team_id, name, key_hash, key_prefix, created_by, created_at, last_used FROM team_api_keys WHERE key_hash = $1 ` func (q *Queries) GetAPIKeyByHash(ctx context.Context, keyHash string) (TeamApiKey, error) { row := q.db.QueryRow(ctx, getAPIKeyByHash, keyHash) var i TeamApiKey err := row.Scan( &i.ID, &i.TeamID, &i.Name, &i.KeyHash, &i.KeyPrefix, &i.CreatedBy, &i.CreatedAt, &i.LastUsed, ) return i, err } const insertAPIKey = `-- name: InsertAPIKey :one INSERT INTO team_api_keys (id, team_id, name, key_hash, key_prefix, created_by) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id, team_id, name, key_hash, key_prefix, created_by, created_at, last_used ` type InsertAPIKeyParams struct { ID pgtype.UUID `json:"id"` TeamID pgtype.UUID `json:"team_id"` Name string `json:"name"` KeyHash string `json:"key_hash"` KeyPrefix string `json:"key_prefix"` CreatedBy pgtype.UUID `json:"created_by"` } func (q *Queries) InsertAPIKey(ctx context.Context, arg InsertAPIKeyParams) (TeamApiKey, error) { row := q.db.QueryRow(ctx, insertAPIKey, arg.ID, arg.TeamID, arg.Name, arg.KeyHash, arg.KeyPrefix, arg.CreatedBy, ) var i TeamApiKey err := row.Scan( &i.ID, &i.TeamID, &i.Name, &i.KeyHash, &i.KeyPrefix, &i.CreatedBy, &i.CreatedAt, &i.LastUsed, ) return i, err } const listAPIKeysByTeam = `-- name: ListAPIKeysByTeam :many SELECT id, team_id, name, key_hash, key_prefix, created_by, created_at, last_used FROM team_api_keys WHERE team_id = $1 ORDER BY created_at DESC ` func (q *Queries) ListAPIKeysByTeam(ctx context.Context, teamID pgtype.UUID) ([]TeamApiKey, error) { rows, err := q.db.Query(ctx, listAPIKeysByTeam, teamID) if err != nil { return nil, err } defer rows.Close() var items []TeamApiKey for rows.Next() { var i TeamApiKey if err := rows.Scan( &i.ID, &i.TeamID, &i.Name, &i.KeyHash, &i.KeyPrefix, &i.CreatedBy, &i.CreatedAt, &i.LastUsed, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listAPIKeysByTeamWithCreator = `-- name: ListAPIKeysByTeamWithCreator :many SELECT k.id, k.team_id, k.name, k.key_hash, k.key_prefix, k.created_by, k.created_at, k.last_used, u.email AS creator_email FROM team_api_keys k LEFT JOIN users u ON u.id = k.created_by WHERE k.team_id = $1 ORDER BY k.created_at DESC ` type ListAPIKeysByTeamWithCreatorRow struct { ID pgtype.UUID `json:"id"` TeamID pgtype.UUID `json:"team_id"` Name string `json:"name"` KeyHash string `json:"key_hash"` KeyPrefix string `json:"key_prefix"` CreatedBy pgtype.UUID `json:"created_by"` CreatedAt pgtype.Timestamptz `json:"created_at"` LastUsed pgtype.Timestamptz `json:"last_used"` CreatorEmail pgtype.Text `json:"creator_email"` } func (q *Queries) ListAPIKeysByTeamWithCreator(ctx context.Context, teamID pgtype.UUID) ([]ListAPIKeysByTeamWithCreatorRow, error) { rows, err := q.db.Query(ctx, listAPIKeysByTeamWithCreator, teamID) if err != nil { return nil, err } defer rows.Close() var items []ListAPIKeysByTeamWithCreatorRow for rows.Next() { var i ListAPIKeysByTeamWithCreatorRow if err := rows.Scan( &i.ID, &i.TeamID, &i.Name, &i.KeyHash, &i.KeyPrefix, &i.CreatedBy, &i.CreatedAt, &i.LastUsed, &i.CreatorEmail, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const updateAPIKeyLastUsed = `-- name: UpdateAPIKeyLastUsed :exec UPDATE team_api_keys SET last_used = NOW() WHERE id = $1 ` func (q *Queries) UpdateAPIKeyLastUsed(ctx context.Context, id pgtype.UUID) error { _, err := q.db.Exec(ctx, updateAPIKeyLastUsed, id) return err }