Jonathan Amsterdam
88ede6efb5
stdlib: implement Conn.ResetSession
...
This prevents closed connections from being returned
by `database.sql.DB.Conn`.
Fixes #974 .
2021-03-26 10:25:07 -05:00
Jack Christensen
a49f4bb135
Use errors instead of golang.org/x/xerrors
2021-03-25 09:55:12 -04:00
Jack Christensen
495d482f20
Fix PG version extraction in tests
2021-03-13 07:55:53 -06:00
Jack Christensen
00704ce8b7
Skip test on too old PostgreSQL
2021-03-13 07:18:26 -06:00
Jack Christensen
e93da6c744
Fix ignored deferred error with database/sql QueryRow
...
fixes #958
2021-03-13 06:52:58 -06:00
Jack Christensen
09371f21d0
Use JSON format compat with PG and CockroachDB
2021-02-27 10:28:45 -06:00
Jack Christensen
fea4bc4318
Use bigint in tests for compat. with CockroachDB
2021-02-27 10:26:14 -06:00
Jack Christensen
fb60d0780e
Skip unsupported testing functionality on CockroachDB
2021-02-27 10:25:45 -06:00
Jack Christensen
82bac82213
stdlib: consider any Ping failure as fatal
...
refs #672
2020-12-03 19:41:03 -06:00
Jack Christensen
4ebf1d2e0b
Passthrough all parameters directly to pgx
2020-07-18 08:44:57 -05:00
Jack Christensen
c8a9da960c
Revert "stdlib: close connection on Tx commit or rollback that doesn't end Tx"
...
This reverts commit 2583134306
.
This fix should actually be on the main Tx implementation.
2020-07-13 22:48:28 -05:00
Jack Christensen
2583134306
stdlib: close connection on Tx commit or rollback that doesn't end Tx
...
refs #787
2020-07-13 22:40:42 -05:00
zikaeroh
84510c4590
Cache column names in stdlib Rows
2020-06-29 10:20:13 -07:00
Jack Christensen
bf47a3d0a4
Fix stdlib decoding error with certain order and combination of fields
...
fixes #781
2020-06-29 09:38:53 -05:00
Jack Christensen
4e50623069
Fix stdlib number size conversions
2020-06-06 09:54:19 -05:00
Jack Christensen
81140f6c27
Improve stdlib performance with large results
2020-06-06 09:49:14 -05:00
Jack Christensen
0e04d8187e
Add raw benchmark
2020-06-01 08:53:45 -05:00
Jack Christensen
8dee3382f7
Improve unknown type support for database/sql
...
- Return unknown type OID instead of empty string for type name.
- ScanType is string instead of empty interface for unknown types.
fixes #759
2020-05-30 13:27:25 -05:00
Jack Christensen
837704dc7d
Update stdlib docs to point to Conn.Raw instead of AcquireConn
2020-05-30 13:27:25 -05:00
Jack Christensen
2bd26ec7fa
Expose stdlib.Conn.Conn() to enable database/sql.Conn.Raw()
2020-05-30 13:27:25 -05:00
Jack Christensen
64789acf46
Merge pull request #734 from georgysavva/stdlib-timeouts
...
Improve Stdlib context timeouts
2020-05-13 07:45:18 -05:00
Jack Christensen
a66b09fbd8
Improve simple protocol / text format
...
Increased data type support for simple protocol. Improved test
coverage of simple protocol. This has the additional advantage of
exercising the text encoders and decoders.
2020-05-08 16:20:15 -05:00
Jack Christensen
c3381c6911
Replace t.Fatal with require where possible
2020-05-08 12:47:47 -05:00
Jack Christensen
ec53234e86
Rename ensureConnValid to ensureDBValid
2020-05-08 12:26:24 -05:00
Jack Christensen
c44cda4bb4
Clean up old Go 1.10 build tags
...
pgx requires Go modules which requires at least Go 1.11 so there is no
use in build tags to support older Go versions.
2020-05-08 12:18:09 -05:00
Jack Christensen
c03ac1519e
Improve stdlib performance with large result sets
...
In a hot path type assertions are expensive. Cache the already correctly
typed interfaces. ~20% improvement with 1000 rows.
Before:
jack@glados ~/dev/pgx/stdlib ±master » PGX_BENCH_SELECT_ROWS_COUNTS='1 10 1000' got ./... -bench=SelectRows -benchmem
goos: darwin
goarch: amd64
pkg: github.com/jackc/pgx/v4/stdlib
BenchmarkSelectRowsScanSimple/1_rows-16 21465 55060 ns/op 1679 B/op 40 allocs/op
BenchmarkSelectRowsScanSimple/10_rows-16 16692 71176 ns/op 3827 B/op 148 allocs/op
BenchmarkSelectRowsScanSimple/1000_rows-16 800 1369547 ns/op 248855 B/op 12938 allocs/op
BenchmarkSelectRowsScanNull/1_rows-16 20306 57883 ns/op 1940 B/op 54 allocs/op
BenchmarkSelectRowsScanNull/10_rows-16 15942 74729 ns/op 4294 B/op 171 allocs/op
BenchmarkSelectRowsScanNull/1000_rows-16 829 1326788 ns/op 261291 B/op 13051 allocs/op
PASS
ok github.com/jackc/pgx/v4/stdlib 10.429s
After:
jack@glados ~/dev/pgx/stdlib ±master⚡ » PGX_BENCH_SELECT_ROWS_COUNTS='1 10 1000' got ./... -bench=SelectRows -benchmem
goos: darwin
goarch: amd64
pkg: github.com/jackc/pgx/v4/stdlib
BenchmarkSelectRowsScanSimple/1_rows-16 21327 55097 ns/op 2127 B/op 43 allocs/op
BenchmarkSelectRowsScanSimple/10_rows-16 16724 69496 ns/op 4276 B/op 151 allocs/op
BenchmarkSelectRowsScanSimple/1000_rows-16 1009 1124573 ns/op 250037 B/op 12941 allocs/op
BenchmarkSelectRowsScanNull/1_rows-16 20577 58117 ns/op 2396 B/op 57 allocs/op
BenchmarkSelectRowsScanNull/10_rows-16 16402 72533 ns/op 4750 B/op 174 allocs/op
BenchmarkSelectRowsScanNull/1000_rows-16 1010 1161437 ns/op 261735 B/op 13054 allocs/op
PASS
ok github.com/jackc/pgx/v4/stdlib 10.363s
2020-05-08 00:06:42 -05:00
Jack Christensen
dea915e605
Compare binary and text format through pgx
...
Make ID field bigger -- otherwise all ints are less than 4 digits and
get a bit too much of an advantage in text vs. binary
2020-05-07 22:28:46 -05:00
Jack Christensen
e439372d2a
Add multi-row select benchmarks
2020-05-07 22:28:46 -05:00
georgysavva
e27a6e71b5
Wrap stdlib Conn.Close() and Stmt.Close() with default 5 seconds timeout.
2020-05-02 16:57:39 +03:00
georgysavva
7738775417
Include context into stdlib.wrapTx{} in order to propagate it to the underlying pgx.Tx.Commit() and Rollback() methods.
2020-04-02 15:30:55 +03:00
Bas van Beek
e75d315079
bail early if preloading rows.Next() results in rows.Err()
2020-03-17 19:50:23 +01:00
Jack Christensen
77c1076d39
stdlib.ReleaseConn closes connections left in invalid state
...
If a connection is in a transaction or has an open result set then
close the connection when returning it to database/sql. When next
database/sql attempts to use it the connection will return
driver.ErrBadConn and database/sql will remove it from the pool.
fixes #673
2020-02-01 12:00:26 -06:00
Alex Gaynor
efbbde0487
Fixes #664 -- implement DriverContext for stdlib
2020-01-23 14:19:40 -06:00
Johan Brandhorst
d75362f396
Add back GetDefaultDriver
...
This method is useful when it is necessary
to wrap the pgx stdlib driver, for example to
add tracing and metrics.
Fixes #645
2019-12-07 10:19:51 +00:00
Jack Christensen
69e9c33daf
Add RegisterConnConfig to stdlib
...
This restored functionality lost in the v3 to v4 transition when
RegisterDriverConfig was removed.
fixes #617
2019-11-16 11:06:57 -06:00
Jack Christensen
76348773bd
Make Conn.ConnInfo private
2019-09-10 18:09:21 -05:00
Jack Christensen
04a0609876
Remove unused pgmock code
2019-08-31 13:13:45 -05:00
Jack Christensen
28d5375b74
Update stdlib for latest pgconn
2019-08-27 18:29:27 -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
b2b949afa4
Rename BeginEx to BeginTx and update docs
2019-08-24 20:50:24 -05:00
Jack Christensen
3675337e5b
Update for rename of pgconn.PreparedStatementDescription
2019-08-24 20:44:56 -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
99e5461522
Add pgx.Tx interface and pseudo nested transaction support
...
This complicates the idea of a persistent transaction status and error
so that concept was removed.
2019-08-17 17:22:14 -05:00
Jack Christensen
c3e41872a8
Resplit Begin and BeginEx
...
This is in preparation for a Begin / Tx interface that will similate
nested transactions with savepoints.
In addition, this passes the TxOptions struct by value and thereby
removes an allocation.
2019-08-17 15:53:55 -05:00
Jonathan Yoder
0c07df20b2
Clarify stdlib.AcquireConn Comment
2019-08-15 08:41:13 -05:00
Jack Christensen
5eae85194e
Bring stdlib iso change from v3
2019-08-08 15:35:30 -05:00
Jack Christensen
a99cd7758a
stdlib AfterConnect takes context
2019-06-29 13:53:43 -05:00
Jack Christensen
0830aae884
Remove unnecessary internal function
2019-05-20 21:03:39 -05:00
Jack Christensen
98f3e64bec
Use envvars for stdlib tests
2019-05-20 20:39:45 -05:00
Jack Christensen
29f02807b0
Restore simple protocol support
2019-05-20 20:36:03 -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
243f9031b3
Remove extra prepare in stdlib
2019-04-27 15:45:30 -05:00
Jack Christensen
2263521f70
Only have a single Begin transaction method
2019-04-24 13:35:27 -05:00
Jack Christensen
1b8f0016e9
Split pgtype into own repo
2019-04-20 19:20:00 -05:00
Jack Christensen
efb333df6b
Fix go modules
...
Wow. This is fun. Sure is easy to get modules wrong when upgrading a v2+
project.
2019-04-20 17:41:08 -05:00
Jack Christensen
b7e56b003a
Replace lastStmtSent with pgconn support
2019-04-20 17:12:20 -05:00
Jack Christensen
66625e6489
Prepare takes context
...
Also remove PrepareEx. It's primary usage was for context. Supplying
parameter OIDs is unnecessary when you can type cast in the query SQL.
If it does become necessary or desirable to add options back it can be
added in a backwards compatible way by adding a varargs as last
argument.
2019-04-20 11:47:16 -05:00
Jack Christensen
95756b1d7f
Deallocate takes context
2019-04-20 11:34:52 -05:00
Jack Christensen
2a55a4048a
Add QueryResultFormats option
2019-04-13 14:06:48 -05:00
Jack Christensen
36461eff94
Remove unused method
2019-04-13 12:07:41 -05:00
Jack Christensen
c53c9e6eb5
Remove simple protocol and one round trip query options
...
It is impossible to guarantee that the a query executed with the simple
protocol will behave the same as with the extended protocol. This is
because the normal pgx path relies on knowing the OID of query
parameters. Without this encoding a value can only be determined by the
value instead of the combination of value and PostgreSQL type. For
example, how should a []int32 be encoded? It might be encoded into a
PostgreSQL int4[] or json.
Removal also simplifies the core query path.
The primary reason for the simple protocol is for servers like PgBouncer
that may not be able to support normal prepared statements. After
further research it appears that issuing a "flush" instead "sync" after
preparing the unnamed statement would allow PgBouncer to work.
The one round trip mode can be better handled with prepared statements.
As a last resort, all original server functionality can still be accessed by
dropping down to PgConn.
2019-04-13 11:39:01 -05:00
Jack Christensen
b638d52a4f
Dirty hack to get a few more stdlib tests to pass
2019-04-12 21:42:50 -05:00
Jack Christensen
b77f901168
Inital pass at converting stdlib
...
Multiple tests still failing
2019-04-12 16:57:42 -05:00
Jack Christensen
858d00788a
Use extracted packages with Go modules
2019-04-05 10:59:47 -05:00
James Hartig
6d336eccb1
Added LastStmtSent and use it to retry on errors if statement was not sent
...
Previously, a failed connection could be put back in a pool and when the
next query was attempted it would fail immediately trying to prepare the
query or reset the deadline. It wasn't clear if the Query or Exec call
could safely be retried since there was no way to know where it failed.
You can now call LastQuerySent and if it returns false then you're
guaranteed that the last call to Query(Ex)/Exec(Ex) didn't get far enough
to attempt to send the query. The call can be retried with a new
connection.
This is used in the stdlib to return a ErrBadConn if a network error
occurred and the statement was not attempted.
Fixes #427
2018-11-19 10:44:40 -05:00
Greg Curtis
8b8e883961
stdlib: fix race with Driver.configs in Open
...
The Driver.configs map is protected by configMutex in
registerDriverConfig and unregisterDriverConfig, but not in Open. This
results in a race if Open is called while another goroutine is
registering/unregistering a DriverConfig.
2018-11-10 00:28:05 -08:00
Jack Christensen
897e90f353
Type modifier should be int32 not uint32
2018-09-22 07:43:18 -05:00
Valery Krivchikov
c844a2402b
Call context.WithTimeout cancel function
2018-09-15 13:23:09 +03:00
Jack Christensen
0a483bad9d
Merge branch 'implement-opendb' of https://github.com/james-lawrence/pgx into james-lawrence-implement-opendb
2018-07-14 09:57:49 -05:00
Jack Christensen
1fbd6977e1
Use json instead of jsonb for PG 9.3 compat.
2018-04-14 10:02:08 -05:00
Jack Christensen
8e9b095ce0
Merge pull request #410 from jbowens/acquireconn
...
stdlib: allow nested database/sql/driver.Drivers
2018-04-14 10:33:26 -04:00
Jack Christensen
5297846239
pgtype.JSON(B).Value now returns []byte
...
Allows scanning jsonb column into *json.RawMessage.
fixes #409
2018-04-14 09:17:56 -05:00
Jackson Owens
14f1f2aa01
stdlib: allow nested database/sql/driver.Drivers
...
database/sql/driver.Driver implementations can be nested, with each
layer adding additional functionality. If pgx/stdlib.Driver is wrapped
in another driver.Driver implementation, AcquireConn will error,
detecting that the *sql.DB's driver is not (directly) pgx.Driver.
It looks like it should be possible to support the current functionality
without requiring that the top-level Driver be pgx/stdlib.Driver, but
it requires using a global map of fakeTxConns instead of a per-Driver
map of fakeTxConns.
Is this reasonable?
2018-04-11 19:31:33 -07:00
James Lawrence
19a9154d23
implement driver.Connector
2018-04-08 11:12:15 -04:00
Jack Christensen
3707b79782
Add prefer simple protocol support to stdlib
...
Test code partially taken from james-lawrence
(7471e7f9eb
)
2018-01-13 13:46:20 -06:00
ferhat elmas
763deea17e
Run gofmt with simplify flag
2017-12-21 23:45:26 +01:00
Nick Jones
e86386c8d2
Fix docs in stdlib.
2017-12-07 16:28:54 +11:00
Jack Christensen
546a1e8ecf
Document parameter notation in stdlib docs
...
refs #351
2017-11-17 09:37:57 -06:00
Timothée Peignier
0f84f73c7b
Add more ColumnType support
2017-08-18 18:22:08 -07:00
Jack Christensen
a147e0f3b8
Fix test on Travis
2017-07-22 08:41:13 -05:00
Jack Christensen
8f4178b3d3
Use github.com/pkg/errors
2017-06-04 21:30:03 -05:00
Jack Christensen
8712627257
Use Go casing convention for CID/TID/XID/CIDR
2017-06-03 12:01:49 -05:00
Jack Christensen
27ab289096
Use Go casing convention for OID
2017-06-03 11:53:49 -05:00
Jack Christensen
dfe250c13b
Allow either error message
2017-06-02 08:38:27 -05:00
Jack Christensen
07c5b76a24
Allow for either of 2 possible errors from tx context cancelation
2017-05-29 11:39:06 -05:00
Jack Christensen
21d2ed0934
Add mock close
2017-05-22 08:51:23 -05:00
Jack Christensen
8a7165dd98
Add ctx to PrepareEx
...
Remove PrepareExContext
2017-05-20 18:03:59 -05:00
Jack Christensen
d1fd222ca5
Add transaction context support
2017-05-20 17:58:19 -05:00
Jack Christensen
2a27fb1817
Remove accidentally committed mock db open
2017-05-20 08:30:47 -05:00
Jack Christensen
e5820baebe
Add driver.StmtQueryContext support to stdlib.Stmt
2017-05-19 17:31:56 -05:00
Jack Christensen
7f226539a0
Add driver.StmtExecContext support to stdlib.Stmt
2017-05-19 16:18:54 -05:00
Jack Christensen
f9cb22e4b8
Add driver.RowsColumnTypeDatabaseTypeName support to stdlib.Rows
2017-05-19 16:05:30 -05:00
Jack Christensen
5ee76a26c8
Add tests for stdlib.Conn.QueryContext
2017-05-19 15:54:55 -05:00
Jack Christensen
4f31904904
Remove spurious Println
2017-05-19 15:52:18 -05:00
Jack Christensen
dbcfa46d8e
Add driver.ExecerContext support to stdlib.Conn
2017-05-19 14:57:49 -05:00
Jack Christensen
f8d7602270
Add driver.ConnPrepareContext support to stdlib.Conn
2017-05-19 14:31:01 -05:00
Jack Christensen
936cb68866
Add driver.Pinger support to stdlib.Conn
2017-05-19 08:54:08 -05:00
Jack Christensen
479ebdfa19
Add basic pgmock support
...
Primarily useful for testing pgx itself. Design is still subject to change.
2017-05-13 17:56:54 -05:00