middleware

package
v0.3.19 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertArgsToNamedValues added in v0.3.0

func ConvertArgsToNamedValues(args ...interface{}) []driver.NamedValue

ConvertArgsToNamedValues converts args to named values

func ConvertSliceToString added in v0.3.11

func ConvertSliceToString(args ...interface{}) (string, error)

ConvertSliceToString converts args to string, it's usually used to generate "in clause" of a select statement

func ConvertToString added in v0.3.11

func ConvertToString(arg interface{}) (string, error)

ConvertToString converts an interface type argument to string, it's usually used to generate "in clause" of a select statement

func GetQuestionMarks added in v0.3.17

func GetQuestionMarks(num int) string

GetQuestionMarks returns question marks with given num

Types

type Pool

type Pool interface {
	// Close releases each connection in the pool
	Close() error
	// IsClosed returns if pool had been closed
	IsClosed() bool
	// Get gets a connection from the pool
	Get() (PoolConn, error)
	// Transaction returns a connection that could run multiple statements in the same transaction
	Transaction() (Transaction, error)
	// Supply creates given number of connections and add them to the pool
	Supply(num int) error
	// Release releases given number of connections, each connection will disconnect with the middleware
	Release(num int) error
}

type PoolConn

type PoolConn interface {
	// Close returns connection back to the pool
	Close() error
	// Disconnect disconnects from the middleware, normally when using connection pool
	Disconnect() error
	// IsValid validates if connection is valid
	IsValid() bool
	// Prepare prepares a statement and returns a Statement
	Prepare(command string) (Statement, error)
	// PrepareContext prepares a statement with context and returns a Statement
	PrepareContext(ctx context.Context, command string) (Statement, error)
	// Execute executes given command and placeholders on the middleware
	Execute(command string, args ...interface{}) (Result, error)
	// ExecuteContext executes given command and placeholders with context on the middleware
	ExecuteContext(ctx context.Context, command string, args ...interface{}) (Result, error)
}

type Statement added in v0.3.0

type Statement interface {
	// Close closes the statement
	Close() error
	// Execute executes given command and placeholders on the middleware
	Execute(args ...interface{}) (Result, error)
	// ExecuteContext executes given command and placeholders with context on the middleware
	ExecuteContext(ctx context.Context, args ...interface{}) (Result, error)
	// Commit commits the transaction
	Commit() error
	// Rollback rollbacks the transaction
	Rollback() error
}

type Transaction added in v0.2.22

type Transaction interface {
	PoolConn
	// Begin begins a transaction
	Begin() error
	// Commit commits current transaction
	Commit() error
	// Rollback rollbacks current transaction
	Rollback() error
}

Directories

Path Synopsis
sql

Jump to

Keyboard shortcuts

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