package driver

Import Path
	database/sql/driver (on golang.org and go.dev)

Dependency Relation
	imports 6 packages, and imported by 7 packages

Involved Source Files
	d-> driver.go
	    types.go

Exported Type Names

type ColumnConverter (interface) ColumnConverter may be optionally implemented by Stmt if the statement is aware of its own columns' types and can convert from any type to a driver Value. Deprecated: Drivers should implement NamedValueChecker. (T) ColumnConverter(idx int) ValueConverter
type Conn (interface) Conn is a connection to a database. It is not used concurrently by multiple goroutines. Conn is assumed to be stateful. (T) Begin() (Tx, error) (T) Close() error (T) Prepare(query string) (Stmt, error) T : io.Closer func Connector.Connect(context.Context) (Conn, error) func Driver.Open(name string) (Conn, error) func github.com/go-sql-driver/mysql.MySQLDriver.Open(dsn string) (Conn, error)
type ConnBeginTx (interface) ConnBeginTx enhances the Conn interface with context and TxOptions. (T) BeginTx(ctx context.Context, opts TxOptions) (Tx, error)
type Connector (interface) A Connector represents a driver in a fixed configuration and can create any number of equivalent Conns for use by multiple goroutines. A Connector can be passed to sql.OpenDB, to allow drivers to implement their own sql.DB constructors, or returned by DriverContext's OpenConnector method, to allow drivers access to context and to avoid repeated parsing of driver configuration. (T) Connect(context.Context) (Conn, error) (T) Driver() Driver func DriverContext.OpenConnector(name string) (Connector, error) func github.com/go-sql-driver/mysql.NewConnector(cfg *mysql.Config) (Connector, error) func github.com/go-sql-driver/mysql.MySQLDriver.OpenConnector(dsn string) (Connector, error) func database/sql.OpenDB(c Connector) *sql.DB
type ConnPrepareContext (interface) ConnPrepareContext enhances the Conn interface with context. (T) PrepareContext(ctx context.Context, query string) (Stmt, error)
type Driver (interface) Driver is the interface that must be implemented by a database driver. Database drivers may implement DriverContext for access to contexts and to parse the name only once for a pool of connections, instead of once per connection. (T) Open(name string) (Conn, error) github.com/go-sql-driver/mysql.MySQLDriver func Connector.Driver() Driver func database/sql.(*DB).Driver() Driver func database/sql.Register(name string, driver Driver)
type DriverContext (interface) If a Driver implements DriverContext, then sql.DB will call OpenConnector to obtain a Connector and then invoke that Connector's Connect method to obtain each needed connection, instead of invoking the Driver's Open method for each connection. The two-step sequence allows drivers to parse the name just once and also provides access to per-Conn contexts. (T) OpenConnector(name string) (Connector, error) github.com/go-sql-driver/mysql.MySQLDriver
type Execer (interface) Execer is an optional interface that may be implemented by a Conn. If a Conn implements neither ExecerContext nor Execer, the sql package's DB.Exec will first prepare a query, execute the statement, and then close the statement. Exec may return ErrSkip. Deprecated: Drivers should implement ExecerContext instead. (T) Exec(query string, args []Value) (Result, error)
type ExecerContext (interface) ExecerContext is an optional interface that may be implemented by a Conn. If a Conn does not implement ExecerContext, the sql package's DB.Exec will fall back to Execer; if the Conn does not implement Execer either, DB.Exec will first prepare a query, execute the statement, and then close the statement. ExecerContext may return ErrSkip. ExecerContext must honor the context timeout and return when the context is canceled. (T) ExecContext(ctx context.Context, query string, args []NamedValue) (Result, error)
type IsolationLevel int IsolationLevel is the transaction isolation level stored in TxOptions. This type should be considered identical to sql.IsolationLevel along with any values defined on it.
type NamedValue (struct) NamedValue holds both the value name and value. Name string Ordinal int Value Value func ExecerContext.ExecContext(ctx context.Context, query string, args []NamedValue) (Result, error) func NamedValueChecker.CheckNamedValue(*NamedValue) error func QueryerContext.QueryContext(ctx context.Context, query string, args []NamedValue) (Rows, error) func StmtExecContext.ExecContext(ctx context.Context, args []NamedValue) (Result, error) func StmtQueryContext.QueryContext(ctx context.Context, args []NamedValue) (Rows, error)
type NamedValueChecker (interface) NamedValueChecker may be optionally implemented by Conn or Stmt. It provides the driver more control to handle Go and database types beyond the default Values types allowed. The sql package checks for value checkers in the following order, stopping at the first found match: Stmt.NamedValueChecker, Conn.NamedValueChecker, Stmt.ColumnConverter, DefaultParameterConverter. If CheckNamedValue returns ErrRemoveArgument, the NamedValue will not be included in the final query arguments. This may be used to pass special options to the query itself. If ErrSkip is returned the column converter error checking path is used for the argument. Drivers may wish to return ErrSkip after they have exhausted their own special cases. (T) CheckNamedValue(*NamedValue) error
type NotNull (struct) NotNull is a type that implements ValueConverter by disallowing nil values but otherwise delegating to another ValueConverter. Converter ValueConverter (T) ConvertValue(v interface{}) (Value, error) T : ValueConverter
type Null (struct) Null is a type that implements ValueConverter by allowing nil values but otherwise delegating to another ValueConverter. Converter ValueConverter (T) ConvertValue(v interface{}) (Value, error) T : ValueConverter
type Pinger (interface) Pinger is an optional interface that may be implemented by a Conn. If a Conn does not implement Pinger, the sql package's DB.Ping and DB.PingContext will check if there is at least one Conn available. If Conn.Ping returns ErrBadConn, DB.Ping and DB.PingContext will remove the Conn from pool. (T) Ping(ctx context.Context) error
type Queryer (interface) Queryer is an optional interface that may be implemented by a Conn. If a Conn implements neither QueryerContext nor Queryer, the sql package's DB.Query will first prepare a query, execute the statement, and then close the statement. Query may return ErrSkip. Deprecated: Drivers should implement QueryerContext instead. (T) Query(query string, args []Value) (Rows, error)
type QueryerContext (interface) QueryerContext is an optional interface that may be implemented by a Conn. If a Conn does not implement QueryerContext, the sql package's DB.Query will fall back to Queryer; if the Conn does not implement Queryer either, DB.Query will first prepare a query, execute the statement, and then close the statement. QueryerContext may return ErrSkip. QueryerContext must honor the context timeout and return when the context is canceled. (T) QueryContext(ctx context.Context, query string, args []NamedValue) (Rows, error)
type Result (interface) Result is the result of a query execution. (T) LastInsertId() (int64, error) (T) RowsAffected() (int64, error) RowsAffected database/sql.Result (interface) T : database/sql.Result func Execer.Exec(query string, args []Value) (Result, error) func ExecerContext.ExecContext(ctx context.Context, query string, args []NamedValue) (Result, error) func Stmt.Exec(args []Value) (Result, error) func StmtExecContext.ExecContext(ctx context.Context, args []NamedValue) (Result, error)
type Rows (interface) Rows is an iterator over an executed query's results. (T) Close() error (T) Columns() []string (T) Next(dest []Value) error RowsColumnTypeDatabaseTypeName (interface) RowsColumnTypeLength (interface) RowsColumnTypeNullable (interface) RowsColumnTypePrecisionScale (interface) RowsColumnTypeScanType (interface) RowsNextResultSet (interface) T : io.Closer func Queryer.Query(query string, args []Value) (Rows, error) func QueryerContext.QueryContext(ctx context.Context, query string, args []NamedValue) (Rows, error) func Stmt.Query(args []Value) (Rows, error) func StmtQueryContext.QueryContext(ctx context.Context, args []NamedValue) (Rows, error)
type RowsAffected int64 RowsAffected implements Result for an INSERT or UPDATE operation which mutates a number of rows. (T) LastInsertId() (int64, error) (T) RowsAffected() (int64, error) T : Result T : database/sql.Result
type RowsColumnTypeDatabaseTypeName (interface) RowsColumnTypeDatabaseTypeName may be implemented by Rows. It should return the database system type name without the length. Type names should be uppercase. Examples of returned types: "VARCHAR", "NVARCHAR", "VARCHAR2", "CHAR", "TEXT", "DECIMAL", "SMALLINT", "INT", "BIGINT", "BOOL", "[]BIGINT", "JSONB", "XML", "TIMESTAMP". (T) Close() error (T) ColumnTypeDatabaseTypeName(index int) string (T) Columns() []string (T) Next(dest []Value) error T : Rows T : io.Closer
type RowsColumnTypeLength (interface) RowsColumnTypeLength may be implemented by Rows. It should return the length of the column type if the column is a variable length type. If the column is not a variable length type ok should return false. If length is not limited other than system limits, it should return math.MaxInt64. The following are examples of returned values for various types: TEXT (math.MaxInt64, true) varchar(10) (10, true) nvarchar(10) (10, true) decimal (0, false) int (0, false) bytea(30) (30, true) (T) Close() error (T) ColumnTypeLength(index int) (length int64, ok bool) (T) Columns() []string (T) Next(dest []Value) error T : Rows T : io.Closer
type RowsColumnTypeNullable (interface) RowsColumnTypeNullable may be implemented by Rows. The nullable value should be true if it is known the column may be null, or false if the column is known to be not nullable. If the column nullability is unknown, ok should be false. (T) Close() error (T) ColumnTypeNullable(index int) (nullable, ok bool) (T) Columns() []string (T) Next(dest []Value) error T : Rows T : io.Closer
type RowsColumnTypePrecisionScale (interface) RowsColumnTypePrecisionScale may be implemented by Rows. It should return the precision and scale for decimal types. If not applicable, ok should be false. The following are examples of returned values for various types: decimal(38, 4) (38, 4, true) int (0, 0, false) decimal (math.MaxInt64, math.MaxInt64, true) (T) Close() error (T) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) (T) Columns() []string (T) Next(dest []Value) error T : Rows T : io.Closer
type RowsColumnTypeScanType (interface) RowsColumnTypeScanType may be implemented by Rows. It should return the value type that can be used to scan types into. For example, the database column type "bigint" this should return "reflect.TypeOf(int64(0))". (T) Close() error (T) ColumnTypeScanType(index int) reflect.Type (T) Columns() []string (T) Next(dest []Value) error T : Rows T : io.Closer
type RowsNextResultSet (interface) RowsNextResultSet extends the Rows interface by providing a way to signal the driver to advance to the next result set. (T) Close() error (T) Columns() []string (T) HasNextResultSet() bool (T) Next(dest []Value) error (T) NextResultSet() error T : Rows T : io.Closer
type SessionResetter (interface) SessionResetter may be implemented by Conn to allow drivers to reset the session state associated with the connection and to signal a bad connection. (T) ResetSession(ctx context.Context) error
type Stmt (interface) Stmt is a prepared statement. It is bound to a Conn and not used by multiple goroutines concurrently. (T) Close() error (T) Exec(args []Value) (Result, error) (T) NumInput() int (T) Query(args []Value) (Rows, error) T : io.Closer func Conn.Prepare(query string) (Stmt, error) func ConnPrepareContext.PrepareContext(ctx context.Context, query string) (Stmt, error)
type StmtExecContext (interface) StmtExecContext enhances the Stmt interface by providing Exec with context. (T) ExecContext(ctx context.Context, args []NamedValue) (Result, error)
type StmtQueryContext (interface) StmtQueryContext enhances the Stmt interface by providing Query with context. (T) QueryContext(ctx context.Context, args []NamedValue) (Rows, error)
type Tx (interface) Tx is a transaction. (T) Commit() error (T) Rollback() error database/sql.(*Tx) gorm.io/gorm.(*PreparedStmtTX) gorm.io/gorm.TxCommitter (interface) T : gorm.io/gorm.TxCommitter func Conn.Begin() (Tx, error) func ConnBeginTx.BeginTx(ctx context.Context, opts TxOptions) (Tx, error)
type TxOptions (struct) TxOptions holds the transaction options. This type should be considered identical to sql.TxOptions. Isolation IsolationLevel ReadOnly bool func ConnBeginTx.BeginTx(ctx context.Context, opts TxOptions) (Tx, error)
type Validator (interface) Validator may be implemented by Conn to allow drivers to signal if a connection is valid or if it should be discarded. If implemented, drivers may return the underlying error from queries, even if the connection should be discarded by the connection pool. (T) IsValid() bool go/token.Pos go/token.(*Position) internal/reflectlite.Value reflect.Value
type Value (interface) Value is a value that drivers must be able to handle. It is either nil, a type handled by a database driver's NamedValueChecker interface, or an instance of one of these types: int64 float64 bool []byte string time.Time If the driver supports cursors, a returned Value may also implement the Rows interface in this package. This is used, for example, when a user selects a cursor such as "select cursor(select * from my_table) from dual". If the Rows from the select is closed, the cursor Rows will also be closed. func NotNull.ConvertValue(v interface{}) (Value, error) func Null.ConvertValue(v interface{}) (Value, error) func ValueConverter.ConvertValue(v interface{}) (Value, error) func Valuer.Value() (Value, error) func database/sql.NullBool.Value() (Value, error) func database/sql.NullFloat64.Value() (Value, error) func database/sql.NullInt32.Value() (Value, error) func database/sql.NullInt64.Value() (Value, error) func database/sql.NullString.Value() (Value, error) func database/sql.NullTime.Value() (Value, error) func github.com/go-sql-driver/mysql.NullTime.Value() (Value, error) func gorm.io/gorm.DeletedAt.Value() (Value, error) func Execer.Exec(query string, args []Value) (Result, error) func Queryer.Query(query string, args []Value) (Rows, error) func Rows.Next(dest []Value) error func RowsColumnTypeDatabaseTypeName.Next(dest []Value) error func RowsColumnTypeLength.Next(dest []Value) error func RowsColumnTypeNullable.Next(dest []Value) error func RowsColumnTypePrecisionScale.Next(dest []Value) error func RowsColumnTypeScanType.Next(dest []Value) error func RowsNextResultSet.Next(dest []Value) error func Stmt.Exec(args []Value) (Result, error) func Stmt.Query(args []Value) (Rows, error)
type ValueConverter (interface) ValueConverter is the interface providing the ConvertValue method. Various implementations of ValueConverter are provided by the driver package to provide consistent implementations of conversions between drivers. The ValueConverters have several uses: * converting from the Value types as provided by the sql package into a database table's specific column type and making sure it fits, such as making sure a particular int64 fits in a table's uint16 column. * converting a value as given from the database into one of the driver Value types. * by the sql package, for converting from a driver's Value type to a user's type in a scan. (T) ConvertValue(v interface{}) (Value, error) NotNull Null func ColumnConverter.ColumnConverter(idx int) ValueConverter
type Valuer (interface) Valuer is the interface providing the Value method. Types implementing Valuer interface are able to convert themselves to a driver Value. (T) Value() (Value, error) database/sql.NullBool database/sql.NullFloat64 database/sql.NullInt32 database/sql.NullInt64 database/sql.NullString database/sql.NullTime github.com/go-sql-driver/mysql.NullTime gorm.io/gorm.DeletedAt
Exported Values
var Bool boolType Bool is a ValueConverter that converts input values to bools. The conversion rules are: - booleans are returned unchanged - for integer types, 1 is true 0 is false, other integers are an error - for strings and []byte, same rules as strconv.ParseBool - all other types are an error
var DefaultParameterConverter defaultConverter DefaultParameterConverter is the default implementation of ValueConverter that's used when a Stmt doesn't implement ColumnConverter. DefaultParameterConverter returns its argument directly if IsValue(arg). Otherwise, if the argument implements Valuer, its Value method is used to return a Value. As a fallback, the provided argument's underlying type is used to convert it to a Value: underlying integer types are converted to int64, floats to float64, bool, string, and []byte to themselves. If the argument is a nil pointer, ConvertValue returns a nil Value. If the argument is a non-nil pointer, it is dereferenced and ConvertValue is called recursively. Other types are an error.
var ErrBadConn error ErrBadConn should be returned by a driver to signal to the sql package that a driver.Conn is in a bad state (such as the server having earlier closed the connection) and the sql package should retry on a new connection. To prevent duplicate operations, ErrBadConn should NOT be returned if there's a possibility that the database server might have performed the operation. Even if the server sends back an error, you shouldn't return ErrBadConn.
var ErrRemoveArgument error ErrRemoveArgument may be returned from NamedValueChecker to instruct the sql package to not pass the argument to the driver query interface. Return when accepting query specific options or structures that aren't SQL query arguments.
var ErrSkip error ErrSkip may be returned by some optional interfaces' methods to indicate at runtime that the fast path is unavailable and the sql package should continue as if the optional interface was not implemented. ErrSkip is only supported where explicitly documented.
var Int32 int32Type Int32 is a ValueConverter that converts input values to int64, respecting the limits of an int32 value.
func IsScanValue(v interface{}) bool IsScanValue is equivalent to IsValue. It exists for compatibility.
func IsValue(v interface{}) bool IsValue reports whether v is a valid Value parameter type.
var ResultNoRows noRows ResultNoRows is a pre-defined Result for drivers to return when a DDL command (such as a CREATE TABLE) succeeds. It returns an error for both LastInsertId and RowsAffected.
var String stringType String is a ValueConverter that converts its input to a string. If the value is already a string or []byte, it's unchanged. If the value is of another type, conversion to string is done with fmt.Sprintf("%v", v).