• Stars
    star
    168
  • Rank 217,617 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created about 5 years ago
  • Updated 8 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CI


This version is used with pgx v4. In pgx v5 it is part of the https://github.com/jackc/pgx repository.


pgconn

Package pgconn is a low-level PostgreSQL database driver. It operates at nearly the same level as the C library libpq. It is primarily intended to serve as the foundation for higher level libraries such as https://github.com/jackc/pgx. Applications should handle normal queries with a higher level library and only use pgconn directly when required for low-level access to PostgreSQL functionality.

Example Usage

pgConn, err := pgconn.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
	log.Fatalln("pgconn failed to connect:", err)
}
defer pgConn.Close(context.Background())

result := pgConn.ExecParams(context.Background(), "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
for result.NextRow() {
	fmt.Println("User 123 has email:", string(result.Values()[0]))
}
_, err = result.Close()
if err != nil {
	log.Fatalln("failed reading result:", err)
}

Testing

The pgconn tests require a PostgreSQL database. It will connect to the database specified in the PGX_TEST_CONN_STRING environment variable. The PGX_TEST_CONN_STRING environment variable can be a URL or DSN. In addition, the standard PG* environment variables will be respected. Consider using direnv to simplify environment variable handling.

Example Test Environment

Connect to your PostgreSQL server and run:

create database pgx_test;

Now you can run the tests:

PGX_TEST_CONN_STRING="host=/var/run/postgresql dbname=pgx_test" go test ./...

Connection and Authentication Tests

Pgconn supports multiple connection types and means of authentication. These tests are optional. They will only run if the appropriate environment variable is set. Run go test -v | grep SKIP to see if any tests are being skipped. Most developers will not need to enable these tests. See ci/setup_test.bash for an example set up if you need change authentication code.

More Repositories

1

pgx

PostgreSQL driver and toolkit for Go
Go
8,422
star
2

tern

The SQL Fan's Migrator
Go
656
star
3

tod

Time of day and shift types for Ruby
Ruby
415
star
4

surus

PostgreSQL extensions for ActiveRecord
Ruby
395
star
5

sqlfmt

SQL Formatter
Yacc
335
star
6

pgtype

Go
295
star
7

pglogrepl

PostgreSQL logical replication library for Go.
Go
277
star
8

puddle

Generic resource pool for Go
Go
232
star
9

pgproto3

Go
151
star
10

pgerrcode

Package pgerrcode contains constants for PostgreSQL error codes.
Go
130
star
11

pgmock

Go
111
star
12

edge

Edge provides graph functionality to ActiveRecord.
Ruby
89
star
13

mat-view-strat-pg

Materialized View Strategies Using PostgreSQL
PLpgSQL
59
star
14

go_db_bench

Benchmarks for database/drivers from Go
Go
52
star
15

json_api_bench

Benchmark of Rails and PostgreSQL JSON generation techniques
Ruby
32
star
16

tpr

The Pithy Reader - a fast, simple, and lightweight feed aggregator and reader
Go
22
star
17

pgxlisten

pgxlisten provides higher level PostgreSQL LISTEN / NOTIFY tooling built on pgx.
Go
18
star
18

pg-custom-aggregate-grt

PostgreSQL custom aggregate greatest running total implemented in PL/pgSQL and C
PLpgSQL
17
star
19

pgxutil

Go
16
star
20

react2fs

Run command in reaction to file system events
Go
15
star
21

chunkreader

Go
14
star
22

overload

HTTP load tester
Go
14
star
23

pgxrecord

pgxrecord is a tiny framework for CRUD operations and data mapping.
Go
14
star
24

pgxjob

pgxjob provides a job queue implementation using PostgreSQL.
Go
13
star
25

pgx-top-to-bottom

HTML
13
star
26

pgio

Package pgio is a low-level toolkit building messages in the PostgreSQL wire protocol.
Go
12
star
27

command_model

CommandModel - when update_attributes isn't enough.
Ruby
12
star
28

pgx-zerolog

Go
10
star
29

writable-cte-examples

Examples of Writable Common Table Expressions in PostgreSQL
Ruby
9
star
30

pgxdata

Go
9
star
31

pgtocsv

pgtocsv executes a query on a PostgreSQL database and outputs the results in CSV.
Go
9
star
32

numfmt

Number formatting in Go
Go
9
star
33

pgservicefile

pgservicefile is a parser PostgreSQL for service files (e.g. .pg_service.conf)
Go
8
star
34

pgsql

Go
8
star
35

go_map_vs_switch

Benchmark for Go map of functions vs. switch
Go
7
star
36

pgx-shopspring-decimal

Go
7
star
37

pg-extid

Go
7
star
38

booklog

Go
7
star
39

go-extid

Go
7
star
40

pgundolog

pgundolog is a system for rolling back changes to a PostgreSQL database without using transactions.
PLpgSQL
7
star
41

pgx-zap

Go
6
star
42

pgx-gofrs-uuid

Go
6
star
43

hannibal

Experimental PostgreSQL web application server
Go
5
star
44

cavein

TCP tunnel that designed for testing applications with random connection losses
Go
5
star
45

quo_vadis

Really simple and fast HTTP Router
Go
5
star
46

pgxrepl

Replication client library for PostgreSQL in Go using the pgx driver
Go
5
star
47

text_tunnel

Use your local text editor to edit files on remote servers.
Ruby
5
star
48

pgpassfile

Go
4
star
49

doublecheck

Doublecheck your database before it is too late
Go
4
star
50

csvtopg

csvtopg copies a CSV to a PostgreSQL database.
Go
4
star
51

chicagolang-feb-2015

Slides for Building Command Line Applications in Go
Go
4
star
52

go_router_tutorial

Tutorial to build a simple HTTP router in Go
Go
4
star
53

why-pgx

Slides for lightning talk on pgx
4
star
54

gel

Go Compiled Templates
Go
3
star
55

ego

Experimental shorthand for Go error handling.
Go
3
star
56

pgx_notify_lost_connection

Test for PGX WaitForNotification when connection is lost
Go
3
star
57

pigeon-exp-xmlpp

Experimenting with pigeon PEG generator for Go
Go
3
star
58

doublecheck_view

Ruby gem for integrating doublecheck view pattern with database integration tests
Ruby
3
star
59

cachet

The cache for all your Ts
Go
2
star
60

pgxsql

Go
2
star
61

flex

Go
2
star
62

cgol-rust

Quick, experimental port of Go cgol to Rust
Rust
2
star
63

dailyprogrammer

Go
2
star
64

sadpath

sadpath provides a simple way to centralize error handling and reduce boilerplate.
Go
2
star
65

imperator

Imperator is an imperative normalization and validation library for Go.
Go
2
star
66

pg95-whats-new

What's new in PostgreSQL 9.5
PLpgSQL
2
star
67

go-intro

Quick introduction to Go -- sample project and speaker notes
Go
2
star
68

pgxbench

PLSQL
2
star
69

react2fs-deb

react2fs Debian package
Go
2
star
70

ppg

ppg runs a SQL file multiple times in parallel
Go
2
star
71

box

Go
2
star
72

tern-deb

Build scripts for debian package for tern
Go
2
star
73

sqlfmt-deb

sqlfmt Debian package
Go
2
star
74

ctxio

Go
2
star
75

jchat

Go
2
star
76

exp-go-repl

Experimenting with yacc
Go
2
star
77

webby-template-minimal-website

Minimal possible website template for Webby
2
star
78

mp

mp (map parser) provides a parser that parses maps into types defined at runtime.
Go
2
star
79

go-hello

Go program to practice packaging
Go
2
star
80

form

HTTP forms for Go
Go
2
star
81

tpr-deb

The Pithy Reader Debian Package
Go
2
star
82

go-server-closed-tcp-conn-os-inconsistencies

Example of differing server closed TCP connections on Linux and Windows
2
star
83

assert_db_rejects

Test database level constraints with ActiveRecord
Ruby
2
star
84

pgx_issues

Test and example cases for pgx issues
Go
1
star
85

context-rows-cancel

Test of Go database/sql context cancelation
Go
1
star
86

pgx845

This is a test application for https://github.com/jackc/pgx/issues/845.
Go
1
star
87

homebrew-formulas

Jack Christensen's Formulas
Ruby
1
star
88

markovbot

Go
1
star
89

reggie

Regular expression builder and tester for Ruby
Ruby
1
star
90

snake_case

Go
1
star
91

cbc-sinatra-crash

Test app demonstrating a crash
Ruby
1
star
92

hackers-delight

Hacker's Delight Exercises and Experiments
Go
1
star
93

pg_pl_bench

Go
1
star
94

booklogh

Experimental port of Booklog to Hannibal
PLpgSQL
1
star
95

alt_record

An alternative implementation of the active record pattern for Ruby
Ruby
1
star
96

structify

Go
1
star
97

form_model

Ruby
1
star
98

testdb

Test database manager
Go
1
star
99

go_database_sql_retry_bug

Test application to determine if database/sql auto-retry logic is safe
Go
1
star
100

go-tls-deadline-temporary-error

Go
1
star