drivers

package
v0.14.13 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package drivers handles the registration, default implementation, and handles hooks for usql database drivers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available added in v0.4.0

func Available() map[string]Driver

Available returns the available drivers.

func BatchAsTransaction added in v0.14.13

func BatchAsTransaction(u *dburl.URL) bool

BatchAsTransaction returns whether or not a driver requires batched queries to be done within a transaction block.

func CanChangePassword added in v0.5.0

func CanChangePassword(u *dburl.URL) error

CanChangePassword returns whether or not the a driver supports changing passwords.

func ChangePassword added in v0.5.0

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

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

func Columns added in v0.4.0

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

Columns returns the column names for the SQL row result for a driver.

func ConfigStmt added in v0.6.0

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

ConfigStmt sets the stmt.Stmt options for a driver.

func ConvertBytes added in v0.4.0

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

ConvertBytes returns a func to handle converting bytes for a driver.

func ConvertDefault added in v0.14.13

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

ConvertDefault returns a func to handle converting a interface{} for a driver.

func ConvertMap added in v0.14.13

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

ConvertMap returns a func to handle converting a map[string]interface{} for a driver.

func ConvertSlice added in v0.14.13

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

ConvertSlice returns a func to handle converting a []interface{} for a driver.

func Copy added in v0.14.13

func Copy(ctx context.Context, u *dburl.URL, stdout, stderr func() io.Writer, rows *sql.Rows, table string) (int64, error)

Copy copies the result set to the destination sql.DB.

func CopyWithInsert added in v0.14.13

func CopyWithInsert(placeholder func(int) string) func(ctx context.Context, db *sql.DB, rows *sql.Rows, table string) (int64, error)

CopyWithInsert builds a copy handler based on insert.

func ForceParams added in v0.6.0

func ForceParams(u *dburl.URL)

ForceParams forces parameters on the DSN for a driver.

func ForceQueryParameters added in v0.6.0

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

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

func IsBatchQueryPrefix added in v0.14.13

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 added in v0.4.0

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

IsPasswordErr returns true if an err is a password error for a driver.

func Lexer added in v0.6.0

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

Lexer returns the syntax lexer for a driver.

func LowerColumnNames added in v0.14.13

func LowerColumnNames(u *dburl.URL) bool

LowerColumnNames returns whether or not column names should be converted to lower case for a driver.

func NewCompleter added in v0.14.13

func NewCompleter(ctx context.Context, u *dburl.URL, db DB, readerOpts []metadata.ReaderOption, opts ...completer.Option) readline.AutoCompleter

NewCompleter creates a metadata completer for a driver and database connection.

func NewMetadataReader added in v0.14.13

func NewMetadataReader(ctx context.Context, u *dburl.URL, db DB, w io.Writer, opts ...metadata.ReaderOption) (metadata.Reader, error)

NewMetadataReader wraps creating a new database introspector for a driver.

func NewMetadataWriter added in v0.14.13

func NewMetadataWriter(ctx context.Context, u *dburl.URL, db DB, w io.Writer, opts ...metadata.ReaderOption) (metadata.Writer, error)

NewMetadataWriter wraps creating a new database metadata printer for a driver.

func NewStmt added in v0.14.13

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

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

func Open added in v0.4.0

func Open(ctx context.Context, u *dburl.URL, stdout, stderr func() io.Writer) (*sql.DB, error)

Open opens a sql.DB connection for a driver.

func Ping added in v0.4.0

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

Ping pings the database for a driver.

func Process added in v0.4.0

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

Process processes the sql query for a driver.

func QueryExecType added in v0.4.0

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 added in v0.4.0

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

Register registers driver d with name and associated aliases.

func Registered added in v0.4.0

func Registered(name string) bool

Registered returns whether or not a driver is registered.

func RequirePreviousPassword added in v0.5.0

func RequirePreviousPassword(u *dburl.URL) bool

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

func RowsAffected added in v0.4.0

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

RowsAffected returns the rows affected for the SQL result for a driver.

