• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H25-Mar-2021-8272

ci/H25-Mar-2021-7160

internal/ctxwatch/H25-Mar-2021-216166

stmtcache/H25-Mar-2021-476342

.gitignoreH A D25-Mar-202123 43

CHANGELOG.mdH A D25-Mar-20213.1 KiB11067

LICENSEH A D25-Mar-20211.1 KiB2318

README.mdH A D25-Mar-20212.1 KiB5742

auth_scram.goH A D25-Mar-20217.4 KiB267201

benchmark_test.goH A D25-Mar-20217.4 KiB323257

config.goH A D25-Mar-202121.8 KiB718512

config_test.goH A D25-Mar-202124 KiB871808

defaults.goH A D25-Mar-20211.3 KiB5233

defaults_windows.goH A D25-Mar-20211.4 KiB4729

doc.goH A D25-Mar-20211.2 KiB301

errors.goH A D25-Mar-20214.3 KiB194156

errors_test.goH A D25-Mar-20211.7 KiB5551

export_test.goH A D25-Mar-2021230 128

frontend_test.goH A D25-Mar-20211.6 KiB7149

go.modH A D25-Mar-2021441 1613

go.sumH A D25-Mar-202112.9 KiB137136

helper_test.goH A D25-Mar-20211,012 3729

pgconn.goH A D25-Mar-202150.1 KiB1,7121,242

pgconn_stress_test.goH A D25-Mar-20212.5 KiB9173

pgconn_test.goH A D25-Mar-202156.3 KiB2,0101,538

README.md

1[![](https://godoc.org/github.com/jackc/pgconn?status.svg)](https://godoc.org/github.com/jackc/pgconn)
2![CI](https://github.com/jackc/pgconn/workflows/CI/badge.svg)
3
4# pgconn
5
6Package pgconn is a low-level PostgreSQL database driver. It operates at nearly the same level as the C library libpq.
7It is primarily intended to serve as the foundation for higher level libraries such as https://github.com/jackc/pgx.
8Applications should handle normal queries with a higher level library and only use pgconn directly when required for
9low-level access to PostgreSQL functionality.
10
11## Example Usage
12
13```go
14pgConn, err := pgconn.Connect(context.Background(), os.Getenv("DATABASE_URL"))
15if err != nil {
16	log.Fatalln("pgconn failed to connect:", err)
17}
18defer pgConn.Close(context.Background())
19
20result := pgConn.ExecParams(context.Background(), "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
21for result.NextRow() {
22	fmt.Println("User 123 has email:", string(result.Values()[0]))
23}
24_, err = result.Close()
25if err != nil {
26	log.Fatalln("failed reading result:", err)
27}
28```
29
30## Testing
31
32The pgconn tests require a PostgreSQL database. It will connect to the database specified in the `PGX_TEST_CONN_STRING`
33environment variable. The `PGX_TEST_CONN_STRING` environment variable can be a URL or DSN. In addition, the standard `PG*`
34environment variables will be respected. Consider using [direnv](https://github.com/direnv/direnv) to simplify
35environment variable handling.
36
37### Example Test Environment
38
39Connect to your PostgreSQL server and run:
40
41```
42create database pgx_test;
43```
44
45Now you can run the tests:
46
47```bash
48PGX_TEST_CONN_STRING="host=/var/run/postgresql dbname=pgx_test" go test ./...
49```
50
51### Connection and Authentication Tests
52
53Pgconn supports multiple connection types and means of authentication. These tests are optional. They
54will only run if the appropriate environment variable is set. Run `go test -v | grep SKIP` to see if any tests are being
55skipped. Most developers will not need to enable these tests. See `ci/setup_test.bash` for an example set up if you need change
56authentication code.
57