data

package
v0.0.0-...-c9bcc77 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrObjectNotFound = errors.New("db.err.object_not_found")
View Source
var ErrTooManyRows = errors.New("db.err.too_many_rows")

Functions

func Exec

func Exec(ctx context.Context, pool *pgxpool.Pool, sql string, args ...any) (pgconn.CommandTag, error)

func GenerateRandomSecret

func GenerateRandomSecret(length int) (string, error)

func HashToken

func HashToken(token string) string

func QueryMany

func QueryMany[T any](ctx context.Context, pool *pgxpool.Pool, sql string, args ...any) ([]T, error)

func QueryOne

func QueryOne[T any](ctx context.Context, pool *pgxpool.Pool, sql string, args ...any) (T, error)

func WithTransaction

func WithTransaction(ctx context.Context, pool *pgxpool.Pool, fn func(pgx.Tx) error) error

Types

type Entity

type Entity struct {
	ID        uuid.UUID  `json:"id" db:"id"`
	CreatedAt time.Time  `json:"created_at" db:"created_at"`
	UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"`
}

type Session

type Session struct {
	ID         uuid.UUID `db:"id"`
	UserID     uuid.UUID `db:"user_id"`
	IpAddress  string    `db:"ip_address"`
	UserAgent  string    `db:"user_agent"`
	CreatedAt  time.Time `db:"created_at"`
	ExpiresAt  time.Time `db:"expires_at"`
	LastSeenAt time.Time `db:"last_seen_at"`
}

type Store

type Store interface {
	UserByEmail(ctx context.Context, email string) (*User, error)
	User(ctx context.Context, id uuid.UUID) (*User, error)
	CreateUser(ctx context.Context, user *User) (*User, error)
	CreateToken(ctx context.Context, userAuthToken *UserAuthToken) (*UserAuthToken, error)
	Token(ctx context.Context, tokenHash string) (*UserAuthToken, error)
	CompleteMagicLinkSignIn(ctx context.Context, userID uuid.UUID, tokenID uuid.UUID, usedAt time.Time) error
	CreateSession(ctx context.Context, session *Session) (*Session, error)
	UserBySessionID(ctx context.Context, sessionID uuid.UUID) (*User, error)
	Session(ctx context.Context, sessionID uuid.UUID) (*Session, error)
	DeleteSession(ctx context.Context, sessionID uuid.UUID) error
}

type User

type User struct {
	Entity

	Email         string     `json:"email" db:"email"`
	IsEnabled     bool       `json:"is_enabled" db:"is_enabled"`
	SecurityStamp uuid.UUID  `json:"security_stamp" db:"security_stamp"`
	LastLoginAt   *time.Time `json:"last_login_at" db:"last_login_at"`
}

func NewUser

func NewUser(email string) *User

type UserAuthToken

type UserAuthToken struct {
	Entity

	UserID     uuid.UUID  `json:"user_id" db:"user_id"`
	Token      string     `json:"token" db:"token"`
	IpAddress  string     `json:"ip_address" db:"ip_address"`
	UserAgent  string     `json:"user_agent" db:"user_agent"`
	ValidUntil time.Time  `json:"valid_until" db:"valid_until"`
	UsedAt     *time.Time `json:"used_at" db:"used_at"`
}

func NewUserAuthToken

func NewUserAuthToken(userID uuid.UUID, token string, ipAddress string, userAgent string) *UserAuthToken

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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