db

package
v0.0.0-...-c98df5a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UniqueViolation = "23505"
)

Variables

View Source
var ErrRecordNotFound = pgx.ErrNoRows

Functions

func ErrorCode

func ErrorCode(err error) string

Types

type Api

type Api struct {
	ID int64 `json:"id"`
	// public keys from 3rd API
	Key        string    `json:"key"`
	UsageCount int64     `json:"usage_count"`
	CreatedAt  time.Time `json:"created_at"`
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type Querier

type Querier interface {
	CreateAPI(ctx context.Context, key string) (Api, error)
	GetAPI(ctx context.Context) (Api, error)
	UpdateAPIUsageCount(ctx context.Context, arg UpdateAPIUsageCountParams) error
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) CreateAPI

func (q *Queries) CreateAPI(ctx context.Context, key string) (Api, error)

func (*Queries) GetAPI

func (q *Queries) GetAPI(ctx context.Context) (Api, error)

func (*Queries) UpdateAPIUsageCount

func (q *Queries) UpdateAPIUsageCount(ctx context.Context, arg UpdateAPIUsageCountParams) error

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type SQLStore

type SQLStore struct {
	*Queries
	// contains filtered or unexported fields
}

SQLStore provides all functions to execute SQL queries and transactions

func (*SQLStore) GetAPITx

func (store *SQLStore) GetAPITx(ctx context.Context) (string, error)

GetAPITx performs an API using It randomly selects an API, and update usage count within a database transaction

type Store

type Store interface {
	Querier
	GetAPITx(ctx context.Context) (string, error)
}

func NewStore

func NewStore(connPool *pgxpool.Pool) Store

type UpdateAPIUsageCountParams

type UpdateAPIUsageCountParams struct {
	ID         int64 `json:"id"`
	UsageCount int64 `json:"usage_count"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL