db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const UniqueViolationCode = "23505"

Variables

View Source
var (
	UserProfileAlreadyExistsError = errors.New("user profile already exists")
	GamerTagAlreadyInUseError     = errors.New("gamer tag already in use")
	UserAlreadyReferredError      = errors.New("user already referred")
	ReferrerDoesNotExistError     = errors.New("referrer does not exist")
	SelfReferralError             = errors.New("self referrals not permitted")
)
View Source
var RecordNotFoundError = pgx.ErrNoRows

Functions

This section is empty.

Types

type CreateProfileParams

type CreateProfileParams struct {
	WalletAddress string `json:"wallet_address"`
	GamerTag      string `json:"gamer_tag"`
}

type CreateProfileTxParams

type CreateProfileTxParams struct {
	CreateProfileParams
	Referrer    string
	AfterCreate func() error
}

type CreateProfileTxResult

type CreateProfileTxResult struct {
	Profile  Profile
	Referral Referral
}

type CreateReferralParams

type CreateReferralParams struct {
	Referrer string `json:"referrer"`
	Referee  string `json:"referee"`
}

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 Error

type Error struct {
	Code           string
	ConstraintName string
}

func ParseError

func ParseError(err error) *Error

type GetProfileTxParams

type GetProfileTxParams struct {
	WalletAddress string
	AfterCreate   func() (string, error)
}

type GetProfileTxResult

type GetProfileTxResult struct {
	EnsName string
	Profile Profile
}

type ListProfilesParams

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

type ListReferralsParams

type ListReferralsParams struct {
	Referrer string `json:"referrer"`
	Limit    int32  `json:"limit"`
	Offset   int32  `json:"offset"`
}

type Profile

type Profile struct {
	WalletAddress string    `json:"wallet_address"`
	GamerTag      string    `json:"gamer_tag"`
	CreatedAt     time.Time `json:"created_at"`
}

type Querier

type Querier interface {
	CreateProfile(ctx context.Context, arg CreateProfileParams) (Profile, error)
	CreateReferral(ctx context.Context, arg CreateReferralParams) (Referral, error)
	DeleteProfile(ctx context.Context, walletAddress string) error
	GetProfile(ctx context.Context, walletAddress string) (Profile, error)
	GetProfilesCount(ctx context.Context) (int64, error)
	GetReferralsCount(ctx context.Context, referrer string) (int64, error)
	GetReferrer(ctx context.Context, referee string) (Referral, error)
	ListProfiles(ctx context.Context, arg ListProfilesParams) ([]Profile, error)
	ListReferrals(ctx context.Context, arg ListReferralsParams) ([]Referral, error)
	UpdateProfile(ctx context.Context, arg UpdateProfileParams) (Profile, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateProfile

func (q *Queries) CreateProfile(ctx context.Context, arg CreateProfileParams) (Profile, error)

func (*Queries) CreateReferral

func (q *Queries) CreateReferral(ctx context.Context, arg CreateReferralParams) (Referral, error)

func (*Queries) DeleteProfile

func (q *Queries) DeleteProfile(ctx context.Context, walletAddress string) error

func (*Queries) GetProfile

func (q *Queries) GetProfile(ctx context.Context, walletAddress string) (Profile, error)

func (*Queries) GetProfilesCount

func (q *Queries) GetProfilesCount(ctx context.Context) (int64, error)

func (*Queries) GetReferralsCount

func (q *Queries) GetReferralsCount(ctx context.Context, referrer string) (int64, error)

func (*Queries) GetReferrer

func (q *Queries) GetReferrer(ctx context.Context, referee string) (Referral, error)

func (*Queries) ListProfiles

func (q *Queries) ListProfiles(ctx context.Context, arg ListProfilesParams) ([]Profile, error)

func (*Queries) ListReferrals

func (q *Queries) ListReferrals(ctx context.Context, arg ListReferralsParams) ([]Referral, error)

func (*Queries) UpdateProfile

func (q *Queries) UpdateProfile(ctx context.Context, arg UpdateProfileParams) (Profile, error)

func (*Queries) WithTx

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

type Referral

type Referral struct {
	ID         uuid.UUID `json:"id"`
	Referrer   string    `json:"referrer"`
	Referee    string    `json:"referee"`
	ReferredAt time.Time `json:"referred_at"`
}

type SQLStore

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

func (*SQLStore) CreateProfileTx

func (store *SQLStore) CreateProfileTx(ctx context.Context, params CreateProfileTxParams) (CreateProfileTxResult, error)

func (*SQLStore) GetProfileTx

func (store *SQLStore) GetProfileTx(ctx context.Context, params GetProfileTxParams) (GetProfileTxResult, error)

func (*SQLStore) UpdateProfileTx

func (store *SQLStore) UpdateProfileTx(ctx context.Context, params UpdateProfileTxParams) (UpdateProfileTxResult, error)

type Store

type Store interface {
	Querier
	GetProfileTx(ctx context.Context, params GetProfileTxParams) (GetProfileTxResult, error)
	UpdateProfileTx(ctx context.Context, params UpdateProfileTxParams) (UpdateProfileTxResult, error)
	CreateProfileTx(ctx context.Context, params CreateProfileTxParams) (CreateProfileTxResult, error)
}

func NewStore

func NewStore(connPool *pgxpool.Pool) Store

type UpdateProfileParams

type UpdateProfileParams struct {
	GamerTag      pgtype.Text `json:"gamer_tag"`
	WalletAddress string      `json:"wallet_address"`
}

type UpdateProfileTxParams

type UpdateProfileTxParams struct {
	WalletAddress string
	GamerTag      string
	AfterCreate   func() (string, error)
}

type UpdateProfileTxResult

type UpdateProfileTxResult struct {
	EnsName string
	Profile Profile
}

Jump to

Keyboard shortcuts

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