db

package
v0.0.0-...-bdc5b51 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package db provides the database queries and utiltiies around migrations and transactions. It is in part, genrated code using sqlc based off the *.sql files in the same directory.

This package also provides the QueriesExt struct which extends the functionality of the generated Queries struct to include the ability to work with transactions and the underlying pgx connection.

Index

Constants

View Source
const (
	// UserActionPasswordReset is the action type for a password reset
	// this is verified by a check constrain in the database.
	UserActionPasswordReset = "password_reset"
)

Variables

This section is empty.

Functions

func IntoPgTimePrt

func IntoPgTimePrt(t *time.Time) pgtype.Timestamp

Types

type Config

type Config struct {
	Host      string `conf:"default:localhost"`
	Port      string `conf:"default:5432"`
	Username  string `conf:"default:postgres"`
	Password  string `conf:"default:postgres"`
	Database  string `conf:"default:postgres"`
	EnableSSL bool   `conf:"default:false"`
}

func (Config) DSN

func (d Config) DSN() string

type CreateProviderParams

type CreateProviderParams struct {
	UserID         uuid.UUID
	ProviderName   string
	ProviderUserID string
	Metadata       interface{}
}

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 DeleteProviderParams

type DeleteProviderParams struct {
	UserID       uuid.UUID
	ProviderName string
}

type ProviderGetOneParams

type ProviderGetOneParams struct {
	UserID       uuid.UUID
	ProviderName string
}

type ProviderStateCreateParams

