Commit Graph

316 Commits (c672c0d59595f729130088a5b8104600ff2a062a)

Author SHA1 Message Date
Jack Christensen 6cdb58fc71 Exec implemented in terms of ExecContext 2017-02-11 18:49:39 -06:00
Jack Christensen 9c74626d22 Ping implemented in terms of PingContext 2017-02-11 18:44:39 -06:00
Jack Christensen 8cc480fc48 Fix grammar 2017-02-11 18:44:27 -06:00
Jack Christensen e4f9108e82 wip 2017-02-11 14:59:16 -06:00
Jack Christensen f0dfe4fe89 Merge alive and busy states into atomic status 2017-02-11 13:01:51 -06:00
Jack Christensen 09d37880ba wip 2017-02-09 21:42:58 -06:00
Jack Christensen b8fdc38fa8 Only store Conn's *bufio.Reader in msgReader
Confusing and redundant to have the same *bufio.Reader in msgReader
and Conn.
2017-02-09 19:37:23 -06:00
Jack Christensen 72b6d32e2f Extracted more context handling 2017-02-07 21:49:58 -06:00
Jack Christensen 004c18e5a2 Begin extracting context handling 2017-02-07 20:35:37 -06:00
Jack Christensen 351eb8ba67 Initial proof-of-concept database/sql context support 2017-02-06 19:39:34 -06:00
Jack Christensen 14eedb4fca Add ConnPool context methods 2017-02-06 18:54:49 -06:00
Jack Christensen 37b86083e4 Fix race condition with canceled contexts 2017-02-04 18:44:55 -06:00
Jack Christensen 78adfb13d7 Add Ping, PingContext, and ExecContext 2017-02-04 14:20:00 -06:00
Jack Christensen 69434056c6 Remove Conn.TxStatus 2017-01-07 14:10:11 -06:00
Jack Christensen ec513248ac Conn.PID accessed through method 2017-01-07 13:37:36 -06:00
Jack Christensen f895e970b5 Merge branch 'master' into v3-experimental
* master:
  Tweak replication test setup
  Properly make it a func init()
  The naming really matters
  Fix the syntax
  Properly make the replication tests skippable on 9.5 and below
  I forgot the tests are 9.6+
  One more try for travis
  Valid YAML helps.
  Dont break old postgres
  Try to fix travis
  Add the ability to set all the fields in the constructor
  Start replication now wraps the sql and returns errors properly
  It should all be unsigned.
  Capitalization
  Add replication stop mechanism
  Add basic logical replication protocol support
2017-01-06 15:25:57 -06:00
Jack Christensen 93e5c68f69 Merge branch 'master' into v3-experimental 2016-12-10 12:21:08 -06:00
Kris Wehner 7bbb1c7307 Add basic logical replication protocol support 2016-12-04 21:35:22 -08:00
ferhat elmas 84439a13cb Simplify map composite literals as gofmt -s handles 2016-11-09 00:52:10 +01:00
Jack Christensen 3734a92a71 Log TLS connection errors as info when fallback available
fixes #198
2016-10-21 14:27:38 -05:00
Jack Christensen f7b6b3f077 Handle json/jsonb in binary to support CopyTo
fixes #189
2016-10-01 11:01:54 -05:00
Martin Hamrle 9f6b99e332 Cleanups
Cleanups suggested by gometalinter tools.
2016-08-30 20:05:44 +02:00
Jack Christensen 73124171e2 Rename Pid to PID 2016-08-02 15:10:00 -05:00
Jack Christensen 390f75c0e1 Reduce Logger interface to Log method 2016-08-02 14:42:31 -05:00
Jack Christensen 214443deb7 Rename Oid to OID 2016-08-02 13:31:55 -05:00
Jack Christensen 30cb421551 Add basic record to []interface{} decoding
refs #155
2016-06-21 15:00:47 -05:00
Jack Christensen 40f00f4a82 Pass PrepareEx opts as pointer and DRY implementation 2016-05-20 08:30:10 -05:00
Jack Christensen 7954a36b2d Tweak Prepare docs 2016-05-20 08:16:28 -05:00
Jack Christensen b06560aa03 Rename Preparex to PrepareEx 2016-05-20 08:14:56 -05:00
William King 2ba5bb405b Slight doc update 2016-05-18 13:27:22 -07:00
William King e417cc2f15 Preparex 2016-05-18 13:15:15 -07:00
Jack Christensen 90f22c1717 Don't share inet constant memory between connections 2016-05-12 08:00:53 -05:00
Jack Christensen a488fe026f Every Conn in a ConnPool gets its own PgTypes
Rather than sharing which could allow data races.
2016-05-12 07:51:53 -05:00
John Barker a282d9df90 Cache connection properties in the pool
This is a quick attempt to improve connection startup time by caching
the properties that are loaded when a connection is ready in the pool,
so that further connections don't incur this cost.

