package stdlib

Import Path
	github.com/jackc/pgx/v4/stdlib (on go.dev)

Dependency Relation
	imports 15 packages, and imported by 3 packages

Involved Source Files Package stdlib is the compatibility layer from pgx to database/sql. A database/sql connection can be established through sql.Open. db, err := sql.Open("pgx", "postgres://pgx_md5:secret@localhost:5432/pgx_test?sslmode=disable") if err != nil { return err } Or from a DSN string. db, err := sql.Open("pgx", "user=postgres password=secret host=localhost port=5432 database=pgx_test sslmode=disable") if err != nil { return err } Or a pgx.ConnConfig can be used to set configuration not accessible via connection string. In this case the pgx.ConnConfig must first be registered with the driver. This registration returns a connection string which is used with sql.Open. connConfig, _ := pgx.ParseConfig(os.Getenv("DATABASE_URL")) connConfig.Logger = myLogger connStr := stdlib.RegisterConnConfig(connConfig) db, _ := sql.Open("pgx", connStr) pgx uses standard PostgreSQL positional parameters in queries. e.g. $1, $2. It does not support named parameters. db.QueryRow("select * from users where id=$1", userID) In Go 1.13 and above (*sql.Conn) Raw() can be used to get a *pgx.Conn from the standard database/sql.DB connection pool. This allows operations that use pgx specific functionality. // Given db is a *sql.DB conn, err := db.Conn(context.Background()) if err != nil { // handle error from acquiring connection from DB pool } err = conn.Raw(func(driverConn interface{}) error { conn := driverConn.(*stdlib.Conn).Conn() // conn is a *pgx.Conn // Do pgx specific stuff with conn conn.CopyFrom(...) return nil }) if err != nil { // handle error that occurred while using *pgx.Conn }
Package-Level Type Names (total 11, in which 5 are exported)
/* sort exporteds by: | */
(*T) Begin() (driver.Tx, error) (*T) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) (*T) CheckNamedValue(*driver.NamedValue) error (*T) Close() error Conn returns the underlying *pgx.Conn (*T) ExecContext(ctx context.Context, query string, argsV []driver.NamedValue) (driver.Result, error) (*T) Ping(ctx context.Context) error (*T) Prepare(query string) (driver.Stmt, error) (*T) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) (*T) QueryContext(ctx context.Context, query string, argsV []driver.NamedValue) (driver.Rows, error) (*T) ResetSession(ctx context.Context) error *T : database/sql/driver.Conn *T : database/sql/driver.ConnBeginTx *T : database/sql/driver.ConnPrepareContext *T : database/sql/driver.ExecerContext *T : database/sql/driver.NamedValueChecker *T : database/sql/driver.Pinger *T : database/sql/driver.QueryerContext *T : database/sql/driver.SessionResetter *T : io.Closer
(*T) Open(name string) (driver.Conn, error) (*T) OpenConnector(name string) (driver.Connector, error) *T : database/sql/driver.Driver *T : database/sql/driver.DriverContext
OptionOpenDB options for configuring the driver when opening a new db pool. func OptionAfterConnect(ac func(context.Context, *pgx.Conn) error) OptionOpenDB func OpenDB(config pgx.ConnConfig, opts ...OptionOpenDB) *sql.DB
(*T) Close() error ColumnTypeDatabaseTypeName returns the database system type name. If the name is unknown the OID is returned. ColumnTypeLength returns 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. ColumnTypePrecisionScale should return the precision and scale for decimal types. If not applicable, ok should be false. ColumnTypeScanType returns the value type that can be used to scan types into. (*T) Columns() []string (*T) Next(dest []driver.Value) error *T : database/sql/driver.Rows *T : database/sql/driver.RowsColumnTypeDatabaseTypeName *T : database/sql/driver.RowsColumnTypeLength *T : database/sql/driver.RowsColumnTypePrecisionScale *T : database/sql/driver.RowsColumnTypeScanType *T : io.Closer
(*T) Close() error (*T) Exec(argsV []driver.Value) (driver.Result, error) (*T) ExecContext(ctx context.Context, argsV []driver.NamedValue) (driver.Result, error) (*T) NumInput() int (*T) Query(argsV []driver.Value) (driver.Rows, error) (*T) QueryContext(ctx context.Context, argsV []driver.NamedValue) (driver.Rows, error) *T : database/sql/driver.Stmt *T : database/sql/driver.StmtExecContext *T : database/sql/driver.StmtQueryContext *T : io.Closer
Package-Level Functions (total 10, in which 7 are exported)
AcquireConn acquires a *pgx.Conn from database/sql connection pool. It must be released with ReleaseConn. In Go 1.13 this functionality has been incorporated into the standard library in the db.Conn.Raw() method.
GetDefaultDriver returns the driver initialized in the init function and used when the pgx driver is registered.
OptionAfterConnect provide a callback for after connect.
RegisterConnConfig registers a ConnConfig and returns the connection string to use with Open.
ReleaseConn releases a *pgx.Conn acquired with AcquireConn.
UnregisterConnConfig removes the ConnConfig registration for connStr.
Package-Level Variables (total 6, in which 1 are exported)
Package-Level Constants (only one, which is unexported)