Involved Source Filescopy.go
Package database adds some useful functionality to a sql.DB.
It is independent of the database driver and the
DB schema.
driver.gologging.goreflect.go
Package-Level Type Names (total 10, in which 2 are exported)
emptyStringScanner wraps the functionality of sql.NullString to just write
an empty string if the value is NULL.
ptr*string( T) Scan(value interface{}) error
T : database/sql.Scanner
Begin starts and returns a new transaction.
Deprecated: Drivers should implement ConnBeginTx instead (or additionally).
BeginTx starts and returns a new transaction.
If the context is canceled by the user the sql package will
call Tx.Rollback before discarding and closing the connection.
This must check opts.Isolation to determine if there is a set
isolation level. If the driver does not support a non-default
level and one is set or if there is a non-default isolation level
that is not supported, an error must be returned.
This must also check opts.ReadOnly to determine if the read-only
value is true to either set the read-only transaction property if supported
or return an error if it is not supported.
Close invalidates and potentially stops any current
prepared statements and transactions, marking this
connection as no longer in use.
Because the sql package maintains a free pool of
connections and only calls Close when there's a surplus of
idle connections, it shouldn't be necessary for drivers to
do their own connection caching.
Drivers must ensure all network calls made by Close
do not block indefinitely (e.g. apply a timeout).
( T) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)( T) Ping(ctx context.Context) error
Prepare returns a prepared statement, bound to this connection.
PrepareContext returns a prepared statement, bound to this connection.
context is for the preparation of the statement,
it must not store the context within the statement itself.
( T) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
*github.com/jackc/pgx/v4/stdlib.Conn
*wrapConn
contrib.go.opencensus.io/integrations/ocsql.conn(interface)
*contrib.go.opencensus.io/integrations/ocsql.ocConn
T : database/sql/driver.Conn
T : database/sql/driver.ConnBeginTx
T : database/sql/driver.ConnPrepareContext
T : database/sql/driver.ExecerContext
T : database/sql/driver.Pinger
T : database/sql/driver.QueryerContext
T : io.Closer
ptr is a pointer to a pointer to something: **T
( T) Scan(value interface{}) error( T) Value() (driver.Value, error)
T : database/sql.Scanner
T : database/sql/driver.Valuer
func NullPtr(p interface{}) nullPtr
Package-Level Functions (total 17, in which 7 are exported)
CopyFromChan returns a CopyFromSource that gets its rows from a channel.
New creates a new DB from a sql.DB.
NullIsEmpty returns a sql.Scanner that writes the empty string to s if the
sql.Value is NULL.
NullPtr is for scanning nullable database columns into pointer variables or
fields. When given a pointer to to a pointer to some type T, it returns a
value that can be passed to a Scan function. If the corresponding column is
nil, the variable will be set to nil. Otherwise, it will be set to a newly
allocated pointer to the column value.
Open creates a new DB for the given connection string.
RegisterOCWrapper registers a driver that wraps the OpenCensus driver, which in
turn wraps the driver named as the first argument.
StructScanner takes a struct and returns a function that, when called on a
struct pointer of that type, returns a slice of arguments suitable for
Row.Scan or Rows.Scan. The call to either Scan will populate the exported
fields of the struct in the order they appear in the type definition.
StructScanner panics if p is not a struct or a pointer to a struct.
The function it returns will panic if its argument is not a pointer
to a struct.
Example:
type Player struct { Name string; Score int }
playerScanArgs := database.StructScanner(Player{})
err := db.RunQuery(ctx, "SELECT name, score FROM players", func(rows *sql.Rows) error {
var p Player
if err := rows.Scan(playerScanArgs(&p)...); err != nil {
return err
}
// use p
return nil
})
buildInsertQuery builds an multi-value insert query, following the format:
INSERT TO <table> (<columns>) VALUES (<placeholders-for-each-item-in-values>) <conflictAction>
If returningColumns is not empty, it appends a RETURNING clause to the query.
When calling buildInsertQuery, it must be true that nvalues % len(columns) == 0.
Package-Level Variables (total 4, in which 1 are exported)
QueryLoggingDisabled stops logging of queries when true.
For use in tests only: not concurrency-safe.
maxBulkUpdateArrayLen is the maximum size of an array that BulkUpdate will send to
Postgres. (Postgres has no size limit on arrays, but we want to keep the statements
to a reasonable size.)
It is a variable for testing.
serializationFailureCode is the Postgres error code returned when a serializable
transaction fails because it would violate serializability.
See https://www.postgresql.org/docs/current/errcodes-appendix.html.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.