dbx

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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.

Jump to

Keyboard shortcuts

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