Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jackc committed Jun 22, 2019
1 parent 731f1ea commit d2440c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@

# pgconn

Package pgconn is a low-level PostgreSQL database driver.

It is intended to serve as the foundation for the next generation of https://github.com/jackc/pgx.
Package pgconn is a low-level PostgreSQL database driver. It operates at nearly the same level is 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

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

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

Expand Down
7 changes: 7 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ func NetworkAddress(host string, port uint16) (network, address string) {
// security guarantees than it would with libpq. Do not rely on this behavior as it
// may be possible to match libpq in the future. If you need full security use
// "verify-full".
//
// Other known differences with libpq:
//
// If a host name resolves into multiple addresses, libpq will try all addresses. pgconn will only try the first.
//
// When multiple hosts are specified, libpq allows them to have different passwords set via the .pgpass file. pgconn
// does not.
func ParseConfig(connString string) (*Config, error) {
settings := defaultSettings()
addEnvSettings(settings)
Expand Down
2 changes: 1 addition & 1 deletion pgconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (pgConn *PgConn) hardClose() error {
return pgConn.conn.Close()
}

// TODO - rethink how to report status. At the moment this is just a temporary measure so pgx.Conn can detect deatch of
// TODO - rethink how to report status. At the moment this is just a temporary measure so pgx.Conn can detect death of
// underlying connection.
func (pgConn *PgConn) IsAlive() bool {
return pgConn.status >= connStatusIdle
Expand Down

0 comments on commit d2440c7

Please sign in to comment.