datafx

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDB = "DEFAULT"

Variables

View Source
var (
	ErrUnknownProvider          = errors.New("unknown provider")
	ErrUnableToDetermineDialect = errors.New("unable to determine dialect")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Sources map[string]ConfigDataSource `conf:"SOURCES"`
}

type ConfigDataSource

type ConfigDataSource struct {
	Provider string `conf:"PROVIDER"`
	DSN      string `conf:"DSN"`
}

type ContextKey

type ContextKey string
const (
	ContextKeyUnitOfWork ContextKey = "unit-of-work"
)

type Dialect

type Dialect string
const (
	// DialectPostgresPgx Dialect = "pgx".
	DialectPostgres Dialect = "postgres"
	DialectSQLite   Dialect = "sqlite"
	DialectMySQL    Dialect = "mysql"
)

func DetermineDialect

func DetermineDialect(provider string, dsn string) (Dialect, error)

type Registry

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

func NewRegistry

func NewRegistry(logger *slog.Logger) *Registry

func (*Registry) AddConnection

func (registry *Registry) AddConnection(ctx context.Context, name string, provider string, dsn string) error

func (*Registry) GetDefaultSql

func (registry *Registry) GetDefaultSql() SqlDataSource

func (*Registry) GetNamedSql

func (registry *Registry) GetNamedSql(name string) SqlDataSource

func (*Registry) LoadFromConfig

func (registry *Registry) LoadFromConfig(ctx context.Context, config *Config) error

type SqlDataSource

type SqlDataSource interface {
	GetDialect() Dialect
	GetConnection() SqlExecutor
	UseUnitOfWork(ctx context.Context) (*UnitOfWork, error)
}

type SqlDataSourceStd

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

func NewSqlDataSourceStd

func NewSqlDataSourceStd(ctx context.Context, dialect Dialect, dsn string) (*SqlDataSourceStd, error)

func (*SqlDataSourceStd) GetConnection

func (dataSource *SqlDataSourceStd) GetConnection() SqlExecutor

func (*SqlDataSourceStd) GetDialect added in v0.6.4

func (dataSource *SqlDataSourceStd) GetDialect() Dialect

func (*SqlDataSourceStd) UseUnitOfWork

func (dataSource *SqlDataSourceStd) UseUnitOfWork(ctx context.Context) (*UnitOfWork, error)

type SqlExecutor

type SqlExecutor interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

type TransactionFinalizer

type TransactionFinalizer interface {
	Rollback() error
	Commit() error
}

type TransactionStarter

type TransactionStarter interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

type UnitOfWork

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

func UseUnitOfWork

func UseUnitOfWork(ctx context.Context, transactionStarter TransactionStarter) (*UnitOfWork, error)

func (*UnitOfWork) Bind

func (uow *UnitOfWork) Bind(context context.Context, txScope TransactionFinalizer)

func (*UnitOfWork) Close

func (uow *UnitOfWork) Close() error

func (*UnitOfWork) Commit

func (uow *UnitOfWork) Commit() error

func (*UnitOfWork) Context

func (uow *UnitOfWork) Context() context.Context

func (*UnitOfWork) TxScope

func (uow *UnitOfWork) TxScope() TransactionFinalizer

func (*UnitOfWork) Use

func (uow *UnitOfWork) Use(fn func(TransactionFinalizer) any)

Jump to

Keyboard shortcuts

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