pgx/pgconn
Alejandro Do Nascimento Mora c4ac6d810f Use DefaultQueryExecMode in CopyFrom
CopyFrom had to create a prepared statement to get the OIDs of the data
types that were going to be copied into the table. Every COPY operation
required an extra round trips to retrieve the type information. There
was no way to customize this behavior.

By leveraging the QueryExecMode feature, like in `Conn.Query`, users can
specify if they want to cache the prepared statements, execute
them on every request (like the old behavior), or bypass the prepared
statement relying on the pgtype.Map to get the type information.

The `QueryExecMode` behave exactly like in `Conn.Query` in the way the
data type OIDs are fetched, meaning that:

- `QueryExecModeCacheStatement`: caches the statement.
- `QueryExecModeCacheDescribe`: caches the statement and assumes they do
  not change.
- `QueryExecModeDescribeExec`: gets the statement description on every
  execution. This is like to the old behavior of `CopyFrom`.
- `QueryExecModeExec` and `QueryExecModeSimpleProtocol`: maintain the
  same behavior as before, which is the same as `QueryExecModeDescribeExec`.
  It will keep getting the statement description on every execution

The `QueryExecMode` can only be set via
`ConnConfig.DefaultQueryExecMode`, unlike `Conn.Query` there's no
support for specifying the `QueryExecMode` via optional arguments
in the function signature.
2022-12-23 13:22:26 -06:00
..
internal/ctxwatch Bump module version to v5 2021-12-11 13:29:03 -06:00
README.md Improve testing / contributing instructions 2022-10-29 17:14:09 -05:00
auth_scram.go Merge remote-tracking branch 'pgconn/master' into v5-dev 2022-07-12 06:45:54 -05:00
benchmark_private_test.go Use string internally for CommandTag 2022-07-11 21:09:03 -05:00
benchmark_test.go pgconn and pgproto use same environment variable for tests as pgx 2022-10-29 13:23:25 -05:00
config.go Expose underlying pgconn GetSSLPassword support to pgx 2022-11-03 20:09:52 -05:00
config_test.go pgconn and pgproto use same environment variable for tests as pgx 2022-10-29 13:23:25 -05:00
defaults.go Make Chunkreader an internal implementation detail 2022-02-26 08:50:46 -06:00
defaults_windows.go Make Chunkreader an internal implementation detail 2022-02-26 08:50:46 -06:00
doc.go Add pipeline mode to pgconn 2022-07-02 21:48:16 -05:00
errors.go pgconn.Timeout() no longer considers `context.Canceled` as a timeout error. 2022-09-17 10:18:06 -05:00
errors_test.go Bump module version to v5 2021-12-11 13:29:03 -06:00
export_test.go Import to pgx main repo in pgconn subdir 2021-12-04 13:51:24 -06:00
helper_test.go Bump module version to v5 2021-12-11 13:29:03 -06:00
krb5.go Merge remote-tracking branch 'pgconn/master' into v5-dev 2022-07-12 06:45:54 -05:00
pgconn.go pgconn.Timeout() no longer considers `context.Canceled` as a timeout error. 2022-09-17 10:18:06 -05:00
pgconn_private_test.go Use string internally for CommandTag 2022-07-11 21:09:03 -05:00
pgconn_stress_test.go pgconn and pgproto use same environment variable for tests as pgx 2022-10-29 13:23:25 -05:00
pgconn_test.go Use DefaultQueryExecMode in CopyFrom 2022-12-23 13:22:26 -06:00

README.md

pgconn

Package pgconn is a low-level PostgreSQL database driver. It operates at nearly the same level as the C library libpq. It is primarily intended to serve as the foundation for higher level libraries such as https://github.com/jackc/pgx. Applications should handle normal queries with a higher level library and only use pgconn directly when required for low-level access to PostgreSQL functionality.

Example Usage

pgConn, err := pgconn.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
	log.Fatalln("pgconn failed to connect:", err)
}
defer pgConn.Close(context.Background())

result := pgConn.ExecParams(context.Background(), "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
for result.NextRow() {
	fmt.Println("User 123 has email:", string(result.Values()[0]))
}
_, err = result.Close()
if err != nil {
	log.Fatalln("failed reading result:", err)
}

Testing

See CONTRIBUTING.md for setup instructions.