Commit Graph

521 Commits (04bcc0219dc3acf67f27e68decd6dffe97334779)

Author SHA1 Message Date
Jack Christensen 29254180ca Add callback functions to queued queries
Improve batch query ergonomics by allowing the code to handle the
results of a query to be right next to the query.
2022-07-16 17:46:47 -05:00
Jack Christensen 78875bb95a Add tracing support
Replaces existing logging support. Package tracelog provides adapter for
old style logging.

https://github.com/jackc/pgx/issues/1061
2022-07-16 12:27:10 -05:00
Jack Christensen 9201cc0341 ConnectConfig copies config 2022-07-16 08:58:43 -05:00
Jack Christensen 786de2bda8 Use correct cache 2022-07-11 20:42:55 -05:00
Jack Christensen 90c2dc6f68 Rename ForEachScannedRow to ForEachRow 2022-07-09 16:47:28 -05:00
Jack Christensen c31b89a3f2 Delay handling invalidated statements when in transaction 2022-07-09 10:20:54 -05:00
Jack Christensen e7aa76ccf9 SendBatch now uses pipeline mode to prepare and describe statements
Previously, a batch with 10 unique parameterized statements executed
100 times would entail 11 network round trips. 1 for each prepare /
describe and 1 for executing them all. Now pipeline mode is used to
prepare / describe all statements in a single network round trip. So it
would only take 2 round trips.
2022-07-09 09:32:36 -05:00
Jack Christensen 76946fb5a3 Replace QueryFunc with ForEachScannedRow 2022-07-07 20:29:04 -05:00
Jack Christensen 1168b375e4 Expose pgx functionality for manual integration with pgconn
This is primarily useful for using pipeline mode.
2022-07-04 13:29:49 -05:00
Stepan Rabotkin 4099b447b9 feat: add batch logging 2022-05-12 19:05:08 -05:00
Jack Christensen a89a400b69 Fix documentation for Rows.RawValues and test new behavior 2022-04-30 08:27:57 -05:00
Jack Christensen e8f81bb7de Merge branch 'master' into v5-dev
Rewrite fix for https://github.com/jackc/pgx/issues/1196 for pgx v5.
2022-04-28 08:06:34 -05:00
Jack Christensen 7ceeea6fe6 Fix explicitly prepared statements with describe statement cache mode
fixes https://github.com/jackc/pgx/issues/1196
2022-04-28 07:58:24 -05:00
Jack Christensen 107196ab0c Add NamedArgs
https://github.com/jackc/pgx/issues/1186
https://github.com/jackc/pgx/issues/387
2022-04-23 18:45:38 -05:00
Jack Christensen b72b0daa5a Add QueryRewriter interface 2022-04-23 17:26:42 -05:00
Jack Christensen 1f4b34f932 Merge branch 'master' into v5-dev 2022-04-23 11:05:24 -05:00
Jack Christensen 097b6aacb7 Add time to logging failed Exec
fixes #1189
2022-04-21 19:26:25 -05:00
Jack Christensen f14fb3d692 Replace interface{} with any 2022-04-09 09:12:55 -05:00
Jack Christensen ee93440ac1 pgtype uses pgxtest
Added ValueRoundTripTest to pgxtest
Removed pgtype/testutil