I'm not entirely convinced by the interface here, perhaps these 3 items
could live in their own type and that be passed around for clearer code,
but the idea works well.
2016-05-10 18:34:26 -04:00
John Barker 3ac09ce728 Reduce the set of types loaded on connect [Fixes #140]
Modify the pg_types query so that it does not load the table array types
that are created when new tables are created.
2016-05-10 14:10:51 -04:00
Jack Christensen 7323d3f5a7 Encode/decode [][]byte to/from bytea[]
fixes #139
2016-04-30 19:07:29 -05:00
Jack Christensen b596fa3455 Avoid allocation for WriteBuf on query 2016-04-30 13:32:19 -05:00
Jack Christensen e5ec5851e5 Reduce allocations for row objects 2016-04-30 12:22:36 -05:00
Jack Christensen 04e9fbcc55 Fix some golint errors
- Add comments
- Rename variables
- Remove unnecessary "else"
2016-03-29 15:18:09 -05:00
Jack Christensen 9ce1b2b16e Fix Listen/Unlisten with special characters
fixes #132
2016-03-24 15:26:44 -05:00
Jack Christensen c6b6d7bad7 Expose encoding and decoding functions 2016-02-15 13:57:11 -06:00
Jack Christensen 0f7bf19387 Add *Conn.SetLogLevel
Allow changing log level after connection is established. Because
log level and loggers can be set independently, it is now possible
to have a log level above none when there is a nil logger. This
means all log statements need to check for nil logger and an
appropriate log level. This check has been factored out into
*Conn.shouldLog.
2016-02-13 10:13:10 -06:00
Jack Christensen cffae7ff5d Add SetLogger to *Conn
Allow replacing logger after connection is established. Also
refactor internals of logging such that there is a log method that
adds the pid to all log calls instead of making a new logger object.
The reason for this is so pid will be logged regardless of whether
loggers are replaced and restored.
2016-02-12 17:49:04 -06:00
Jack Christensen 9f9a9779ac Add compatibility with database/sql custom types
Support database/sql.Scanner
Support database/sql/driver.Valuer
2015-12-31 14:46:43 -06:00
Jack Christensen f004f0802c Add ConnPool.Reset method
refs #110
2015-12-12 13:15:14 -06:00
Jack Christensen dd26ad0091 Remove unreachable code 2015-11-14 14:14:52 -06:00
Jack Christensen e1215d9b19 []byte skips encoding/decoding
refs #104
2015-11-12 14:54:25 -06:00
Jack Christensen 60cca3de7d Disable SSL renegotiation
fixes #103
2015-10-26 12:07:54 -05:00
Jack Christensen 8d9eb62609 Add docs for relating to ConnConfig.RuntimeParams 2015-10-16 16:16:39 -05:00
Jack Christensen ec8f6259e6 ParseEnvLibpq extracts PGAPPNAME 2015-10-16 16:13:15 -05:00
Jack Christensen 829d61ce40 ParseDSN extracts RuntimeParams 2015-10-16 15:48:24 -05:00
Jack Christensen 5b0550c1cb ParseURI extracts run-time parameters
refs #99
2015-10-16 15:37:49 -05:00
Jack Christensen 1fb63a4b41 Add RuntimeParams to ConnConfig 2015-10-16 15:37:32 -05:00
Jack Christensen 41b96b5f77 Fix stdlib error caused by idempotent Prepare 2015-10-16 14:58:03 -05:00
Jack Christensen 984eace2b5 Make *Conn.Prepare idempotent.
fixes #94
2015-10-16 14:17:07 -05:00
Jack Christensen and Jake Worth c726a51450 Add inet[] and cidr[] support 2015-09-29 13:23:26 -05:00
Jack Christensen 4987d5425e Fix JSON encoding of *string 2015-09-21 13:40:47 -05:00
Jack Christensen ca16a4c98f Unlisten tweaks
- Use unlisten * when releasing connection with listeners to pool
- Only unlisten on releasing connection to pool when necessary
- Remove Unlisten("") as was to release all listeners
2015-09-21 08:18:10 -05:00
Joseph Glanville eb5cadccf9 Track Listen/Unlisten and clear subscriptions on conn release 2015-09-21 07:56:45 -05:00
Jack Christensen 86837e5576 Add guards against usage of busy connection 2015-09-16 10:22:16 -05:00
Jack Christensen 23c48c2f87 Add trace logging 2015-09-16 08:40:01 -05:00
Jack Christensen a1aa06c934 More efficient logging with log levels 2015-09-16 08:20:51 -05:00
Jack Christensen a2e078597b Add logging to rxMsg
Also benchmark what a log call costs
2015-09-14 10:25:48 -05:00
Jack Christensen 6e5fa60c4c Fix cases where net conn write failure was not marking connection as dead
Also added loop to run these timing sensitive tests multiple times.
2015-09-12 19:32:55 -05:00
Jack Christensen 4ff46becfc Generalize pointer to string uuid transcoding to any non-varchar/text type 2015-09-09 18:07:05 -05:00
Joseph Glanville 2184ffb5e9 Add support for encoding to UUID from string types 2015-09-10 00:58:51 +10:00
Jonathan Rudenberg 272262536b Add support for pointers to pointers
Using types like **string allows the inner pointer to be nil’ed out,
avoiding the need for NullX types.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
2015-09-08 11:52:58 -05:00
Jack Christensen 4ebb0508b6 Encode dates in binary format
- Also allow NullTime to handle dates
2015-09-08 11:51:28 -05:00
Jack Christensen 9d200733b9 Merge common JSON and JSONB 2015-09-04 11:04:51 -05:00
Joseph Glanville 0013733535 Add JSON/JSONB support 2015-09-04 18:15:46 +10:00
Jack Christensen fd39261551 Use binary transcoding for inet/cidr
fixes #87
2015-09-03 11:39:32 -05:00
Jack Christensen 9af068add0 Add cidr support 2015-09-03 09:42:01 -05:00
Jack Christensen d494f83cd1 Add inet support 2015-09-03 09:33:19 -05:00
Jack Christensen a0c76b897c Fix doc typos 2015-08-21 13:50:31 -05:00
Jack Christensen c44cbb12ab Add sslmode note for ParseDSN 2015-08-21 13:50:06 -05:00
Rick Snyder 6413491657 Add support for specifying sslmode in connection strings
Add tests for sslmode parameter when calling ParseURI.  Fix existing tests to work since default sslmode is 'prefer'

Make sure we default to prefer if sslmode is not provided in ParseDSN

Fix existing tests for ParseDSN to expect TLS configuration for prefer since prefer is the default sslmode; also, add tests for ParseDSN when specifying sslmode parameter on connection string
2015-08-19 11:33:12 -04:00
Jack Christensen 07a11abc07 Add basic PGSSLMODE support to ParseEnvLibpq 2015-05-23 13:49:26 -05:00
Jack Christensen 51d6d1a3a6 Add ParseEnvLibpq with support for basic envvars 2015-05-23 12:46:36 -05:00
Jack Christensen dd9d960ba3 Add fallback TLS ConnConfig option
This is in preparation for supporting libpq style SSL options.
2015-05-23 11:57:36 -05:00
Jack Christensen 0c0a426d18 Add named error for server refused TLS 2015-05-15 19:21:59 -05:00
Jack Christensen 5bb7f64dac Add more error fields to PgError 2015-05-01 18:06:17 -05:00
Lewis Marshall 784d12cbbc Support using a custom dialer
For example I may want to use a dialer which retries transient network
errors (e.g. DNS issues).

Signed-off-by: Lewis Marshall <lewis@lmars.net>
2015-04-18 22:42:55 +01:00
deoxxa 7e2886c576 add ParseDSN function 2015-04-08 14:50:56 +10:00
Jack Christensen fc484ab5fd Allow NullTime to work with timestamp 2015-03-27 18:14:36 -04:00
Jack Christensen 28ef19702f Detect too many parameters on Prepare
refs #65
2015-03-14 18:58:09 -05:00
Jonathan Rudenberg 0176e3ccc0 Implement large object support
This patch implements large object support as described in
http://www.postgresql.org/docs/current/static/largeobjects.html
2015-01-01 22:01:01 -05:00
Jack Christensen d77e599ce6 Add timestamptz[] support 2014-12-23 18:17:39 -06:00
Karl Seguin 67292290cf support for inserting []time.Time into timestamp[] columns 2014-12-21 13:35:39 +07:00
Karl Seguin d1b42d1c8e support inserting into bool[] 2014-12-21 13:01:24 +07:00
Jack Christensen 79818c2557 Merge pull request #49 from karlseguin/mem1
reduce unecessary memory allocation
2014-11-17 20:36:57 -06:00
Karl Seguin a8f5ce12c5 Trying to reduce memory allocation. logQueryArgs is called even when
using the default discardLogger. This allocates quite a bit of memory.
Created a default dlogger instance and avoid logging code when that's our
logger. I couldn't think of a better implementation without touching the
Logger interface.

On 100 000 inserts, this brought the allocation down to 58MB from 122MB.
It should also result in some small performance gains.
2014-11-18 07:53:33 +07:00
Karl Seguin 04b54f03a5 Use LastIndex instead of Split for better performance getting the number of rows affected from CommandTag 2014-11-16 12:43:47 +07:00
Jack Christensen 5edd660971 WaitForNotification detects lost connections quicker
Ping server every 15 seconds while waiting if no traffic has occurred.
2014-10-03 14:58:04 -05:00
Jack Christensen 44f44c1baa Merge pull request #39 from anaxagoras/emptyquery
support EmptyQueryResponse message type
2014-09-27 14:37:13 -05:00
Jack Christensen 9e30e7aa93 Remove duplicate line 2014-09-27 12:20:36 -05:00
Jack Christensen 3d7974ce30 Always use keep-alive on TCP conns 2014-09-27 12:13:10 -05:00
Andy Walker f715715c86 add support for EmptyQueryResponse 2014-09-26 17:14:28 -04:00
Andy Walker 33fb73b8ab name consistency 2014-09-24 18:53:07 -04:00
Andy Walker b46ee0a951 Add keep-alive option by creating a dialer first, then setting KeepAlive option 2014-09-24 18:38:15 -04:00
Jack Christensen 98853ea98f more docs 2014-09-19 17:35:00 -05:00
Andy Walker 2f1ec582d7 Instead of native map[string]string, use type pgx.Hstore instead 2014-09-19 15:27:15 -05:00
Andy Walker 821605a8dd Adding hstore support. map[string]string will encode to hstores and throw errors on hstores with NULL values, and there is now a NullHstore type that is basically map[string]NullString and will both accept and decode NULL values properly 2014-09-19 15:27:15 -05:00
Jack Christensen 8f81acfb5f Enhance support for custom types
* Add per connection oid to name map
* Global default type format is now based on names not oids
* Add better docs for custom types
2014-09-19 15:27:15 -05:00
Brian Dunn and Jack Christensen a68115fc03 Fix data race with Rows and ConnPool
In an effort to reduce memory allocations, Rows was stored on the
Conn. This caused a race condition where Rows are closed and this
returns the Conn to the Pool. The Pool could then give out the Conn
again. Rows would then be reanimated and the original Rows could reclose
it.
2014-09-16 16:29:45 -05:00
Jack Christensen a5f082fa03 Extract more error information 2014-09-15 14:52:32 -05:00
Jack Christensen b21a653085 Truncate logged strings and byte slices 2014-09-15 13:53:59 -05:00
Jack Christensen f5156ac4eb discardLogger should be private 2014-09-04 16:45:35 -05:00
Jack Christensen ff905fe862 Finish compatible interface to inconshreveable/log15 2014-09-04 16:27:40 -05:00
Jack Christensen 98109c57bb Use interface for logging instead of log15 directly 2014-09-04 16:00:53 -05:00
Jack Christensen 311c332fdc More logging 2014-09-03 11:13:29 -05:00
Jack Christensen 0ddf94ef9d Add pgx.Oid serialization 2014-08-08 10:57:33 -05:00
Jack Christensen 2a04433355 Fix misleading error message 2014-08-08 10:31:47 -05:00
Jack Christensen fb55203324 Add support for varchar[] 2014-07-31 13:35:44 -05:00
Jack Christensen e29574d447 Add support for integer, float and text arrays
Restructure internals a bit so pgx/stdlib can turn off binary encoding and
receive text back for array types.
2014-07-26 15:03:52 -05:00
Jack Christensen 3144b5363f Support unknown PostgreSQL types as strings 2014-07-19 17:49:11 -05:00
Jack Christensen 61bf7d841a Always use bound parameters
PostgreSQL has two string syntaxes, one that allows backslash escapes and one
that does not (SQL standard conforming strings). By default PostgreSQL uses
standard conforming strings. QuoteString was only designed for use with
standard conforming strings. If PostgreSQL was configured with certain
combinations of the standard_conforming_strings and backslash_quote settings,
QuoteString may not correctly sanitize strings. QuoteString was only used in
unprepared queries, bound parameters are used for prepared queries.

This commit alters pgx to use always use bound parameters.

As a consequence of never doing string interpolation there is no need to have
separate Text and Binary encoders. There is now only the Encoder interface.

This change had a negative effect on the performance of simple unprepared
queries, but prepared statements should already be used for performance.

fixes #26

https://github.com/jackc/pgx/issues/26
2014-07-18 16:51:11 -05:00
Jack Christensen aff5043df9 Added a lot of documentation 2014-07-12 21:17:38 -05:00
Jack Christensen 4fbd76bee5 Make MsgReader private 2014-07-12 20:08:17 -05:00
Jack Christensen 1cb3ac91f3 EncodeBinary checks oid of param 2014-07-12 09:46:33 -05:00
Jack Christensen ed2b3b3b49 Add timestamp support
But not to NullTime because of text vs binary encoding difficulties.

You really should never use timestamp anyway.
2014-07-12 09:33:49 -05:00
Jack Christensen c108378973 Reorganize code 2014-07-12 08:50:30 -05:00
Jack Christensen 713a8f48a7 Failing to write to Conn.conn kills Conn 2014-07-12 08:04:09 -05:00
Jack Christensen ae6a87545b Use database/sql style transaction interface 2014-07-12 07:59:30 -05:00
Jack Christensen f31665c5db wip 2014-07-12 07:11:16 -05:00
Jack Christensen 19537badff Add Rows.Values 2014-07-11 16:55:45 -05:00
Jack Christensen 6c1c819a5e Error detection for mismatched types 2014-07-11 16:07:08 -05:00
Jack Christensen 4bdefced66 Add NullTime 2014-07-11 15:25:26 -05:00
Jack Christensen 7ca95d7f73 Add NullString
Changes EncodeText interface to work for null values in SQL interpolation
and in prepared statements text format.
2014-07-11 14:16:25 -05:00
Jack Christensen 24395d98df Add more testing of Encode*
Handle case where TextEncoder is used to a core type that the driver
could otherwise have handled as binary.
2014-07-11 11:16:12 -05:00
Jack Christensen 646136fb44 Rename *Rows.NextRow to *Rows.Next
Conform closer to database/sql
2014-07-11 08:26:01 -05:00
Jack Christensen d7529600e0 Rename QueryResult to Rows
This helps conform closer to database/sql
2014-07-11 08:21:29 -05:00
Jack Christensen 01f261c71c Conform closer to database/sql style and add no rows test 2014-07-11 08:16:21 -05:00
Jack Christensen 566d713285 More tests and bug fixes 2014-07-11 07:50:44 -05:00
Jack Christensen efeaf10a2a Make nextColumn private 2014-07-10 08:13:19 -05:00
Jack Christensen 7d97dca9b1 Remove unused function 2014-07-09 08:23:38 -05:00
Jack Christensen 6ae7f63d00 Remove UnexpectedColumnCountError 2014-07-09 08:18:09 -05:00
Jack Christensen 009cdfa0b1 Use Scan and Encode* instead of ValueTranscoders 2014-07-09 07:56:48 -05:00
Jack Christensen 43dcd47a92 Move to Scan interface
Remove SelectValue
2014-07-05 18:23:19 -05:00
Jack Christensen 5b345e80e1 Remove SelectValueTo
Benchmarks revealed that it is no longer performant enough to pull
its own wait. Using go_db_bench to copy JSON results to HTTP responses
it was ~20% *slower* for ~4BK responses and less than 10% faster for
+1MB responses.

The the performance problem was in io.CopyN / io.Copy. io.Copy
allocates a 32KB buffer if it doesn't have io.WriterTo or io.ReaderFrom
available. This extra alloc on every request was more expensive than
just reading the result into a string and writing it out to the response
body.

Tests indicated that if MsgReader implemented a custom Copy that used a
shared buffer it might have a few percent performance advantage. But the
additional complexity is not worth the performance gain.
2014-07-05 09:32:47 -05:00
Jack Christensen b27d828311 Add RowReader.CopyBytes
Implement SelectValueTo in terms of RowReader.CopyBytes
2014-07-05 07:51:32 -05:00
Jack Christensen 7083c51689 Finish migration to writeBuf 2014-07-04 13:34:27 -05:00
Jack Christensen 81cc33f1ed Use writeBuf more 2014-07-04 13:29:23 -05:00
Jack Christensen 9ab8fb4877 Partially migrate to writeBuf 2014-07-04 13:27:24 -05:00
Jack Christensen b25aea5c52 MsgReader no longer uses double buffering 2014-07-04 13:08:37 -05:00
Jack Christensen 78b8e0b6f2 Safely handle bad reads of QueryResult 2014-06-30 19:01:36 -05:00
Jack Christensen 718c4dfdc8 Add *RowReader.ReadInt64 2014-06-30 08:14:13 -05:00
Jack Christensen d30ef1b8b9 Replace SelectFunc with Query as core 2014-06-28 17:07:31 -05:00
Jack Christensen b6ac3ef2b0 Rename Execute to Exec 2014-06-27 14:56:27 -05:00
Jack Christensen aeb6cea1cf Replace binary.Read
It does memory allocs that can be avoided by passing a slice directly to
binary.BigEndian.*
2014-06-27 08:20:15 -05:00
Jack Christensen e8f367ede4 Use flyweight for DataRowReader 2014-06-27 08:00:32 -05:00