Something went wrong. Try again.
(READ ONLY) Margin is an open annotation layer for the internet. Powered by the AT Protocol.
margin.at
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147// Code generated by sqlc. DO NOT EDIT.// versions:// sqlc v1.31.1// source: api_keys.sql
package sqlcdb
import ( "context" "time")
const createAPIKey = `-- name: CreateAPIKey :execINSERT INTO api_keys (id, owner_did, name, key_hash, created_at, uri, cid)VALUES ($1, $2, $3, $4, $5, $6, $7)ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, key_hash = EXCLUDED.key_hash, uri = EXCLUDED.uri, cid = EXCLUDED.cid`
type CreateAPIKeyParams struct { ID string `json:"id"` OwnerDid string `json:"ownerDid"` Name string `json:"name"` KeyHash string `json:"keyHash"` CreatedAt time.Time `json:"createdAt"` Uri *string `json:"uri"` Cid *string `json:"cid"`}
func (q *Queries) CreateAPIKey(ctx context.Context, arg CreateAPIKeyParams) error { _, err := q.db.Exec(ctx, createAPIKey, arg.ID, arg.OwnerDid, arg.Name, arg.KeyHash, arg.CreatedAt, arg.Uri, arg.Cid, ) return err}
const deleteAPIKeyReturningURI = `-- name: DeleteAPIKeyReturningURI :oneDELETE FROM api_keys WHERE id = $1 AND owner_did = $2 RETURNING uri`
type DeleteAPIKeyReturningURIParams struct { ID string `json:"id"` OwnerDid string `json:"ownerDid"`}
func (q *Queries) DeleteAPIKeyReturningURI(ctx context.Context, arg DeleteAPIKeyReturningURIParams) (*string, error) { row := q.db.QueryRow(ctx, deleteAPIKeyReturningURI, arg.ID, arg.OwnerDid) var uri *string err := row.Scan(&uri) return uri, err}
const getAPIKeyByHash = `-- name: GetAPIKeyByHash :oneSELECT id, owner_did, name, key_hash, created_at, last_used_atFROM api_keysWHERE key_hash = $1`
type GetAPIKeyByHashRow struct { ID string `json:"id"` OwnerDid string `json:"ownerDid"` Name string `json:"name"` KeyHash string `json:"keyHash"` CreatedAt time.Time `json:"createdAt"` LastUsedAt *time.Time `json:"lastUsedAt"`}
func (q *Queries) GetAPIKeyByHash(ctx context.Context, keyHash string) (GetAPIKeyByHashRow, error) { row := q.db.QueryRow(ctx, getAPIKeyByHash, keyHash) var i GetAPIKeyByHashRow err := row.Scan( &i.ID, &i.OwnerDid, &i.Name, &i.KeyHash, &i.CreatedAt, &i.LastUsedAt, ) return i, err}
const getAPIKeysByOwner = `-- name: GetAPIKeysByOwner :manySELECT id, owner_did, name, key_hash, created_at, last_used_atFROM api_keysWHERE owner_did = $1ORDER BY created_at DESC`
type GetAPIKeysByOwnerRow struct { ID string `json:"id"` OwnerDid string `json:"ownerDid"` Name string `json:"name"` KeyHash string `json:"keyHash"` CreatedAt time.Time `json:"createdAt"` LastUsedAt *time.Time `json:"lastUsedAt"`}
func (q *Queries) GetAPIKeysByOwner(ctx context.Context, ownerDid string) ([]GetAPIKeysByOwnerRow, error) { rows, err := q.db.Query(ctx, getAPIKeysByOwner, ownerDid) if err != nil { return nil, err } defer rows.Close() var items []GetAPIKeysByOwnerRow for rows.Next() { var i GetAPIKeysByOwnerRow if err := rows.Scan( &i.ID, &i.OwnerDid, &i.Name, &i.KeyHash, &i.CreatedAt, &i.LastUsedAt, ); 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 :execUPDATE api_keys SET last_used_at = $1 WHERE id = $2`
type UpdateAPIKeyLastUsedParams struct { LastUsedAt *time.Time `json:"lastUsedAt"` ID string `json:"id"`}
func (q *Queries) UpdateAPIKeyLastUsed(ctx context.Context, arg UpdateAPIKeyLastUsedParams) error { _, err := q.db.Exec(ctx, updateAPIKeyLastUsed, arg.LastUsedAt, arg.ID) return err}