pgtype tests now run with all (applicable) query modes. This gives
better coverage than before and revealed several bugs which are also
fixed in this commit.
2022-04-02 14:34:19 -05:00
Jack Christensen 500c0721d7 Improve error messages for query argument encoding 2022-04-01 18:00:25 -05:00
Jack Christensen 72b72b9ae9 Remove dead code 2022-03-12 15:07:32 -06:00
Jack Christensen cb721dfb5b SendBatch supports default QueryExecMode 2022-03-12 15:06:13 -06:00
Jack Christensen 1390a11fe2 Query supports QueryExecMode
Fixed QueryExecModeExec as it must only use text format without
specifying param OIDs.
2022-03-12 14:15:39 -06:00
Jack Christensen 46966227bc Enable all QueryExecModes for exec path 2022-03-12 10:04:02 -06:00
Jack Christensen 8e341e20f3 Remove ConnConfig.BuildStatementCache 2022-03-12 09:23:40 -06:00
Jack Christensen f27178ba85 Initial privatization of stmtcache
ConnConfig.BuildStatementCache is pending removal once connections
always have separate caches for prepared and described statements.
2022-03-12 08:35:31 -06:00
Jack Christensen fe21cc7486 Use Map.Encode path for simple protocol 2022-03-05 21:40:49 -06:00
Jack Christensen c4b08378f2 Handle driver.Valuers inside Map.Encode 2022-03-05 21:27:17 -06:00
Jack Christensen 1cef9075d9 Simply typed nil and driver.Valuer handling
* Convert typed nils to untyped nils at beginning of encoding process.
* Restore v4 json/jsonb null behavior
* Add anynil internal package
2022-03-05 19:53:59 -06:00
Jack Christensen 0d8e109c21 Test every QueryExecMode 2022-03-05 14:04:51 -06:00
Jack Christensen aad3d65e16 Initial restructure of simple protocol to query exec mode 2022-03-05 10:27:15 -06:00
Jack Christensen 95cbbfe441 Import pgproto3
Also copy in pgmock as an internal package.
2022-02-21 13:22:42 -06:00
Jack Christensen 1f2f239d09 Renamed pgtype.ConnInfo to pgtype.Map 2022-02-21 09:13:09 -06:00
Jack Christensen bda10b2ec9 Rename pgtype.DataType to pgtype.Type 2022-02-21 09:01:48 -06:00
Jack Christensen 5daa487a2c Merge branch 'master' into v5-dev 2022-02-21 08:35:11 -06:00
Jack Christensen b6b24f9e8a Allocate connRows on demand instead of preallocating in bulk
The 64 element preallocatedRows may be pinning memory from previous
queries.

See https://github.com/jackc/pgx/issues/1127
2022-02-19 11:51:25 -06:00
Jack Christensen 1e565b0d44 Handle stmtCache.Get error previously thought impossible
The statement cache is already prefilled, but it is possible for the
ctx to be canceled between when the statement is prepared and when the
statement is retrieved for use.

refs #1156
2022-02-19 11:28:39 -06:00
Jack Christensen 9c5dfbdfb3 pgconn.CommandTag is now an opaque type
It now makes a copy instead of retaining driver memory. This is in
preparation to reuse the driver read buffer.
2022-02-12 10:26:26 -06:00
Jack Christensen 4b6d527b0b Merge branch 'master' into v5-dev 2022-02-12 09:22:37 -06:00
Saimon Shaplygin 4ac1499060 ref: remove anchored code 2022-02-12 09:15:24 -06:00
Jack Christensen 558748ef9c ArrayCodec contains element DataType 2022-01-29 16:41:07 -06:00
Jack Christensen b5bf9d7bb9 Move LoadDataType to pgx.Conn 2022-01-29 16:32:05 -06:00
Jack Christensen 72cc95e4dd Bump module version to v5 2021-12-11 13:29:03 -06:00
Jack Christensen 0e293b966c Finish import of pgconn 2021-12-04 14:06:57 -06:00
Jack Christensen 7e13db4538 Finish import of pgtype repo
Fix some tests that broke by merging repos
Tweak readme wording
2021-12-04 13:45:57 -06:00
Jack Christensen a457da8bff Unpin extendedQueryBuilder memory immediately after use
refs #1110
2021-11-13 17:12:09 -06:00
Jack Christensen 851091fdf4 Improve Query docs regarding error detection 2021-11-13 04:42:28 -06:00
Dan Gillis b28c053c39 Add comments 2021-09-25 09:26:59 -05:00
Dan Gillis bb8d7ffc87 Add comments
Add several comments and correct ConnectConfig
2021-09-25 09:26:59 -05:00
Jack Christensen a49f4bb135 Use errors instead of golang.org/x/xerrors 2021-03-25 09:55:12 -04:00
Jack Christensen f8c43c97ab Document prefer_simple_protocol config option 2021-03-04 19:58:52 -06:00
Jack Christensen d9ac491657 Add prefer_simple_protocol option to ParseConfig
refs #650
2021-03-04 19:56:14 -06:00
Jack Christensen e8f959e0e1 Add QueryFunc
refs #821
2020-12-12 09:39:58 -06:00
Ethan Pailes 1df45d758d fix stmtcache invalidation
This patch fixes jackc/pgx#841. The meat of the fix lives
in [a PR to the pgconn repo][1]. This change just checks
for errors after executing a prepared statement and informs
the underlying stmtcache about them so that it can properly
clean up. We don't try to get fancy with retries or anything
like that, just return the error and allow the application to handle it.