func UseColumnTypes added in v0.14.13

func UseColumnTypes(u *dburl.URL) bool

UseColumnTypes returns whether or not a driver should uses column types.

func User added in v0.5.0

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

User returns the current database user for a driver.

func Version added in v0.4.0

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

Version returns information about the database connection for a driver.

func WrapErr added in v0.4.0

func WrapErr(driver string, err error) error

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

Types

type DB added in v0.5.0

type DB interface {
	Exec(string, ...interface{}) (sql.Result, error)
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
	Prepare(string) (*sql.Stmt, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
}

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

type Driver added in v0.4.0

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
	// LowerColumnNames will cause column names to be lowered cased.
	LowerColumnNames bool
	// UseColumnTypes will cause database's ColumnTypes func to be used for
	// types.
	UseColumnTypes bool
	// ForceParams will be used to force parameters if defined.
	ForceParams func(*dburl.URL)
	// Open will be used by Open if defined.
	Open func(context.Context, *dburl.URL, func() io.Writer, func() io.Writer) (func(string, string) (*sql.DB, error), error)
	// Version will be used by Version if defined.
	Version func(context.Context, DB) (string, error)
	// User will be used by User if defined.
	User func(context.Context, 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)
	// 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
	// NewMetadataReader returns a db metadata introspector.
	NewMetadataReader func(db DB, opts ...metadata.ReaderOption) metadata.Reader
	// NewMetadataWriter returns a db metadata printer.
	NewMetadataWriter func(db DB, w io.Writer, opts ...metadata.ReaderOption) metadata.Writer
	// NewCompleter returns a db auto-completer.
	NewCompleter func(db DB, opts ...completer.Option) readline.AutoCompleter
	// Copy rows into the database table
	Copy func(ctx context.Context, db *sql.DB, rows *sql.Rows, table string) (int64, error)
}

Driver holds funcs for a driver.

type Error added in v0.4.0

type Error struct {
	Driver string
	Err    error
}

Error is a wrapper to standardize errors.

func (*Error) Error added in v0.4.0

func (e *Error) Error() string

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

func (*Error) Unwrap added in v0.14.13

func (e *Error) Unwrap() error

Unwrap returns the original error.

Directories

