drivers

package
v0.0.0-...-e86feff Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() map[string]Driver

Available returns the available drivers.

func BatchAsTransaction

func BatchAsTransaction(u *dburl.URL) bool

BatchAsTransaction returns whether or not the the specified URL's driver requires batched queries to be done within a transaction block.

func CanChangePassword

func CanChangePassword(u *dburl.URL) error

CanChangePassword returns whether or not the specified driver's URL supports changing passwords.

func ChangePassword

func ChangePassword(u *dburl.URL, db DB, user, new, old string) (string, error)

ChangePassword initiates a user password change for the specified URL's driver. If user is not supplied, then the current user will be retrieved from User.

func Columns

func Columns(u *dburl.URL, rows *sql.Rows) ([]string, error)

Columns returns the columns for SQL result for the specified URL's driver.

func ConfigStmt

func ConfigStmt(u *dburl.URL, s *stmt.Stmt)

ConfigStmt sets the stmt.Stmt options for the specified driver.

func ConvertBytes

func ConvertBytes(u *dburl.URL) func([]byte, string) (string, error)

ConvertBytes returns a func to handle converting bytes for the specified URL's driver.

func ConvertDefault

func ConvertDefault(u *dburl.URL) func(interface{}) (string, error)

ConvertDefault returns a func to handle converting a interface{} for the specified URL's driver.

func ConvertMap

func ConvertMap(u *dburl.URL) func(map[string]interface{}) (string, error)

ConvertMap returns a func to handle converting a map[string]interface{} for the specified URL's driver.

func ConvertSlice

func ConvertSlice(u *dburl.URL) func([]interface{}) (string, error)

ConvertSlice returns a func to handle converting a []interface{} for the specified URL's driver.

func ForceParams

func ForceParams(u *dburl.URL)

ForceParams forces parameters on the supplied DSN for the registered driver.

func ForceQueryParameters

func ForceQueryParameters(params []string) func(*dburl.URL)

ForceQueryParameters is a utility func that wraps forcing params of name, value pairs.

func IsBatchQueryPrefix

func IsBatchQueryPrefix(u *dburl.URL, prefix string) (string, string, bool)

IsBatchQueryPrefix returns whether or not the supplied query prefix is a batch query prefix, and the closing prefix. Used to direct the handler to continue accumulating statements.

func IsPasswordErr

func IsPasswordErr(u *dburl.URL, err error) bool

IsPasswordErr returns true if the specified err is a password error for the specified URL's driver.

func Lexer

func Lexer(u *dburl.URL) chroma.Lexer

Lexer returns the syntax lexer for a specified URL's driver.

func NewStmt

func NewStmt(u *dburl.URL, f func() ([]rune, error), opts ...stmt.Option) *stmt.Stmt

NewStmt wraps creating a new stmt.Stmt for the specified driver.

func NextResultSet

func NextResultSet(q *sql.Rows) bool

NextResultSet is a wrapper around the go1.8 introduced sql.Rows.NextResultSet call.

func Open

func Open(u *dburl.URL) (*sql.DB, error)

Open opens a sql.DB connection for the registered driver.

func Ping

func Ping(u *dburl.URL, db *sql.DB) error

Ping pings the database for a specified URL's driver.

func Process

func Process(u *dburl.URL, prefix, sqlstr string) (string, string, bool, error)

Process processes the supplied SQL query for the specified URL's driver.

func QueryExecType

func QueryExecType(prefix, sqlstr string) (string, bool)

QueryExecType is the default way to determine the "EXEC" prefix for a SQL query and whether or not it should be Exec'd or Query'd.

func Register

func Register(name string, d Driver, aliases ...string)

Register registers driver d with name and associated aliases.

func Registered

func Registered(name string) bool

Registered returns whether or not a specific driver has been registered.

func RequirePreviousPassword

func RequirePreviousPassword(u *dburl.URL) bool

RequirePreviousPassword returns true if the specified URL's driver requires a previous password when changing a user's password.

func RowsAffected

func RowsAffected(u *dburl.URL, res sql.Result) (int64, error)

RowsAffected returns the rows affected for the SQL result for a specified URL's driver.

func User

func User(u *dburl.URL, db DB) (string, error)

User returns the current database user for the specified URL's driver.

func Version

func Version(u *dburl.URL, db DB) (string, error)

Version returns information about the database connection for the specified URL's driver.

func WrapErr

func WrapErr(driver string, err error) error

WrapErr wraps an error using the specified driver when err is not nil.

Types

type DB

type DB interface {
	Exec(string, ...interface{}) (sql.Result, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
	Prepare(string) (*sql.Stmt, error)
}

DB is the common interface for database operations, compatible with database/sql.DB and database/sql.Tx.

type Driver

type Driver struct {
	// Name is a name to override the driver name with.
	Name string

	// AllowDollar will be passed to query buffers to enable dollar ($$) style
	// strings.
	AllowDollar bool

	// AllowMultilineComments will be passed to query buffers to enable
	// multiline (/**/) style comments.
	AllowMultilineComments bool

	// AllowCComments will be passed to query buffers to enable C (//) style
	// comments.
	AllowCComments bool

	// AllowHashComments will be passed to query buffers to enable hash (#)
	// style comments.
	AllowHashComments bool

	// RequirePreviousPassword will be used by RequirePreviousPassword.
	RequirePreviousPassword bool

	// LexerName is the name of the syntax lexer to use.
	LexerName string

	// ForceParams will be used to force parameters if defined.
	ForceParams func(*dburl.URL)

	// Open will be used by Open if defined.
	Open func(*dburl.URL) (func(string, string) (*sql.DB, error), error)

	// Version will be used by Version if defined.
	Version func(DB) (string, error)

	// User will be used by User if defined.
	User func(DB) (string, error)

	// ChangePassword will be used by ChangePassword if defined.
	ChangePassword func(DB, string, string, string) error

	// IsPasswordErr will be used by IsPasswordErr if defined.
	IsPasswordErr func(error) bool

	// Process will be used by Process if defined.
	Process func(string, string) (string, string, bool, error)

	// Columns will be used to retrieve the columns for the rows if
	// defined.
	Columns func(*sql.Rows) ([]string, error)

	// RowsAffected will be used by RowsAffected if defined.
	RowsAffected func(sql.Result) (int64, error)

	// Err will be used by Error.Error if defined.
	Err func(error) (string, string)

	// ConvertBytes will be used by ConvertBytes to convert a raw []byte
	// slice to a string if defined.
	ConvertBytes func([]byte, string) (string, error)

	// ConvertMap will be used by ConvertMap to convert a map[string]interface{}
	// to a string if defined.
	ConvertMap func(map[string]interface{}) (string, error)

	// ConvertSlice will be used by ConvertSlice to convert a []interface{} to
	// a string if defined.
	ConvertSlice func([]interface{}) (string, error)

	// ConvertDefault will be used by ConvertDefault to convert a interface{}
	// to a string if defined.
	ConvertDefault func(interface{}) (string, error)

	// BatchAsTransaction will cause batched queries to be done in a
	// transaction block.
	BatchAsTransaction bool

	// BatchQueryPrefixes will be used by BatchQueryPrefixes if defined.
	BatchQueryPrefixes map[string]string
}

Driver holds funcs for a driver.

type Error

type Error struct {
	Driver string
	Err    error
}

Error is a wrapper to standardize errors.

func (*Error) Error

func (e *Error) Error() string

Error satisfies the error interface, returning simple information about the wrapped error in standardized way.

Jump to

Keyboard shortcuts

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