I had to make [some][1] [changes][2] to to the jackc/pgconn package as well
as this package.

Fixes #841

[1]: https://github.com/jackc/pgconn/pull/56
[2]: https://github.com/jackc/pgconn/pull/55
2020-11-12 08:15:13 -05:00
Jack Christensen 7c47415150 Fix SendBatch of all prepared statements with statement cache disabled
fixes #856
2020-10-29 20:28:57 -05:00
Oleg Kovalov 5f8d853b34 remove unused definitions on conn.go 2020-10-12 08:13:52 -05:00
Oleg Kovalov 557018a24e use simpler strings funcs 2020-10-05 19:26:33 -05:00
Jinzhu 5b06f03d0a Fix SimpleProtocol with prepared statement 2020-08-31 17:06:36 -05:00
georgysavva e29ce9f6d6 Add Config.Copy() in pgx and pgxpool packages. Conn.Config() and Pool.Config() return copy of the original config. 2020-06-02 13:35:05 +03:00
georgysavva 608451a215 Store original config in Conn before updating it. 2020-06-01 19:38:12 +03:00
Jordan Lewis 25099e6f89 Permit SendBatch with Simple Protocol
This commit adds support for sending batches of queries via the Simple
protocol with SendBatch. The result appears identically to how it would
if it were created with the extended protocol.
2020-05-25 01:37:48 -04:00
Jack Christensen ac6c49c39d Require access to ConnString via Config
A Config object may be created via ParseConfig and then further
modified. Requiring access to the original ConnString via the Config
helps indicate that the Config is the source of truth as to how the
connection was actually established.
2020-05-16 18:12:04 -05:00
georgysavva 20c6c44f9f Expose Conn.Config() and Pool.Config(). 2020-05-16 19:53:08 +03:00
georgysavva 33cbec368f rename ConnStr -> ConnString 2020-05-16 19:24:57 +03:00
georgysavva a62de87342 Add ConnStr getter to Pool and Conn structs. 2020-05-16 18:10:29 +03:00
Ben Bader a10b89ebc0 Add query logging for individual batch items 2020-02-18 16:22:29 -08:00
malstoun 8dc8431ef9 Add arguments count check to execParamsAndPreparedPrefix 2020-01-04 12:41:49 +03:00
Jack Christensen 10d5f5eaa8 Do not mutate config.Config.OnNotification in connect
fixes #618
2019-10-12 11:06:43 -05:00
Jack Christensen e16bfa9af5 Add docs regarding closing BatchResults 2019-09-19 22:46:43 -05:00
Jack Christensen 76348773bd Make Conn.ConnInfo private 2019-09-10 18:09:21 -05:00
Jack Christensen 4952a488f2 Add more docs for Conn.Query 2019-09-10 17:35:08 -05:00
Jack Christensen 4a320500cf Remove barely used ProtocolError type 2019-08-27 18:31:54 -05:00
Jack Christensen 863b41aaa6 Remove unused sentinal error 2019-08-27 18:29:38 -05:00
Jack Christensen 8170eaf401 Update to latest version of pgconn
- Also remove a few tests of functionality that is handled by pgconn
2019-08-27 18:22:34 -05:00
Jack Christensen 169632e028 Refactor format code choosing 2019-08-25 00:38:50 -05:00
Jack Christensen a262126b5c Replace IsAlive with IsClosed
IsAlive is ambiguous because the connection may be dead and we do not
know it. It implies the possibility of a ping. IsClosed is clearer -- it
does not promise the connection is alive only that it hasn't been
closed.
2019-08-24 23:49:59 -05:00
Jack Christensen 64b07f0d66 Batch uses statement cache.
This streamlines Queue's interface as well.
2019-08-24 23:40:21 -05:00
Jack Christensen 6508934508 Rename PreparedStatementCache to StatementCache 2019-08-24 22:19:29 -05:00
Jack Christensen 3675337e5b Update for rename of pgconn.PreparedStatementDescription 2019-08-24 20:44:56 -05:00
Jack Christensen 0c3e59b07a Add automatic statement cache 2019-08-24 20:29:54 -05:00
Jack Christensen 180dfe6954 Remove bad error check 2019-08-24 16:29:44 -05:00
Jack Christensen 31705e586a Use pgconn.PreparedStatementDescription directly
Instead of having similar pgx.PreparedStatement
2019-08-24 14:29:05 -05:00
Jack Christensen 6972a57421 pgtype.OID type should only be used for scanning and encoding values
It was a mistake to use it in other contexts. This made interop
difficult between pacakges that depended on pgtype such as pgx and
packages that did not like pgconn and pgproto3. In particular this was
awkward for prepared statements.

