dbx

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 6 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFailedToHashPassword is returned when the password hashing fails
	ErrFailedToHashPassword = errors.New("dbx: failed to hash password")
	// ErrFailedCheckPassword is returned when the password check fails
	ErrFailedCheckPassword = errors.New("dbx: failed to check password")
)

Functions

func CheckPassword added in v0.1.13

func CheckPassword(password []byte, hashedPassword []byte) error

CheckPassword checks if the provided password is correct or not

func HashPassword added in v0.1.13

func HashPassword(password []byte) ([]byte, error)

HashPassword returns the bcrypt hash of the password

Types

type Database

type Database[R, W any] interface {
	// ReadTx starts a read only transaction.
	ReadTx(context.Context, func(context.Context, R) error) error
	// ReadWriteTx starts a read write transaction.
	ReadWriteTx(context.Context, func(context.Context, W) error) error

	Migrator
	io.Closer
}

Database provides methods for transactional operations.

func NewDatabase

func NewDatabase[R, W any](conn *gorm.DB, r ReadTxFactory[R], rw ReadWriteTxFactory[W]) (Database[R, W], error)

NewDatabase returns a new instance of db.

type Migrator

type Migrator interface {
	// Migrate is a method that runs the migration.
	Migrate(context.Context, ...any) error
}

Migrator is a method that runs the migration.

type QueryError

type QueryError struct {
	// Query is the query that caused the error.
	Query string
	// Err is the error that occurred.
	Err error
}

QueryError is an error that occurred while executing a query.

func NewQueryError

func NewQueryError(query string, err error) *QueryError

NewQueryError returns a new QueryError.

func (*QueryError) Error

func (e *QueryError) Error() string

Error implements the error interface.

func (*QueryError) Unwrap

func (e *QueryError) Unwrap() error

Unwrap implements the errors.Wrapper interface.

type ReadTxFactory

type ReadTxFactory[R any] func(*gorm.DB) (R, error)

ReadTxFactory is a function that creates a new instance of Datastore.

type ReadWriteTxFactory

type ReadWriteTxFactory[W any] func(*gorm.DB) (W, error)

ReadWriteTxFactory is a function that creates a new instance of Datastore.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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