mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
104 lines
1.9 KiB
Go
104 lines
1.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: apikeys.sql
|
|
|
|
package dbc
|
|
|
|
import (
|
|
"context"
|
|
|
|
jwt "github.com/golang-jwt/jwt/v5"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createApiKey = `-- name: CreateApiKey :one
|
|
insert into apikeys(name, token, claims)
|
|
values ($1, $2, $3)
|
|
returning
|
|
pk, id, name, token, claims, created_by, created_at, last_used
|
|
`
|
|
|
|
type CreateApiKeyParams struct {
|
|
Name string `json:"name"`
|
|
Token string `json:"token"`
|
|
Claims jwt.MapClaims `json:"claims"`
|
|
}
|
|
|
|
func (q *Queries) CreateApiKey(ctx context.Context, arg CreateApiKeyParams) (Apikey, error) {
|
|
row := q.db.QueryRow(ctx, createApiKey, arg.Name, arg.Token, arg.Claims)
|
|
var i Apikey
|
|
err := row.Scan(
|
|
&i.Pk,
|
|
&i.Id,
|
|
&i.Name,
|
|
&i.Token,
|
|
&i.Claims,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
&i.LastUsed,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteApiKey = `-- name: DeleteApiKey :one
|
|
delete from apikeys
|
|
where id = $1
|
|
returning
|
|
pk, id, name, token, claims, created_by, created_at, last_used
|
|
`
|
|
|
|
func (q *Queries) DeleteApiKey(ctx context.Context, id uuid.UUID) (Apikey, error) {
|
|
row := q.db.QueryRow(ctx, deleteApiKey, id)
|
|
var i Apikey
|
|
err := row.Scan(
|
|
&i.Pk,
|
|
&i.Id,
|
|
&i.Name,
|
|
&i.Token,
|
|
&i.Claims,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
&i.LastUsed,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listApiKeys = `-- name: ListApiKeys :many
|
|
select
|
|
pk, id, name, token, claims, created_by, created_at, last_used
|
|
from
|
|
apikeys
|
|
order by
|
|
last_used
|
|
`
|
|
|
|
func (q *Queries) ListApiKeys(ctx context.Context) ([]Apikey, error) {
|
|
rows, err := q.db.Query(ctx, listApiKeys)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Apikey
|
|
for rows.Next() {
|
|
var i Apikey
|
|
if err := rows.Scan(
|
|
&i.Pk,
|
|
&i.Id,
|
|
&i.Name,
|
|
&i.Token,
|
|
&i.Claims,
|
|
&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
|
|
}
|