databases

package
v1.2.84 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStatementClosed = errors.Warning("sql: statement was closed")
)

Functions

This section is empty.

Types

type ColumnType

type ColumnType struct {
	DatabaseType string
	ScanType     reflect.Type
}

type Database

type Database interface {
	Name() string
	Construct(options Options) (err error)
	Begin(ctx context.Context, options TransactionOptions) (tx Transaction, err error)
	Query(ctx context.Context, query []byte, args []any) (rows Rows, err error)
	Execute(ctx context.Context, query []byte, args []any) (result Result, err error)
	Close(ctx context.Context) (err error)
}

func Cluster

func Cluster() Database

func MasterSlave

func MasterSlave() Database

func Standalone

func Standalone() Database

type DefaultRows

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

func (*DefaultRows) Close

func (rows *DefaultRows) Close() error

func (*DefaultRows) ColumnTypes

func (rows *DefaultRows) ColumnTypes() ([]ColumnType, error)

func (*DefaultRows) Columns

func (rows *DefaultRows) Columns() ([]string, error)

func (*DefaultRows) Next

func (rows *DefaultRows) Next() bool

func (*DefaultRows) Scan

func (rows *DefaultRows) Scan(dst ...any) error

type DefaultTransaction

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

func (*DefaultTransaction) Commit

func (tx *DefaultTransaction) Commit() error

func (*DefaultTransaction) Execute

func (tx *DefaultTransaction) Execute(ctx context.Context, query []byte, args []any) (result Result, err error)

func (*DefaultTransaction) Query

func (tx *DefaultTransaction) Query(ctx context.Context, query []byte, args []any) (rows Rows, err error)

func (*DefaultTransaction) Rollback

func (tx *DefaultTransaction) Rollback() error

type Isolation

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

func (Isolation) String

func (i Isolation) String() string

type Options

type Options struct {
	Log    logs.Logger
	Config configures.Config
}

type Preparer

type Preparer interface {
	Prepare(query string) (*sql.Stmt, error)
}

type Result

type Result struct {
	LastInsertId int64 `json:"lastInsertId"`
	RowsAffected int64 `json:"rowsAffected"`
}

type Rows

type Rows interface {
	Columns() ([]string, error)
	ColumnTypes() ([]ColumnType, error)
	Next() bool
	Scan(dst ...any) error
	Close() error
}

type Statement

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

func (*Statement) Closed

func (stmt *Statement) Closed() bool

func (*Statement) ExecContext

func (stmt *Statement) ExecContext(ctx context.Context, args ...any) (r sql.Result, err error)

func (*Statement) QueryContext

func (stmt *Statement) QueryContext(ctx context.Context, args ...any) (r *sql.Rows, err error)

func (*Statement) Stmt

func (stmt *Statement) Stmt() (v *sql.Stmt, release func(), closed bool)

type Statements

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

func NewStatements

func NewStatements(log logs.Logger, preparer Preparer, size int, evictTimeout time.Duration) (v *Statements, err error)

func (*Statements) Close

func (stmts *Statements) Close()

func (*Statements) Get

func (stmts *Statements) Get(query []byte) (stmt *Statement, err error)

type StatementsConfig

type StatementsConfig struct {
	Enable              bool `json:"enable"`
	CacheSize           int  `json:"cacheSize"`
	EvictTimeoutSeconds int  `json:"evictTimeoutSeconds"`
}

type Transaction

type Transaction interface {
	Commit() error
	Rollback() error
	Query(ctx context.Context, query []byte, args []any) (rows Rows, err error)
	Execute(ctx context.Context, query []byte, args []any) (result Result, err error)
}

func NewTransaction

func NewTransaction(tx *sql.Tx) Transaction

func NewTransactionWithStatements

func NewTransactionWithStatements(tx *sql.Tx, statements *Statements) Transaction

type TransactionOption

type TransactionOption func(options *TransactionOptions)

type TransactionOptions

type TransactionOptions struct {
	Isolation Isolation
	Readonly  bool
}

Jump to

Keyboard shortcuts

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