PostgreSQL driver and toolkit for Go
 
 
 
Go to file
Laurent Debacker bc7ca55b45 Fix decoding of ARRAY[]::text[]
The original version could not decode ARRAY[]::text[]. When an empty array was detected, decode1dArrayHeader was not reading enough values off the socket, and subsequent values were incorrectly read.
2015-04-08 16:53:08 -05:00
examples Add example of listen/notify support 2014-11-01 10:45:18 -05:00
stdlib Add stdlib test for []byte 2014-10-03 14:52:33 -05:00
.gitignore Rename ConnectionParameters to ConnConfig 2014-05-17 13:38:13 -05:00
.travis.yml Enable travis errors on PG 9.0 and 9.1 2015-02-13 13:43:39 -06:00
CHANGELOG.md Update changelog 2014-12-23 18:19:22 -06:00
LICENSE Add license 2013-07-30 19:05:09 -05:00
README.md Update README with more advantages of pgx 2015-04-02 19:53:40 -05:00
bench_test.go Move to Scan interface 2014-07-05 18:23:19 -05:00
conn.go add ParseDSN function 2015-04-08 14:50:56 +10:00
conn_config_test.go.example Add TLS to conn_config_test.go.example 2014-07-29 17:41:53 -05:00
conn_config_test.go.travis Add Travis CI configuration 2015-01-31 14:29:50 -08:00
conn_pool.go ConnPool no longer creates connections just to release them. 2014-11-12 08:11:33 -06:00
conn_pool_test.go select; is valid in 9.4. This causes the two tests to exec successfully when 2014-11-17 21:21:08 +07:00
conn_test.go add tests for ParseDSN 2015-04-08 14:55:15 +10:00
doc.go Add hstore to docs 2014-09-19 17:38:35 -05:00
example_custom_type_test.go Enhance support for custom types 2014-09-19 15:27:15 -05:00
fastpath.go Implement large object support 2015-01-01 22:01:01 -05:00
helper_test.go Add support for integer, float and text arrays 2014-07-26 15:03:52 -05:00
hstore.go document ParseHstore 2014-09-22 13:22:15 -04:00
hstore_test.go Add tests for NullHstore 2014-09-19 17:34:02 -05:00
large_objects.go Minor docs fixes for large objects 2015-01-02 17:05:51 -05:00
large_objects_test.go Implement large object support 2015-01-01 22:01:01 -05:00
logger.go Trying to reduce memory allocation. logQueryArgs is called even when 2014-11-18 07:53:33 +07:00
messages.go add support for EmptyQueryResponse 2014-09-26 17:14:28 -04:00
msg_reader.go combine two small reads into one 2015-01-11 16:47:31 -08:00
query.go Tweak handling of reading null as raw bytes. 2014-12-23 21:58:48 -06:00
query_test.go Test should not use type that does not exist in PG 9.0 2015-02-13 13:42:18 -06:00
sql.go Add QueryArgs 2014-05-21 08:17:24 -05:00
sql_test.go Update github.com/JackC to github.com/jackc 2014-06-21 08:36:20 -05:00
tx.go Tx.QueryRow implemented in terms of Tx.Query 2014-07-14 07:55:20 -05:00
tx_test.go Use database/sql style transaction interface 2014-07-12 07:59:30 -05:00
value_reader.go Tweak handling of reading null as raw bytes. 2014-12-23 21:58:48 -06:00
values.go Fix decoding of ARRAY[]::text[] 2015-04-08 16:53:08 -05:00
values_test.go Add test for empty array between other values 2015-04-08 14:50:57 -05:00

README.md

Pgx

Pgx is a a pure Go database connection library designed specifically for PostgreSQL. Pgx is different from other drivers such as pq because, while it can operate as a database/sql compatible driver, pgx is primarily intended to be used directly. It offers a native interface similar to database/sql that offers better performance and more features.

Features

Pgx supports many additional features beyond what is available through database/sql.

  • Listen / notify
  • Transaction isolation level control
  • Full TLS connection control
  • Binary format support for custom types (can be much faster)
  • Logging support
  • Configurable connection pool with after connect hooks to do arbitrary connection setup
  • PostgreSQL array to Go slice mapping for integers, floats, and strings
  • Hstore support
  • Large object support

Performance

Pgx performs roughly equivalent to pq and go-pg for selecting a single column from a single row, but it is substantially faster when selecting multiple entire rows (6893 queries/sec for pgx vs. 3968 queries/sec for pq -- 73% faster).

See this gist for the underlying benchmark results or checkout go_db_bench to run tests for yourself.

database/sql

Import the github.com/jackc/pgx/stdlib package to use pgx as a driver for database/sql. It is possible to retrieve a pgx connection from database/sql on demand. This allows using the database/sql interface in most places, but using pgx directly when more performance or PostgreSQL specific features are needed.

Documentation

pgx includes extensive documentation in the godoc format. It is viewable online at godoc.org.

Testing

pgx supports multiple connection and authentication types. Setting up a test environment that can test all of them can be cumbersome. In particular, Windows cannot test Unix domain socket connections. Because of this pgx will skip tests for connection types that are not configured.

Normal Test Environment

To setup the normal test environment run the following SQL:

create user pgx_md5 password 'secret';
create database pgx_test;

Connect to database pgx_test and run:

create extension hstore;

Next open connection_settings_test.go.example and make a copy without the .example. If your PostgreSQL server is accepting connections on 127.0.0.1, then you are done.

Connection and Authentication Test Environment

Complete the normal test environment setup and also do the following.

Run the following SQL:

create user pgx_none;
create user pgx_pw password 'secret';

Add the following to your pg_hba.conf:

If you are developing on Unix with domain socket connections:

local  pgx_test  pgx_none  trust
local  pgx_test  pgx_pw    password
local  pgx_test  pgx_md5   md5

If you are developing on Windows with TCP connections:

host  pgx_test  pgx_none  127.0.0.1/32 trust
host  pgx_test  pgx_pw    127.0.0.1/32 password
host  pgx_test  pgx_md5   127.0.0.1/32 md5

Version Policy

pgx follows semantic versioning for the documented public API. master branch tracks the latest stable branch (v2). Consider using import "gopkg.in/jackc/pgx.v2" to lock to the v2 branch or use a vendoring tool such as godep.