This is preparation for removing pgx.PreparedStatement in favor of
pgconn.PreparedStatement.
2019-08-24 13:55:57 -05:00
Jack Christensen 7385349950 Refactor Conn.exec 2019-08-24 12:46:04 -05:00
Jack Christensen e22c023d8a Remove unused struct 2019-08-24 10:52:28 -05:00
Jack Christensen e9770d6ff9 Add listen / notify implemented with pgconn
fixes #553
2019-08-24 10:49:10 -05:00
Jack Christensen b7b52ff079 Require conn and pool configs to be created by ParseConfig
This simplifies handling default values. Now there is no ambiguity
between a zero value and a default value. All default values are set by
ParseConfig and the user can modify them after the initial creation.

fixes #567
2019-08-24 09:53:38 -05:00
Jack Christensen f3c703a102 Remove Conn SetLogger and SetLogLevel
Simplifying interface
2019-08-17 15:34:29 -05:00
Jack Christensen 99c54fbec0 Tweak Conn comment 2019-08-17 13:46:22 -05:00
Jack Christensen 3028821487 Add context.Context to Logger interface
This allows custom logger adapters to add additional fields to log
messages. For example, a HTTP server may with to log the request ID.

fixes #428
2019-08-03 16:16:21 -05:00
Jack Christensen ab1edc79e0 Remove 0 bytes when sanitizing identifiers
Port of 95ea78048a from v3.
2019-08-03 09:51:03 -05:00
Jack Christensen 29f02807b0 Restore simple protocol support 2019-05-20 20:36:03 -05:00
Jack Christensen b0dac84d77 Use extended query builder everywhere 2019-05-17 13:59:41 -05:00
Jack Christensen 79f49ce300 Convert large objects to prepared statements
This allows removing semi-obsolete fastpath interface support. See
https://www.postgresql.org/docs/current/libpq-fastpath.html. This also
simplifies introducing context support.
2019-05-11 11:36:38 -05:00
Jack Christensen 583c8d3b25 Use pgproto3.FieldDescription instead of pgx version
This allows removing a malloc and memcpy.
2019-05-04 13:47:18 -05:00
Jack Christensen ea31df3b50 Extract extendedQueryBuilder 2019-05-04 12:32:21 -05:00
Jack Christensen 8b365ce37e Extract int16SlicePool 2019-05-04 11:01:09 -05:00
Jack Christensen dd571cf345 Remove another malloc from query path 2019-05-04 09:01:57 -05:00
Jack Christensen db68713809 Remove malloc from query path 2019-05-04 08:58:02 -05:00
Jack Christensen 85ddbfeeee Remove 2 mallocs from query path 2019-05-04 08:55:05 -05:00