Namespace: go.std.database.sql
v1.0Contents
Summary
Provides a low-level interface to the database/sql package.
Package sql provides a generic interface around SQL (or SQL-like)
databases.
The sql package must be used in conjunction with a database driver.
See https://golang.org/s/sqldrivers for a list of drivers.
Drivers that do not support context cancellation will not return until
after the query is completed.
For usage examples, see the wiki page at
https://golang.org/s/sqlwiki.
Index
- *ColumnType
- *Conn
- *DB
- *DBStats
- *IsolationLevel
- *NamedArg
- *NullBool
- *NullByte
- *NullFloat64
- *NullInt16
- *NullInt32
- *NullInt64
- *NullString
- *NullTime
- *Out
- *RawBytes
- *Row
- *Rows
- *Stmt
- *Tx
- *TxOptions
- ColumnType
- Conn
- DB
- DBStats
- Drivers
- ErrConnDone
- ErrNoRows
- ErrTxDone
- IsolationLevel
- LevelDefault
- LevelLinearizable
- LevelReadCommitted
- LevelReadUncommitted
- LevelRepeatableRead
- LevelSerializable
- LevelSnapshot
- LevelWriteCommitted
- Named
- NamedArg
- NullBool
- NullByte
- NullFloat64
- NullInt16
- NullInt32
- NullInt64
- NullString
- NullTime
- Open
- OpenDB
- Out
- RawBytes
- Register
- Result
- Row
- Rows
- Scanner
- Stmt
- Tx
- TxOptions
- arrayOfColumnType
- arrayOfConn
- arrayOfDB
- arrayOfDBStats
- arrayOfIsolationLevel
- arrayOfNamedArg
- arrayOfNullBool
- arrayOfNullByte
- arrayOfNullFloat64
- arrayOfNullInt16
- arrayOfNullInt32
- arrayOfNullInt64
- arrayOfNullString
- arrayOfNullTime
- arrayOfOut
- arrayOfRawBytes
- arrayOfResult
- arrayOfRow
- arrayOfRows
- arrayOfScanner
- arrayOfStmt
- arrayOfTx
- arrayOfTxOptions
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
ErrConnDone
Var v1.0ErrConnDone is returned by any operation that is performed on a connection
that has already been returned to the connection pool.
-
ErrNoRows
Var v1.0ErrNoRows 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.
-
ErrTxDone
Var v1.0ErrTxDone is returned by any operation that is performed on a transaction
that has already been committed or rolled back.
-
LevelDefault
GoObject v1.0Various 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.
-
LevelLinearizable
GoObject v1.0Various 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.
-
LevelReadCommitted
GoObject v1.0Various 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.
-
LevelReadUncommitted
GoObject v1.0Various 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.
-
LevelRepeatableRead
GoObject v1.0Various 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.
-
LevelSerializable
GoObject v1.0Various 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.
-
LevelSnapshot
GoObject v1.0Various 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.
-
LevelWriteCommitted
GoObject v1.0Various 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.
Functions, Macros, and Special Forms
-
Drivers
Function v1.0(Drivers)
Drivers returns a sorted list of the names of the registered drivers.
Go returns: []string
Joker input arguments: []
Joker returns: ^arrayOfString -
Named
Function v1.0(Named name value)
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),
)
Go input arguments: (name string, value any)
Go returns: NamedArg
Joker input arguments: [^String name, ^GoObject value]
Joker returns: ^NamedArg -
Open
Function v1.0(Open driverName dataSourceName)
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.
Go input arguments: (driverName string, dataSourceName string)
Go returns: (*DB, error)
Joker input arguments: [^String driverName, ^String dataSourceName]
Joker returns: [^*DB, ^Error] -
OpenDB
Function v1.0(OpenDB c)
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.
Go input arguments: (c database/sql/driver.Connector)
Go returns: *DB
Joker input arguments: [^go.std.database.sql.driver/Connector c]
Joker returns: ^*DB -
Register
Function v1.0(Register name 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.
Go input arguments: (name string, driver database/sql/driver.Driver)
Joker input arguments: [^String name, ^go.std.database.sql.driver/Driver driver]
Types
-
*ColumnType
Concrete Type v1.0ColumnType contains the name and type of a column.
-
DatabaseTypeName
Receiver for *ColumnType v1.0([])
DatabaseTypeName returns the database system name of the column type. If an empty
string is returned, then the driver type name is not supported.
Consult your driver documentation for a list of driver data types. Length specifiers
are not included.
Common type names include "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL",
"INT", and "BIGINT".
-
DecimalSize
Receiver for *ColumnType v1.0([])
DecimalSize returns the scale and precision of a decimal type.
If not applicable or if not supported ok is false.
-
Length
Receiver for *ColumnType v1.0([])
Length returns the column type length for variable length column types such
as text and binary field types. If the type length is unbounded the value will
be math.MaxInt64 (any database limits will still apply).
If the column type is not variable length, such as an int, or if not supported
by the driver ok is false.
-
Name
Receiver for *ColumnType v1.0([])
Name returns the name or alias of the column.
-
Nullable
Receiver for *ColumnType v1.0([])
Nullable reports whether the column may be null.
If a driver does not support this property ok will be false.
-
ScanType
Receiver for *ColumnType v1.0([])
ScanType returns a Go type suitable for scanning into using Rows.Scan.
If a driver does not support this property ScanType will return
the type of an empty interface.
-
*Conn
Concrete Type v1.0Conn 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.
-
BeginTx
Receiver for *Conn v1.0([ctx opts])
BeginTx starts a transaction.
The provided context is used until the transaction is committed or rolled back.
If the context is canceled, the sql package will roll back
the transaction. Tx.Commit will return an error if the context provided to
BeginTx is canceled.
The provided TxOptions is optional and may be nil if defaults should be used.
If a non-default isolation level is used that the driver doesn't support,
an error will be returned.
-
Close
Receiver for *Conn v1.0([])
Close returns the connection to the connection pool.
All operations after a Close will return with ErrConnDone.
Close is safe to call concurrently with other operations and will
block until all other operations finish. It may be useful to first
cancel any used context and then call close directly after.
-
ExecContext
Receiver for *Conn v1.0([ctx query args])
ExecContext executes a query without returning any rows.
The args are for any placeholder parameters in the query.
-
PingContext
Receiver for *Conn v1.0([ctx])
PingContext verifies the connection to the database is still alive.
-
PrepareContext
Receiver for *Conn v1.0([ctx query])
PrepareContext creates a prepared statement for later queries or executions.
Multiple queries or executions may be run concurrently from the
returned statement.
The caller must call the statement's Close method
when the statement is no longer needed.
The provided context is used for the preparation of the statement, not for the
execution of the statement.
-
QueryContext
Receiver for *Conn v1.0([ctx query args])
QueryContext executes a query that returns rows, typically a SELECT.
The args are for any placeholder parameters in the query.
-
QueryRowContext
Receiver for *Conn v1.0([ctx query args])
QueryRowContext executes a query that is expected to return at most one row.
QueryRowContext always returns a non-nil value. Errors are deferred until
Row's Scan method is called.
If the query selects no rows, the *Row's Scan will return ErrNoRows.
Otherwise, the *Row's Scan scans the first selected row and discards
the rest.
-
*DB
Concrete Type v1.0DB 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.
-
Begin
Receiver for *DB v1.0([])
Begin starts a transaction. The default isolation level is dependent on
the driver.
Begin uses context.Background internally; to specify the context, use
BeginTx.
-
BeginTx
Receiver for *DB v1.0([ctx opts])
BeginTx starts a transaction.
The provided context is used until the transaction is committed or rolled back.
If the context is canceled, the sql package will roll back
the transaction. Tx.Commit will return an error if the context provided to
BeginTx is canceled.
The provided TxOptions is optional and may be nil if defaults should be used.
If a non-default isolation level is used that the driver doesn't support,
an error will be returned.
-
Close
Receiver for *DB v1.0([])
Close closes the database and prevents new queries from starting.
Close then waits for all queries that have started processing on the server
to finish.
It is rare to Close a DB, as the DB handle is meant to be
long-lived and shared between many goroutines.
-
Conn
Receiver for *DB v1.0([ctx])
Conn returns a single connection by either opening a new connection
or returning an existing connection from the connection pool. Conn will
block until either a connection is returned or ctx is canceled.
Queries run on the same Conn will be run in the same database session.
Every Conn must be returned to the database pool after use by
calling Conn.Close.
-
Driver
Receiver for *DB v1.0([])
Driver returns the database's underlying driver.
-
Exec
Receiver for *DB v1.0([query args])
Exec executes a query without returning any rows.
The args are for any placeholder parameters in the query.
Exec uses context.Background internally; to specify the context, use
ExecContext.
-
ExecContext
Receiver for *DB v1.0([ctx query args])
ExecContext executes a query without returning any rows.
The args are for any placeholder parameters in the query.
-
Ping
Receiver for *DB v1.0([])
Ping verifies a connection to the database is still alive,
establishing a connection if necessary.
Ping uses context.Background internally; to specify the context, use
PingContext.
-
PingContext
Receiver for *DB v1.0([ctx])
PingContext verifies a connection to the database is still alive,
establishing a connection if necessary.
-
Prepare
Receiver for *DB v1.0([query])
Prepare creates a prepared statement for later queries or executions.
Multiple queries or executions may be run concurrently from the
returned statement.
The caller must call the statement's Close method
when the statement is no longer needed.
Prepare uses context.Background internally; to specify the context, use
PrepareContext.
-
PrepareContext
Receiver for *DB v1.0([ctx query])
PrepareContext creates a prepared statement for later queries or executions.
Multiple queries or executions may be run concurrently from the
returned statement.
The caller must call the statement's Close method
when the statement is no longer needed.
The provided context is used for the preparation of the statement, not for the
execution of the statement.
-
Query
Receiver for *DB v1.0([query args])
Query executes a query that returns rows, typically a SELECT.
The args are for any placeholder parameters in the query.
Query uses context.Background internally; to specify the context, use
QueryContext.
-
QueryContext
Receiver for *DB v1.0([ctx query args])
QueryContext executes a query that returns rows, typically a SELECT.
The args are for any placeholder parameters in the query.
-
QueryRow
Receiver for *DB v1.0([query args])
QueryRow executes a query that is expected to return at most one row.
QueryRow always returns a non-nil value. Errors are deferred until
Row's Scan method is called.
If the query selects no rows, the *Row's Scan will return ErrNoRows.
Otherwise, the *Row's Scan scans the first selected row and discards
the rest.
QueryRow uses context.Background internally; to specify the context, use
QueryRowContext.
-
QueryRowContext
Receiver for *DB v1.0([ctx query args])
QueryRowContext executes a query that is expected to return at most one row.
QueryRowContext always returns a non-nil value. Errors are deferred until
Row's Scan method is called.
If the query selects no rows, the *Row's Scan will return ErrNoRows.
Otherwise, the *Row's Scan scans the first selected row and discards
the rest.
-
SetConnMaxIdleTime
Receiver for *DB v1.0([d])
SetConnMaxIdleTime sets the maximum amount of time a connection may be idle.
Expired connections may be closed lazily before reuse.
If d <= 0, connections are not closed due to a connection's idle time.
-
SetConnMaxLifetime
Receiver for *DB v1.0([d])
SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
Expired connections may be closed lazily before reuse.
If d <= 0, connections are not closed due to a connection's age.
-
SetMaxIdleConns
Receiver for *DB v1.0([n])
SetMaxIdleConns sets the maximum number of connections in the idle
connection pool.
If MaxOpenConns is greater than 0 but less than the new MaxIdleConns,
then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.
If n <= 0, no idle connections are retained.
The default max idle connections is currently 2. This may change in
a future release.
-
SetMaxOpenConns
Receiver for *DB v1.0([n])
SetMaxOpenConns sets the maximum number of open connections to the database.
If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than
MaxIdleConns, then MaxIdleConns will be reduced to match the new
MaxOpenConns limit.
If n <= 0, then there is no limit on the number of open connections.
The default is 0 (unlimited).
-
Stats
Receiver for *DB v1.0([])
Stats returns database statistics.
-
*DBStats
Concrete Type v1.0DBStats contains database statistics.
-
*IsolationLevel
Concrete Type v1.0IsolationLevel is the transaction isolation level used in TxOptions.
-
*NamedArg
Concrete Type v1.0A 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.
-
*NullBool
Concrete Type v1.0NullBool represents a bool that may be null.
NullBool implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Scan
Receiver for *NullBool v1.0([value])
Scan implements the Scanner interface.
-
*NullByte
Concrete Type v1.0NullByte represents a byte that may be null.
NullByte implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Scan
Receiver for *NullByte v1.0([value])
Scan implements the Scanner interface.
-
*NullFloat64
Concrete Type v1.0NullFloat64 represents a float64 that may be null.
NullFloat64 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Scan
Receiver for *NullFloat64 v1.0([value])
Scan implements the Scanner interface.
-
*NullInt16
Concrete Type v1.0NullInt16 represents an int16 that may be null.
NullInt16 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Scan
Receiver for *NullInt16 v1.0([value])
Scan implements the Scanner interface.
-
*NullInt32
Concrete Type v1.0NullInt32 represents an int32 that may be null.
NullInt32 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Scan
Receiver for *NullInt32 v1.0([value])
Scan implements the Scanner interface.
-
*NullInt64
Concrete Type v1.0NullInt64 represents an int64 that may be null.
NullInt64 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Scan
Receiver for *NullInt64 v1.0([value])
Scan implements the Scanner interface.
-
*NullString
Concrete Type v1.0NullString 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
}
-
Scan
Receiver for *NullString v1.0([value])
Scan implements the Scanner interface.
-
*NullTime
Concrete Type v1.0NullTime 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.
-
Scan
Receiver for *NullTime v1.0([value])
Scan implements the Scanner interface.
-
*Out
Concrete Type v1.0Out 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}))
-
*RawBytes
Concrete Type v1.0RawBytes 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.
-
*Row
Concrete Type v1.0Row is the result of calling QueryRow to select a single row.
-
Err
Receiver for *Row v1.0([])
Err provides a way for wrapping packages to check for
query errors without calling Scan.
Err returns the error, if any, that was encountered while running the query.
If this error is not nil, this error will also be returned from Scan.
-
Scan
Receiver for *Row v1.0([dest])
Scan copies the columns from the matched row into the values
pointed at by dest. See the documentation on Rows.Scan for details.
If more than one row matches the query,
Scan uses the first row and discards the rest. If no row matches
the query, Scan returns ErrNoRows.
-
*Rows
Concrete Type v1.0Rows 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.
-
Close
Receiver for *Rows v1.0([])
Close closes the Rows, preventing further enumeration. If Next is called
and returns false and there are no further result sets,
the Rows are closed automatically and it will suffice to check the
result of Err. Close is idempotent and does not affect the result of Err.
-
ColumnTypes
Receiver for *Rows v1.0([])
ColumnTypes returns column information such as column type, length,
and nullable. Some information may not be available from some drivers.
-
Columns
Receiver for *Rows v1.0([])
Columns returns the column names.
Columns returns an error if the rows are closed.
-
Err
Receiver for *Rows v1.0([])
Err returns the error, if any, that was encountered during iteration.
Err may be called after an explicit or implicit Close.
-
Next
Receiver for *Rows v1.0([])
Next prepares the next result row for reading with the Scan method. It
returns true on success, or false if there is no next result row or an error
happened while preparing it. Err should be consulted to distinguish between
the two cases.
Every call to Scan, even the first one, must be preceded by a call to Next.
-
NextResultSet
Receiver for *Rows v1.0([])
NextResultSet prepares the next result set for reading. It reports whether
there is further result sets, or false if there is no further result set
or if there is an error advancing to it. The Err method should be consulted
to distinguish between the two cases.
After calling NextResultSet, the Next method should always be called before
scanning. If there are further result sets they may not have rows in the result
set.
-
Scan
Receiver for *Rows v1.0([dest])
Scan copies the columns in the current row into the values pointed
at by dest. The number of values in dest must be the same as the
number of columns in Rows.
Scan converts columns read from the database into the following
common Go types and special types provided by the sql package:
*string
*[]byte
*int, *int8, *int16, *int32, *int64
*uint, *uint8, *uint16, *uint32, *uint64
*bool
*float32, *float64
*interface{}
*RawBytes
*Rows (cursor value)
any type implementing Scanner (see Scanner docs)
In the most simple case, if the type of the value from the source
column is an integer, bool or string type T and dest is of type *T,
Scan simply assigns the value through the pointer.
Scan also converts between string and numeric types, as long as no
information would be lost. While Scan stringifies all numbers
scanned from numeric database columns into *string, scans into
numeric types are checked for overflow. For example, a float64 with
value 300 or a string with value "300" can scan into a uint16, but
not into a uint8, though float64(255) or "255" can scan into a
uint8. One exception is that scans of some float64 numbers to
strings may lose information when stringifying. In general, scan
floating point columns into *float64.
If a dest argument has type *[]byte, Scan saves in that argument a
copy of the corresponding data. The copy is owned by the caller and
can be modified and held indefinitely. The copy can be avoided by
using an argument of type *RawBytes instead; see the documentation
for RawBytes for restrictions on its use.
If an argument has type *interface{}, Scan copies the value
provided by the underlying driver without conversion. When scanning
from a source value of type []byte to *interface{}, a copy of the
slice is made and the caller owns the result.
Source values of type time.Time may be scanned into values of type
*time.Time, *interface{}, *string, or *[]byte. When converting to
the latter two, time.RFC3339Nano is used.
Source values of type bool may be scanned into types *bool,
*interface{}, *string, *[]byte, or *RawBytes.
For scanning into *bool, the source may be true, false, 1, 0, or
string inputs parseable by strconv.ParseBool.
Scan can also convert a cursor returned from a query, such as
"select cursor(select * from my_table) from dual", into a
*Rows value that can itself be scanned from. The parent
select query will close any cursor *Rows if the parent *Rows is closed.
If any of the first arguments implementing Scanner returns an error,
that error will be wrapped in the returned error
-
*Stmt
Concrete Type v1.0Stmt 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.
-
Close
Receiver for *Stmt v1.0([])
Close closes the statement.
-
Exec
Receiver for *Stmt v1.0([args])
Exec executes a prepared statement with the given arguments and
returns a Result summarizing the effect of the statement.
Exec uses context.Background internally; to specify the context, use
ExecContext.
-
ExecContext
Receiver for *Stmt v1.0([ctx args])
ExecContext executes a prepared statement with the given arguments and
returns a Result summarizing the effect of the statement.
-
Query
Receiver for *Stmt v1.0([args])
Query executes a prepared query statement with the given arguments
and returns the query results as a *Rows.
Query uses context.Background internally; to specify the context, use
QueryContext.
-
QueryContext
Receiver for *Stmt v1.0([ctx args])
QueryContext executes a prepared query statement with the given arguments
and returns the query results as a *Rows.
-
QueryRow
Receiver for *Stmt v1.0([args])
QueryRow executes a prepared query statement with the given arguments.
If an error occurs during the execution of the statement, that error will
be returned by a call to Scan on the returned *Row, which is always non-nil.
If the query selects no rows, the *Row's Scan will return ErrNoRows.
Otherwise, the *Row's Scan scans the first selected row and discards
the rest.
Example usage:
var name string
err := nameByUseridStmt.QueryRow(id).Scan(&name)
QueryRow uses context.Background internally; to specify the context, use
QueryRowContext.
-
QueryRowContext
Receiver for *Stmt v1.0([ctx args])
QueryRowContext executes a prepared query statement with the given arguments.
If an error occurs during the execution of the statement, that error will
be returned by a call to Scan on the returned *Row, which is always non-nil.
If the query selects no rows, the *Row's Scan will return ErrNoRows.
Otherwise, the *Row's Scan scans the first selected row and discards
the rest.
-
*Tx
Concrete Type v1.0Tx 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.
-
Commit
Receiver for *Tx v1.0([])
Commit commits the transaction.
-
Exec
Receiver for *Tx v1.0([query args])
Exec executes a query that doesn't return rows.
For example: an INSERT and UPDATE.
Exec uses context.Background internally; to specify the context, use
ExecContext.
-
ExecContext
Receiver for *Tx v1.0([ctx query args])
ExecContext executes a query that doesn't return rows.
For example: an INSERT and UPDATE.
-
Prepare
Receiver for *Tx v1.0([query])
Prepare creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed
when the transaction has been committed or rolled back.
To use an existing prepared statement on this transaction, see Tx.Stmt.
Prepare uses context.Background internally; to specify the context, use
PrepareContext.
-
PrepareContext
Receiver for *Tx v1.0([ctx query])
PrepareContext creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed
when the transaction has been committed or rolled back.
To use an existing prepared statement on this transaction, see Tx.Stmt.
The provided context will be used for the preparation of the context, not
for the execution of the returned statement. The returned statement
will run in the transaction context.
-
Query
Receiver for *Tx v1.0([query args])
Query executes a query that returns rows, typically a SELECT.
Query uses context.Background internally; to specify the context, use
QueryContext.
-
QueryContext
Receiver for *Tx v1.0([ctx query args])
QueryContext executes a query that returns rows, typically a SELECT.
-
QueryRow
Receiver for *Tx v1.0([query args])
QueryRow executes a query that is expected to return at most one row.
QueryRow always returns a non-nil value. Errors are deferred until
Row's Scan method is called.
If the query selects no rows, the *Row's Scan will return ErrNoRows.
Otherwise, the *Row's Scan scans the first selected row and discards
the rest.
QueryRow uses context.Background internally; to specify the context, use
QueryRowContext.
-
QueryRowContext
Receiver for *Tx v1.0([ctx query args])
QueryRowContext executes a query that is expected to return at most one row.
QueryRowContext always returns a non-nil value. Errors are deferred until
Row's Scan method is called.
If the query selects no rows, the *Row's Scan will return ErrNoRows.
Otherwise, the *Row's Scan scans the first selected row and discards
the rest.
-
Rollback
Receiver for *Tx v1.0([])
Rollback aborts the transaction.
-
Stmt
Receiver for *Tx v1.0([stmt])
Stmt returns a transaction-specific prepared statement from
an existing statement.
Example:
updateMoney, err := db.Prepare("UPDATE balance SET money=money+? WHERE id=?")
...
tx, err := db.Begin()
...
res, err := tx.Stmt(updateMoney).Exec(123.45, 98293203)
The returned statement operates within the transaction and will be closed
when the transaction has been committed or rolled back.
Stmt uses context.Background internally; to specify the context, use
StmtContext.
-
StmtContext
Receiver for *Tx v1.0([ctx stmt])
StmtContext returns a transaction-specific prepared statement from
an existing statement.
Example:
updateMoney, err := db.Prepare("UPDATE balance SET money=money+? WHERE id=?")
...
tx, err := db.Begin()
...
res, err := tx.StmtContext(ctx, updateMoney).Exec(123.45, 98293203)
The provided context is used for the preparation of the statement, not for the
execution of the statement.
The returned statement operates within the transaction and will be closed
when the transaction has been committed or rolled back.
-
*TxOptions
Concrete Type v1.0TxOptions holds the transaction options to be used in DB.BeginTx.
-
ColumnType
Concrete Type v1.0ColumnType contains the name and type of a column.
-
Conn
Concrete Type v1.0Conn 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.
-
DB
Concrete Type v1.0DB 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.
-
DBStats
Concrete Type v1.0DBStats contains database statistics.
-
IsolationLevel
Concrete Type v1.0IsolationLevel is the transaction isolation level used in TxOptions.
-
String
Receiver for IsolationLevel v1.0([])
String returns the name of the transaction isolation level.
-
NamedArg
Concrete Type v1.0A 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.
-
NullBool
Concrete Type v1.0NullBool represents a bool that may be null.
NullBool implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Value
Receiver for NullBool v1.0([])
Value implements the driver Valuer interface.
-
NullByte
Concrete Type v1.0NullByte represents a byte that may be null.
NullByte implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Value
Receiver for NullByte v1.0([])
Value implements the driver Valuer interface.
-
NullFloat64
Concrete Type v1.0NullFloat64 represents a float64 that may be null.
NullFloat64 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Value
Receiver for NullFloat64 v1.0([])
Value implements the driver Valuer interface.
-
NullInt16
Concrete Type v1.0NullInt16 represents an int16 that may be null.
NullInt16 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Value
Receiver for NullInt16 v1.0([])
Value implements the driver Valuer interface.
-
NullInt32
Concrete Type v1.0NullInt32 represents an int32 that may be null.
NullInt32 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Value
Receiver for NullInt32 v1.0([])
Value implements the driver Valuer interface.
-
NullInt64
Concrete Type v1.0NullInt64 represents an int64 that may be null.
NullInt64 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
Value
Receiver for NullInt64 v1.0([])
Value implements the driver Valuer interface.
-
NullString
Concrete Type v1.0NullString 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
}
-
Value
Receiver for NullString v1.0([])
Value implements the driver Valuer interface.
-
NullTime
Concrete Type v1.0NullTime 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.
-
Value
Receiver for NullTime v1.0([])
Value implements the driver Valuer interface.
-
Out
Concrete Type v1.0Out 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}))
-
RawBytes
Concrete Type v1.0RawBytes 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.
-
Result
Abstract Type v1.0A Result summarizes an executed SQL command.
-
LastInsertId
Method for Result v1.0([])
-
RowsAffected
Method for Result v1.0([])
-
Row
Concrete Type v1.0Row is the result of calling QueryRow to select a single row.
-
Rows
Concrete Type v1.0Rows 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.
-
Scanner
Abstract Type v1.0Scanner is an interface used by Scan.
-
Scan
Method for Scanner v1.0([src])
-
Stmt
Concrete Type v1.0Stmt 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.
-
Tx
Concrete Type v1.0Tx 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.
-
TxOptions
Concrete Type v1.0TxOptions holds the transaction options to be used in DB.BeginTx.
-
arrayOfColumnType
Concrete Type v1.0ColumnType contains the name and type of a column.
-
arrayOfConn
Concrete Type v1.0Conn 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.
-
arrayOfDB
Concrete Type v1.0DB 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.
-
arrayOfDBStats
Concrete Type v1.0DBStats contains database statistics.
-
arrayOfIsolationLevel
Concrete Type v1.0IsolationLevel is the transaction isolation level used in TxOptions.
-
arrayOfNamedArg
Concrete Type v1.0A 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.
-
arrayOfNullBool
Concrete Type v1.0NullBool represents a bool that may be null.
NullBool implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
arrayOfNullByte
Concrete Type v1.0NullByte represents a byte that may be null.
NullByte implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
arrayOfNullFloat64
Concrete Type v1.0NullFloat64 represents a float64 that may be null.
NullFloat64 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
arrayOfNullInt16
Concrete Type v1.0NullInt16 represents an int16 that may be null.
NullInt16 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
arrayOfNullInt32
Concrete Type v1.0NullInt32 represents an int32 that may be null.
NullInt32 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
arrayOfNullInt64
Concrete Type v1.0NullInt64 represents an int64 that may be null.
NullInt64 implements the Scanner interface so
it can be used as a scan destination, similar to NullString.
-
arrayOfNullString
Concrete Type v1.0NullString 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
}
-
arrayOfNullTime
Concrete Type v1.0NullTime 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.
-
arrayOfOut
Concrete Type v1.0Out 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}))
-
arrayOfRawBytes
Concrete Type v1.0RawBytes 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.
-
arrayOfResult
Concrete Type v1.0A Result summarizes an executed SQL command.
-
arrayOfRow
Concrete Type v1.0Row is the result of calling QueryRow to select a single row.
-
arrayOfRows
Concrete Type v1.0Rows 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.
-
arrayOfScanner
Concrete Type v1.0Scanner is an interface used by Scan.
-
arrayOfStmt
Concrete Type v1.0Stmt 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.
-
arrayOfTx
Concrete Type v1.0Tx 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.
-
arrayOfTxOptions
Concrete Type v1.0TxOptions holds the transaction options to be used in DB.BeginTx.