Path Synopsis
Package adodb defines and registers usql's Microsoft ADODB driver.
Package adodb defines and registers usql's Microsoft ADODB driver.
Package athena defines and registers usql's AWS Athena driver.
Package athena defines and registers usql's AWS Athena driver.
Package avatica defines and registers usql's Apache Avatica driver.
Package avatica defines and registers usql's Apache Avatica driver.
Package bigquery defines and registers usql's Google BigQuery driver.
Package bigquery defines and registers usql's Google BigQuery driver.
Package cassandra defines and registers usql's Cassandra driver.
Package cassandra defines and registers usql's Cassandra driver.
Package clickhouse defines and registers usql's ClickHouse driver.
Package clickhouse defines and registers usql's ClickHouse driver.
completer package provides a generic SQL command line completer
completer package provides a generic SQL command line completer
Package cosmos defines and registers usql's Azure CosmosDB driver.
Package cosmos defines and registers usql's Azure CosmosDB driver.
Package couchbase defines and registers usql's Couchbase driver.
Package couchbase defines and registers usql's Couchbase driver.
Package csvq defines and registers usql's CSVQ driver.
Package csvq defines and registers usql's CSVQ driver.
Package databend defines and registers usql's Databend driver.
Package databend defines and registers usql's Databend driver.
Package exasol defines and registers usql's Exasol driver.
Package exasol defines and registers usql's Exasol driver.
Package firebird defines and registers usql's Firebird driver.
Package firebird defines and registers usql's Firebird driver.
Package flightsql defines and registers usql's FlightSQL driver.
Package flightsql defines and registers usql's FlightSQL driver.
Package genji defines and registers usql's Genji driver.
Package genji defines and registers usql's Genji driver.
Package godror defines and registers usql's GO DRiver for ORacle driver.
Package godror defines and registers usql's GO DRiver for ORacle driver.
Package h2 defines and registers usql's Apache H2 driver.
Package h2 defines and registers usql's Apache H2 driver.
Package hive defines and registers usql's Apache Hive driver.
Package hive defines and registers usql's Apache Hive driver.
Package ignite defines and registers usql's Apache Ignite driver.
Package ignite defines and registers usql's Apache Ignite driver.
Package impala defines and registers usql's Apache Impala driver.
Package impala defines and registers usql's Apache Impala driver.
Package ingres defines and registers usql's Ingres (Actian X, Vector, VectorH) driver.
Package ingres defines and registers usql's Ingres (Actian X, Vector, VectorH) driver.
Package maxcompute defines and registers usql's Alibaba MaxCompute driver.
Package maxcompute defines and registers usql's Alibaba MaxCompute driver.
informationschema
Package informationschema provides metadata readers that query tables from the information_schema schema.
Package informationschema provides metadata readers that query tables from the information_schema schema.
oracle
Package oracle provides a metadata reader
Package oracle provides a metadata reader
postgres
Package postgres provides a metadata reader
Package postgres provides a metadata reader
Package moderncsqlite defines and registers usql's ModernC SQLite3 driver.
Package moderncsqlite defines and registers usql's ModernC SQLite3 driver.
Package mymysql defines and registers usql's MySQL MyMySQL driver.
Package mymysql defines and registers usql's MySQL MyMySQL driver.
Package mysql defines and registers usql's MySQL driver.
Package mysql defines and registers usql's MySQL driver.
Package netezza defines and registers usql's Netezza driver.
Package netezza defines and registers usql's Netezza driver.
Package odbc defines and registers usql's ODBC driver.
Package odbc defines and registers usql's ODBC driver.
Package oracle defines and registers usql's Oracle Database driver.
Package oracle defines and registers usql's Oracle Database driver.
orshared
Package orshared contains shared a shared driver implementation for the Oracle Database.
Package orshared contains shared a shared driver implementation for the Oracle Database.
Package ots defines and registers usql's Alibaba Tablestore driver.
Package ots defines and registers usql's Alibaba Tablestore driver.
Package pgx defines and registers usql's PostgreSQL PGX driver.
Package pgx defines and registers usql's PostgreSQL PGX driver.
Package postgres defines and registers usql's PostgreSQL driver.
Package postgres defines and registers usql's PostgreSQL driver.
Package presto defines and registers usql's Presto driver.
Package presto defines and registers usql's Presto driver.
Package ql defines and registers usql's Cznic QL driver.
Package ql defines and registers usql's Cznic QL driver.
Package sapase defines and registers usql's SAP ASE driver.
Package sapase defines and registers usql's SAP ASE driver.
Package saphana defines and registers usql's SAP HANA driver.
Package saphana defines and registers usql's SAP HANA driver.
Package snowflake defines and registers usql's Snowflake driver.
Package snowflake defines and registers usql's Snowflake driver.
Package spanner defines and registers usql's Google Spanner driver.
Package spanner defines and registers usql's Google Spanner driver.
Package sqlite3 defines and registers usql's SQLite3 driver.
Package sqlite3 defines and registers usql's SQLite3 driver.
sqshared
Package sqshared contains shared types for the sqlite3 and moderncsqlite drivers.
Package sqshared contains shared types for the sqlite3 and moderncsqlite drivers.
Package sqlserver defines and registers usql's Microsoft SQL Server driver.
Package sqlserver defines and registers usql's Microsoft SQL Server driver.
Package trino defines and registers usql's Trino driver.
Package trino defines and registers usql's Trino driver.
Package vertica defines and registers usql's Vertica driver.
Package vertica defines and registers usql's Vertica driver.
Package voltdb defines and registers usql's VoltDB driver.
Package voltdb defines and registers usql's VoltDB driver.

Jump to

Keyboard shortcuts

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