type ProviderStateCreateParams struct {
	Token     []byte
	ExpiresAt time.Time
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CreateProvider

func (q *Queries) CreateProvider(ctx context.Context, arg CreateProviderParams) (UserIdentityProvider, error)

func (*Queries) DeleteProvider

func (q *Queries) DeleteProvider(ctx context.Context, arg DeleteProviderParams) error

func (*Queries) ProviderGetOne

func (q *Queries) ProviderGetOne(ctx context.Context, arg ProviderGetOneParams) (UserIdentityProvider, error)

func (*Queries) ProviderStateCreate

func (q *Queries) ProviderStateCreate(ctx context.Context, arg ProviderStateCreateParams) error

func (*Queries) ProviderStateDelete

func (q *Queries) ProviderStateDelete(ctx context.Context, token []byte) error

func (*Queries) ProviderStateGet

func (q *Queries) ProviderStateGet(ctx context.Context, token []byte) (UserIdentityProviderState, error)

func (*Queries) SessionCreate

func (q *Queries) SessionCreate(ctx context.Context, arg SessionCreateParams) error

func (*Queries) SessionDeleteByToken

func (q *Queries) SessionDeleteByToken(ctx context.Context, token []byte) error

func (*Queries) SessionDeleteExpiredBefore

func (q *Queries) SessionDeleteExpiredBefore(ctx context.Context, expiresAt time.Time) (int64, error)

SessionDeleteExpiredBefore deletes every session that has expired before the given time.

func (*Queries) UserActionTokenCreate

func (q *Queries) UserActionTokenCreate(ctx context.Context, arg UserActionTokenCreateParams) (UserActionToken, error)

func (*Queries) UserActionTokenDelete

func (q *Queries) UserActionTokenDelete(ctx context.Context, id uuid.UUID) error

func (*Queries) UserActionTokenGet

func (q *Queries) UserActionTokenGet(ctx context.Context, arg UserActionTokenGetParams) (UserActionToken, error)

func (*Queries) UserByEmail

func (q *Queries) UserByEmail(ctx context.Context, email string) (User, error)

func (*Queries) UserByID

func (q *Queries) UserByID(ctx context.Context, id uuid.UUID) (User, error)

func (*Queries) UserByProvider

func (q *Queries) UserByProvider(ctx context.Context, arg UserByProviderParams) (User, error)

func (*Queries) UserBySession

func (q *Queries) UserBySession(ctx context.Context, token []byte) (User, error)

func (*Queries) UserCreate

func (q *Queries) UserCreate(ctx context.Context, arg UserCreateParams) (User, error)

func (*Queries) UserCreateAdmin

func (q *Queries) UserCreateAdmin(ctx context.Context, arg UserCreateAdminParams) (User, error)

func (*Queries) UserDeleteByID

func (q *Queries) UserDeleteByID(ctx context.Context, id uuid.UUID) error

func (*Queries) UserGetAll

func (q *Queries) UserGetAll(ctx context.Context, arg UserGetAllParams) ([]User, error)

func (*Queries) UserGetAllCount

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

func (*Queries) UserUpdate

func (q *Queries) UserUpdate(ctx context.Context, arg UserUpdateParams) (User, error)

func (*Queries) UserUpdateBilling

func (q *Queries) UserUpdateBilling(ctx context.Context, arg UserUpdateBillingParams) (User, error)

func (*Queries) WithTx

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

type QueriesExt

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

QueriesExt is an extension of the generated Queries struct which also depends directly on the internal sql connection and allows for easier transaction handling and some basic utility methods for working with the database.

func NewExt

func NewExt(ctx context.Context, logger zerolog.Logger, config Config, runMigrations bool) (*QueriesExt, error)

func (*QueriesExt) Close

func (qe *QueriesExt) Close(ctx context.Context) error

Close closes the connection.

func (*QueriesExt) WithTx

func (qe *QueriesExt) WithTx(ctx context.Context, fn func(*QueriesExt) error) error

WithTx runs the given function in a transaction.

type SessionCreateParams

type SessionCreateParams struct {
	UserID    uuid.UUID
	Token     []byte
	ExpiresAt time.Time
}

type User

type User struct {
	ID                    uuid.UUID
	CreatedAt             time.Time
	UpdatedAt             time.Time
	Username              string
	Email                 string
	PasswordHash          string
	IsAdmin               bool
	StripeCustomerID      *string
	StripeSubscriptionID  *string
	SubscriptionStartDate pgtype.Timestamp
	SubscriptionEndedDate pgtype.Timestamp
}

type UserActionToken

type UserActionToken struct {
	ID        uuid.UUID
	CreatedAt time.Time
	ExpiresAt time.Time
	UserID    uuid.UUID
	Token     []byte
	Action    string
}

type UserActionTokenCreateParams

type UserActionTokenCreateParams struct {
	UserID    uuid.UUID
	Token     []byte
	Action    string
	ExpiresAt time.Time
}

type UserActionTokenGetParams

type UserActionTokenGetParams struct {
	Token  []byte
	Action string
	Now    time.Time
}

type UserByProviderParams

type UserByProviderParams struct {
	ProviderName   string
	ProviderUserID string
}

type UserCreateAdminParams

type UserCreateAdminParams struct {
	Username     string
	Email        string
	PasswordHash string
}

type UserCreateParams

type UserCreateParams struct {
	Username     string
	Email        string
	PasswordHash string
}

type UserGetAllParams

type UserGetAllParams struct {
	Limit  int32
	Offset int32
}

type UserIdentityProvider

type UserIdentityProvider struct {
	ID             uuid.UUID
	CreatedAt      time.Time
	UserID         uuid.UUID
	ProviderName   string
	ProviderUserID string
	Metadata       []byte
}

type UserIdentityProviderState

type UserIdentityProviderState struct {
	ID        uuid.UUID
	Token     []byte
	ExpiresAt time.Time
}

type UserSession

type UserSession struct {
	ID        uuid.UUID
	CreatedAt time.Time
	ExpiresAt time.Time
	UserID    uuid.UUID
	Token     []byte
}

type UserUpdateBillingParams

type UserUpdateBillingParams struct {
	ID                    uuid.UUID
	StripeCustomerID      *string
	StripeSubscriptionID  *string
	SubscriptionStartDate pgtype.Timestamp
	SubscriptionEndedDate pgtype.Timestamp
}

type UserUpdateParams

type UserUpdateParams struct {
	ID           uuid.UUID
	Username     *string
	Email        *string
	PasswordHash *string
}

Directories

Path Synopsis
Package migrations handles the database migrations using goose and embedded sql files.
Package migrations handles the database migrations using goose and embedded sql files.

Jump to

Keyboard shortcuts

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