package sql

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

Dependency Relation
	imports 14 packages, and imported by 0 packages

Involved Source Files
	    convert.go
	    ctxutil.go
	d-> sql.go

Exported Type Names

type ColumnType (struct) ColumnType contains the name and type of a column. (*T) DatabaseTypeName() string (*T) DecimalSize() (precision, scale int64, ok bool) (*T) Length() (length int64, ok bool) (*T) Name() string (*T) Nullable() (nullable, ok bool) (*T) ScanType() reflect.Type func (*Rows).ColumnTypes() ([]*ColumnType, error)
type Conn (struct) Conn represents a single database connection rather than a pool of database connections. Prefer running queries from DB unless there is a specific need for a continuous single database connection. A Conn must call Close to return the connection to the database pool and may do so concurrently with a running query. After a call to Close, all operations on the connection fail with ErrConnDone. (*T) BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error) (*T) Close() error (*T) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) (*T) PingContext(ctx context.Context) error (*T) PrepareContext(ctx context.Context, query string) (*Stmt, error) (*T) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) (*T) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row (*T) Raw(f func(driverConn interface{}) error) (err error) *T : io.Closer func (*DB).Conn(ctx context.Context) (*Conn, error)
type DB (struct) DB is a database handle representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines. The sql package creates and frees connections automatically; it also maintains a free pool of idle connections. If the database has a concept of per-connection state, such state can be reliably observed within a transaction (Tx) or connection (Conn). Once DB.Begin is called, the returned Tx is bound to a single connection. Once Commit or Rollback is called on the transaction, that transaction's connection is returned to DB's idle connection pool. The pool size can be controlled with SetMaxIdleConns. (*T) Begin() (*Tx, error) (*T) BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error) (*T) Close() error (*T) Conn(ctx context.Context) (*Conn, error) (*T) Driver() driver.Driver (*T) Exec(query string, args ...interface{}) (Result, error) (*T) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) (*T) Ping() error (*T) PingContext(ctx context.Context) error (*T) Prepare(query string) (*Stmt, error) (*T) PrepareContext(ctx context.Context, query string) (*Stmt, error) (*T) Query(query string, args ...interface{}) (*Rows, error) (*T) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) (*T) QueryRow(query string, args ...interface{}) *Row (*T) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row (*T) SetConnMaxIdleTime(d time.Duration) (*T) SetConnMaxLifetime(d time.Duration) (*T) SetMaxIdleConns(n int) (*T) SetMaxOpenConns(n int) (*T) Stats() DBStats *T : io.Closer func Open(driverName, dataSourceName string) (*DB, error) func OpenDB(c driver.Connector) *DB
type DBStats (struct) DBStats contains database statistics. Idle int InUse int MaxIdleClosed int64 MaxIdleTimeClosed int64 MaxLifetimeClosed int64 MaxOpenConnections int OpenConnections int WaitCount int64 WaitDuration time.Duration func (*DB).Stats() DBStats
type IsolationLevel int IsolationLevel is the transaction isolation level used in TxOptions. (T) String() string T : expvar.Var T : fmt.Stringer const LevelDefault const LevelLinearizable const LevelReadCommitted const LevelReadUncommitted const LevelRepeatableRead const LevelSerializable const LevelSnapshot const LevelWriteCommitted
type NamedArg (struct) A NamedArg is a named argument. NamedArg values may be used as arguments to Query or Exec and bind to the corresponding named parameter in the SQL statement. For a more concise way to create NamedArg values, see the Named function. Name string Value interface{} func Named(name string, value interface{}) NamedArg
type NullBool (struct) NullBool represents a bool that may be null. NullBool implements the Scanner interface so it can be used as a scan destination, similar to NullString. Bool bool Valid bool (*T) Scan(value interface{}) error (T) Value() (driver.Value, error) *T : Scanner T : database/sql/driver.Valuer
type NullFloat64 (struct) NullFloat64 represents a float64 that may be null. NullFloat64 implements the Scanner interface so it can be used as a scan destination, similar to NullString. Float64 float64 Valid bool (*T) Scan(value interface{}) error (T) Value() (driver.Value, error) *T : Scanner T : database/sql/driver.Valuer
type NullInt32 (struct) NullInt32 represents an int32 that may be null. NullInt32 implements the Scanner interface so it can be used as a scan destination, similar to NullString. Int32 int32 Valid bool (*T) Scan(value interface{}) error (T) Value() (driver.Value, error) *T : Scanner T : database/sql/driver.Valuer
type NullInt64 (struct) NullInt64 represents an int64 that may be null. NullInt64 implements the Scanner interface so it can be used as a scan destination, similar to NullString. Int64 int64 Valid bool (*T) Scan(value interface{}) error (T) Value() (driver.Value, error) *T : Scanner T : database/sql/driver.Valuer
type NullString (struct) NullString represents a string that may be null. NullString implements the Scanner interface so it can be used as a scan destination: var s NullString err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&s) ... if s.Valid { // use s.String } else { // NULL value } String string Valid bool (*T) Scan(value interface{}) error (T) Value() (driver.Value, error) *T : Scanner T : database/sql/driver.Valuer
type NullTime (struct) NullTime represents a time.Time that may be null. NullTime implements the Scanner interface so it can be used as a scan destination, similar to NullString. Time time.Time Valid bool (*T) Scan(value interface{}) error (T) Value() (driver.Value, error) *T : Scanner T : database/sql/driver.Valuer
type Out (struct) Out may be used to retrieve OUTPUT value parameters from stored procedures. Not all drivers and databases support OUTPUT value parameters. Example usage: var outArg string _, err := db.ExecContext(ctx, "ProcName", sql.Named("Arg1", sql.Out{Dest: &outArg})) Dest interface{} In bool
type RawBytes ([]) RawBytes is a byte slice that holds a reference to memory owned by the database itself. After a Scan into a RawBytes, the slice is only valid until the next call to Next, Scan, or Close.
type Result (interface) A Result summarizes an executed SQL command. (T) LastInsertId() (int64, error) (T) RowsAffected() (int64, error) database/sql/driver.Result (interface) database/sql/driver.RowsAffected T : database/sql/driver.Result func (*Conn).ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) func (*DB).Exec(query string, args ...interface{}) (Result, error) func (*DB).ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) func (*Stmt).Exec(args ...interface{}) (Result, error) func (*Stmt).ExecContext(ctx context.Context, args ...interface{}) (Result, error) func (*Tx).Exec(query string, args ...interface{}) (Result, error) func (*Tx).ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
type Row (struct) Row is the result of calling QueryRow to select a single row. (*T) Err() error (*T) Scan(dest ...interface{}) error func (*Conn).QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row func (*DB).QueryRow(query string, args ...interface{}) *Row func (*DB).QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row func (*Stmt).QueryRow(args ...interface{}) *Row func (*Stmt).QueryRowContext(ctx context.Context, args ...interface{}) *Row func (*Tx).QueryRow(query string, args ...interface{}) *Row func (*Tx).QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
type Rows (struct) Rows is the result of a query. Its cursor starts before the first row of the result set. Use Next to advance from row to row. (*T) Close() error (*T) ColumnTypes() ([]*ColumnType, error) (*T) Columns() ([]string, error) (*T) Err() error (*T) Next() bool (*T) NextResultSet() bool (*T) Scan(dest ...interface{}) error *T : io.Closer func (*Conn).QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) func (*DB).Query(query string, args ...interface{}) (*Rows, error) func (*DB).QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) func (*Stmt).Query(args ...interface{}) (*Rows, error) func (*Stmt).QueryContext(ctx context.Context, args ...interface{}) (*Rows, error) func (*Tx).Query(query string, args ...interface{}) (*Rows, error) func (*Tx).QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
type Scanner (interface) Scanner is an interface used by Scan. (T) Scan(src interface{}) error *NullBool *NullFloat64 *NullInt32 *NullInt64 *NullString *NullTime
type Stmt (struct) Stmt is a prepared statement. A Stmt is safe for concurrent use by multiple goroutines. If a Stmt is prepared on a Tx or Conn, it will be bound to a single underlying connection forever. If the Tx or Conn closes, the Stmt will become unusable and all operations will return an error. If a Stmt is prepared on a DB, it will remain usable for the lifetime of the DB. When the Stmt needs to execute on a new underlying connection, it will prepare itself on the new connection automatically. (*T) Close() error (*T) Exec(args ...interface{}) (Result, error) (*T) ExecContext(ctx context.Context, args ...interface{}) (Result, error) (*T) Query(args ...interface{}) (*Rows, error) (*T) QueryContext(ctx context.Context, args ...interface{}) (*Rows, error) (*T) QueryRow(args ...interface{}) *Row (*T) QueryRowContext(ctx context.Context, args ...interface{}) *Row *T : io.Closer func (*Conn).PrepareContext(ctx context.Context, query string) (*Stmt, error) func (*DB).Prepare(query string) (*Stmt, error) func (*DB).PrepareContext(ctx context.Context, query string) (*Stmt, error) func (*Tx).Prepare(query string) (*Stmt, error) func (*Tx).PrepareContext(ctx context.Context, query string) (*Stmt, error) func (*Tx).Stmt(stmt *Stmt) *Stmt func (*Tx).StmtContext(ctx context.Context, stmt *Stmt) *Stmt func (*Tx).Stmt(stmt *Stmt) *Stmt func (*Tx).StmtContext(ctx context.Context, stmt *Stmt) *Stmt
type Tx (struct) Tx is an in-progress database transaction. A transaction must end with a call to Commit or Rollback. After a call to Commit or Rollback, all operations on the transaction fail with ErrTxDone. The statements prepared for a transaction by calling the transaction's Prepare or Stmt methods are closed by the call to Commit or Rollback. (*T) Commit() error (*T) Exec(query string, args ...interface{}) (Result, error) (*T) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) (*T) Prepare(query string) (*Stmt, error) (*T) PrepareContext(ctx context.Context, query string) (*Stmt, error) (*T) Query(query string, args ...interface{}) (*Rows, error) (*T) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) (*T) QueryRow(query string, args ...interface{}) *Row (*T) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row (*T) Rollback() error (*T) Stmt(stmt *Stmt) *Stmt (*T) StmtContext(ctx context.Context, stmt *Stmt) *Stmt *T : database/sql/driver.Tx func (*Conn).BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error) func (*DB).Begin() (*Tx, error) func (*DB).BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error)
type TxOptions (struct) TxOptions holds the transaction options to be used in DB.BeginTx. Isolation IsolationLevel ReadOnly bool func (*Conn).BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error) func (*DB).BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error)
Exported Values
func Drivers() []string Drivers returns a sorted list of the names of the registered drivers.
var ErrConnDone error ErrConnDone is returned by any operation that is performed on a connection that has already been returned to the connection pool.
var ErrNoRows error ErrNoRows is returned by Scan when QueryRow doesn't return a row. In such a case, QueryRow returns a placeholder *Row value that defers this error until a Scan.
var ErrTxDone error ErrTxDone is returned by any operation that is performed on a transaction that has already been committed or rolled back.
const LevelDefault IsolationLevel = 0 Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned. See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
const LevelLinearizable IsolationLevel = 7 Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned. See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
const LevelReadCommitted IsolationLevel = 2 Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned. See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
const LevelReadUncommitted IsolationLevel = 1 Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned. See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
const LevelRepeatableRead IsolationLevel = 4 Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned. See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
const LevelSerializable IsolationLevel = 6 Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned. See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
const LevelSnapshot IsolationLevel = 5 Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned. See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
const LevelWriteCommitted IsolationLevel = 3 Various isolation levels that drivers may support in BeginTx. If a driver does not support a given isolation level an error may be returned. See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
func Named(name string, value interface{}) NamedArg Named provides a more concise way to create NamedArg values. Example usage: db.ExecContext(ctx, ` delete from Invoice where TimeCreated < @end and TimeCreated >= @start;`, sql.Named("start", startTime), sql.Named("end", endTime), )
func Open(driverName, dataSourceName string) (*DB, error) Open opens a database specified by its database driver name and a driver-specific data source name, usually consisting of at least a database name and connection information. Most users will open a database via a driver-specific connection helper function that returns a *DB. No database drivers are included in the Go standard library. See https://golang.org/s/sqldrivers for a list of third-party drivers. Open may just validate its arguments without creating a connection to the database. To verify that the data source name is valid, call Ping. The returned DB is safe for concurrent use by multiple goroutines and maintains its own pool of idle connections. Thus, the Open function should be called just once. It is rarely necessary to close a DB.
func OpenDB(c driver.Connector) *DB OpenDB opens a database using a Connector, allowing drivers to bypass a string based data source name. Most users will open a database via a driver-specific connection helper function that returns a *DB. No database drivers are included in the Go standard library. See https://golang.org/s/sqldrivers for a list of third-party drivers. OpenDB may just validate its arguments without creating a connection to the database. To verify that the data source name is valid, call Ping. The returned DB is safe for concurrent use by multiple goroutines and maintains its own pool of idle connections. Thus, the OpenDB function should be called just once. It is rarely necessary to close a DB.
func Register(name string, driver driver.Driver) Register makes a database driver available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.