db

package
v0.0.0-...-0b7c896 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ForeignKeyViolation = "23503"
	UniqueViolation     = "23505"
)

Variables

View Source
var ErrRecordNotFound = pgx.ErrNoRows
View Source
var ErrUniqueViolation = &pgconn.PgError{
	Code: UniqueViolation,
}

Functions

func ErrorCode

func ErrorCode(err error) string

Types

type CreateUserWatchParams

type CreateUserWatchParams struct {
	UserID      uuid.UUID `json:"user_id"`
	WatchReason string    `json:"watch_reason"`
}

type CreateUserWatchTxParams

type CreateUserWatchTxParams struct {
	CreateUserWatchParams
	AfterCreate func(user UserWatch) error
}

type CreateUserWatchTxResult

type CreateUserWatchTxResult struct {
	UserWatch UserWatch
}

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 FraudAlert

type FraudAlert struct {
	ID          int64              `json:"id"`
	AlertID     pgtype.Int4        `json:"alert_id"`
	UserID      uuid.UUID          `json:"user_id"`
	AlertReason string             `json:"alert_reason"`
	AlertLevel  pgtype.Int4        `json:"alert_level"`
	Slug        string             `json:"slug"`
	CreatedAt   pgtype.Timestamptz `json:"created_at"`
}

type ListUsersOnWatchParams

type ListUsersOnWatchParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type Querier

type Querier interface {
	CreateUserWatch(ctx context.Context, arg CreateUserWatchParams) (UserWatch, error)
	DeleteUserFromWatch(ctx context.Context, userID uuid.UUID) error
	GetUserWatch(ctx context.Context, userID uuid.UUID) (UserWatch, error)
	GetUserWatchForUpdate(ctx context.Context, userID uuid.UUID) (UserWatch, error)
	ListUsersOnWatch(ctx context.Context, arg ListUsersOnWatchParams) ([]UserWatch, error)
	UpdateUserWatch(ctx context.Context, arg UpdateUserWatchParams) (UserWatch, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateUserWatch

func (q *Queries) CreateUserWatch(ctx context.Context, arg CreateUserWatchParams) (UserWatch, error)

func (*Queries) DeleteUserFromWatch

func (q *Queries) DeleteUserFromWatch(ctx context.Context, userID uuid.UUID) error

func (*Queries) GetUserWatch

func (q *Queries) GetUserWatch(ctx context.Context, userID uuid.UUID) (UserWatch, error)

func (*Queries) GetUserWatchForUpdate

func (q *Queries) GetUserWatchForUpdate(ctx context.Context, userID uuid.UUID) (UserWatch, error)

func (*Queries) ListUsersOnWatch

func (q *Queries) ListUsersOnWatch(ctx context.Context, arg ListUsersOnWatchParams) ([]UserWatch, error)

func (*Queries) UpdateUserWatch

func (q *Queries) UpdateUserWatch(ctx context.Context, arg UpdateUserWatchParams) (UserWatch, 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) CreateUserWatchTx

func (store *SQLStore) CreateUserWatchTx(ctx context.Context, arg CreateUserWatchTxParams) (CreateUserWatchTxResult, error)

type Store

type Store interface {
	Querier
	CreateUserWatchTx(ctx context.Context, arg CreateUserWatchTxParams) (CreateUserWatchTxResult, error)
}

Store defines all functions to execute db queries and transactions

func NewStore

func NewStore(connPool *pgxpool.Pool) Store

NewStore creates a new store

type Transaction

type Transaction struct {
	ID       int64 `json:"id"`
	FromUser int64 `json:"from_user"`
	ToUser   int64 `json:"to_user"`
	// must be positive
	Amount    int64              `json:"amount"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
}

type UpdateUserWatchParams

type UpdateUserWatchParams struct {
	UserID      uuid.UUID `json:"user_id"`
	WatchReason string    `json:"watch_reason"`
}

type UserWatch

type UserWatch struct {
	ID          int64              `json:"id"`
	UserID      uuid.UUID          `json:"user_id"`
	WatchReason string             `json:"watch_reason"`
	CreatedAt   pgtype.Timestamptz `json:"created_at"`
}

Jump to

Keyboard shortcuts

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