66 Commits

Author SHA1 Message Date
Jack Christensen
fd2093cef8 Add statement type convenience methods to CommandTag and optimize
Added convenient way to check whether a statement was a select, insert,
update, or delete. These methods do not allocate.

RowsAffected now does not allocate even when a large number of rows are
affected. It also is multiple times faster, though the absolute change
is inconsequential.
2020-01-11 18:42:31 -06:00
Jack Christensen
98b3c57584 Try to cancel any in-progress query when a conn is closed by ctx cancel
See https://github.com/jackc/pgx/issues/659
2020-01-08 10:03:54 -06:00
Jack Christensen
bd0ce203e9 CopyFrom not table test was failing with syntax error 2019-12-21 10:31:27 -06:00
Jack Christensen
32350bd1dc TestConnectCustomLookup must test with TCP connection
Test (correctly) fails if run on a Unix domain socket.
2019-11-18 07:29:57 -06:00
Artemiy Ryabinkov
17d3d592e9
add test for custom lookup func
Signed-off-by: Artemiy Ryabinkov <getlag@ya.ru>
2019-09-14 19:11:26 +03:00
Jack Christensen
2f6b8f3f56 Fix context timeout on connect 2019-08-31 17:01:54 -05:00
Jack Christensen
138254da5b Refactor errors
- Use strongly typed errors internally
- SafeToRetry(error) streamlines retry logic over ErrNoBytesSent
- Timeout(error) removes the need to choose between returning a context
  and an i/o error
2019-08-27 18:05:50 -05:00
Jack Christensen
6feea0c1c5 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.

fixes #2
2019-08-24 23:43:26 -05:00
Jack Christensen
760dd75542 Require Config to be created by ParseConfig 2019-08-24 09:28:44 -05:00
Jack Christensen
d364370a31 Add SendBytes and ReceiveMessage 2019-08-20 14:12:07 -05:00
Jack Christensen
f0b479097a Fix missing deferred constraint violations in certain conditions
See https://github.com/jackc/pgx/issues/570.
2019-08-06 17:07:11 -05:00
Jack Christensen
3dec184811 Split ValidateConnect from AfterConnect
This avoids the foot-gun of ParseConfig setting AfterConnect because of
target_session_attrs and the user inadvertently overriding it with an
AfterConnect designed to setup the connection.

Now target_session_attrs will be handled with ValidateConnect.
2019-07-13 10:22:09 -05:00
Jack Christensen
59941377c8 Rename Config.AfterConnectFunc to AfterConnect
No need to include the type in the name.
2019-07-13 09:52:22 -05:00
Artemiy Ryabinkov
529805557f
Fix linters notifications
Signed-off-by: Artemiy Ryabinkov <getlag@ya.ru>
2019-06-22 10:41:01 +03:00
Jack Christensen
a97dd2f9f6 Update test envvar and docs 2019-06-01 09:59:04 -05:00
Jack Christensen
1e3961bd0e Fix flickering test 2019-04-24 16:49:52 -05:00
Jack Christensen
7e0022ef6b Tag errors if no bytes sent to server 2019-04-20 16:48:24 -05:00
Jack Christensen
0f8e1d30e2 Link context errors and underlying conn errors
Using golang.org/x/xerrors type errors both errors can be exposed.
2019-04-20 15:53:30 -05:00
Jack Christensen
f3b5f6b275 Allow skipping TestConnExecBatchHuge in short mode 2019-04-20 15:34:49 -05:00
Jack Christensen
39e6ff5766 Prevent deadlock with huge batches 2019-04-20 11:11:09 -05:00
Jack Christensen
9f774761ba Fix TestConnLocking 2019-04-20 10:59:50 -05:00
Jack Christensen
7bb6c2f3e9 Unify locked and closed into status
No longer panic on locking busy conn
2019-04-19 15:52:12 -05:00
Jack Christensen
2383561e4d Use 0-alloc pgproto3/v2 2019-04-18 23:17:28 -05:00
Jack Christensen
b6e5b74e2c Reuse one MultiResultReader per connection
Using a PgConn while locked now panics. i.e. You must Close any
ResultReader or MultiResultReader.
2019-04-18 22:50:36 -05:00
Jack Christensen
244e114435 Add SCRAM authentication 2019-04-16 20:41:38 -05:00
Jack Christensen
7ad3625edd unlock connection when context is pre-canceled 2019-04-05 12:06:59 -05:00
Jack Christensen
408837dcb1 Handle extended protocol with too many arguments 2019-04-05 11:47:31 -05:00
Jack Christensen
c745509c59 Rename test 2019-04-05 11:27:04 -05:00
Jack Christensen
3d9e42d74c Replace chan based conn locking with bool
This is conceptually simpler and will lead to error messages instead of
deadlocks.
2019-03-30 17:09:39 -05:00
Jack Christensen
444bd6deaf Context cancellation is fatal during query 2019-03-30 16:44:20 -05:00
Jack Christensen
fbdfccf1f9 Use Go modules 2019-03-30 12:55:56 -05:00
Jack Christensen
79ffab9836 All writes errors are fatal 2019-01-28 23:13:03 -06:00
Jack Christensen
96c85cf0c3 Recover from context cancellation during CopyFrom 2019-01-26 12:20:36 -06:00
Jack Christensen
3683e4a0a1 Move CopyFrom to pgconn 2019-01-19 17:24:48 -06:00
Jack Christensen
c9f985c1e4 Add PgConn.EscapeString 2019-01-19 15:44:03 -06:00
Jack Christensen
c447ff4e79 Use NoError instead of Nil for assertions 2019-01-19 14:51:07 -06:00
Jack Christensen
19ef57ad9a Add PgConn.CopyTo 2019-01-19 14:49:39 -06:00
Jack Christensen
edfd837ba4 Add PgConn.WaitForNotification 2019-01-14 20:51:53 -06:00
Jack Christensen
cd4b0025c3 Add listen/notify to pgconn 2019-01-14 20:39:10 -06:00
Jack Christensen
9c36fa1e50 Fix prepare failure 2019-01-12 16:16:47 -06:00
Jack Christensen
bd777fe20c Add custom context cancellation hook 2019-01-12 11:37:13 -06:00
Jack Christensen
c6a73a469a Add example 2019-01-05 18:47:50 -06:00
Jack Christensen
2959411c41 CommandTag is string 2019-01-05 18:06:25 -06:00
Jack Christensen
2c8971b382 Rename some types and methods 2019-01-05 18:01:57 -06:00
Jack Christensen
cddf011806 Big restructure to better handle context cancel 2019-01-05 17:37:28 -06:00
Jack Christensen
b213299a92 Add ensureReadyForQuery to pgconn 2019-01-02 13:59:00 -06:00
Jack Christensen
460946d662 Move notice handling to pgconn 2019-01-02 13:15:26 -06:00
Jack Christensen
6d2fa9c5cf Handle empty query response 2019-01-02 12:28:11 -06:00
Jack Christensen
d545e0704e Prepare returns description 2019-01-01 18:03:20 -06:00
Jack Christensen
7986e2726d pgx uses pgconn.CommandTag instead of own definition 2019-01-01 16:55:48 -06:00