sql

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractRow

func ExtractRow[T any](row Row, callback func(row Row) T) (t T)

func ExtractRowSet

func ExtractRowSet[T any](rowSet RowSet, callback func(rowSet RowSet) []T) []T

func FromContext

func FromContext[T *TransactionContext](ctx context.Context) T

func Register

func Register(name string, driver driver.Driver)

Types

type Connection

type Connection interface {
	ExecContext(ctx context.Context, query string, args ...any) (Result, error)
	PrepareContext(ctx context.Context, query string, args ...any) (Statement, error)
	QueryContext(ctx context.Context, query string, args ...any) (RowSet, error)
	QueryRowContext(ctx context.Context, query string, args ...any) (Row, error)
	PingContext(ctx context.Context) error

	SetConnMaxLifetime(d time.Duration) error
	SetConnMaxIdleTime(d time.Duration) error
	SetMaxIdleConns(n int) error
	SetMaxOpenConns(n int) error

	BeginTransaction(ctx context.Context) (TransactionStatus, error)
	Driver() driver.Driver

	Close() error
	IsClosed() bool
}

type DataSource

type DataSource interface {
	GetConnection() (Connection, error)
}

type DataSourceTransactionManager

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

func NewDataSourceTransactionManager

func NewDataSourceTransactionManager(dataSource DataSource) *DataSourceTransactionManager

func (*DataSourceTransactionManager) Commit

func (m *DataSourceTransactionManager) Commit() error

func (*DataSourceTransactionManager) GetTransaction

func (m *DataSourceTransactionManager) GetTransaction(ctx context.Context, options ...any) (TransactionStatus, error)

func (*DataSourceTransactionManager) Rollback

func (m *DataSourceTransactionManager) Rollback() error

type DefaultTransactionStatus

type DefaultTransactionStatus struct {
}

func NewDefaultTransactionStatus

func NewDefaultTransactionStatus() *DefaultTransactionStatus

type IsolationLevel

type IsolationLevel int
const (
	LevelDefault IsolationLevel = iota
	LevelReadUncommitted
	LevelReadCommitted
	LevelWriteCommitted
	LevelRepeatableRead
	LevelSnapshot
	LevelSerializable
	LevelLinearizable
)

type PreparedStatement

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

func NewPreparedStatement

func NewPreparedStatement(stmt *sql.Stmt) *PreparedStatement

func (*PreparedStatement) Close

func (p *PreparedStatement) Close() error

func (*PreparedStatement) ExecContext

func (p *PreparedStatement) ExecContext(ctx context.Context, args ...any) (Result, error)

func (*PreparedStatement) QueryContext

func (p *PreparedStatement) QueryContext(ctx context.Context, args ...any) (RowSet, error)

func (*PreparedStatement) QueryRowContext

func (p *PreparedStatement) QueryRowContext(ctx context.Context, args ...any) (Row, error)

type Propagation

type Propagation int
const (
	PropagationRequired Propagation = iota
	PropagationSupports
	PropagationMandatory
	PropagationNever
	PropagationNotSupported
	PropagationNested
	PropagationRequiredNew
)

type Result

type Result interface {
	LastInsertId() (int64, error)
	RowsAffected() (int64, error)
}

type Row

type Row interface {
	Scan(dest ...any) error
}

type RowSet

type RowSet interface {
	Row

	Next() bool
}

type Statement

type Statement interface {
	ExecContext(ctx context.Context, args ...any) (Result, error)
	QueryContext(ctx context.Context, args ...any) (RowSet, error)
	QueryRowContext(ctx context.Context, args ...any) (Row, error)
	Close() error
}

type TransactionCallback

type TransactionCallback func(ctx context.Context) (any, error)

type TransactionContext

type TransactionContext struct {
}

type TransactionManager

type TransactionManager interface {
	GetTransaction(ctx context.Context, options ...any) (TransactionStatus, error)
	Commit() error
	Rollback() error
}

type TransactionOption

type TransactionOption func(options *TransactionOptions)

func WithIsolation

func WithIsolation(isolationLevel IsolationLevel) TransactionOption

func WithPropagation

func WithPropagation(propagation Propagation) TransactionOption

func WithReadOnly

func WithReadOnly(readOnly bool) TransactionOption

func WithTimeout

func WithTimeout(timeout time.Duration) TransactionOption

type TransactionOptions

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

func DefaultTransactionOptions

func DefaultTransactionOptions() *TransactionOptions

func NewTransactionOptions

func NewTransactionOptions(opts ...TransactionOption) *TransactionOptions

func (*TransactionOptions) IsReadOnly

func (o *TransactionOptions) IsReadOnly() bool

func (*TransactionOptions) IsolationLevel

func (o *TransactionOptions) IsolationLevel() IsolationLevel

func (*TransactionOptions) Merge

func (*TransactionOptions) Override

func (o *TransactionOptions) Override(options ...TransactionOption) *TransactionOptions

func (*TransactionOptions) Propagation

func (o *TransactionOptions) Propagation() Propagation

func (*TransactionOptions) Timeout

func (o *TransactionOptions) Timeout() time.Duration

type TransactionStatus

type TransactionStatus interface {
	IsNewTransaction() bool
	SetRollbackOnly()
	IsRollbackOnly() bool
	IsCompleted() bool
}

type TransactionTemplate

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

func NewTransactionTemplate

func NewTransactionTemplate(manager TransactionManager) *TransactionTemplate

func (*TransactionTemplate) Execute

func (t *TransactionTemplate) Execute(ctx context.Context, callback TransactionCallback) (result any, err error)

Jump to

Keyboard shortcuts

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