<commit_before># pgx

PostgreSQL client library for Go

## Description

Pgx is a database connection library designed specifically for PostgreSQL.
There are features of PostgreSQL that are difficult or impossible to use with
the standard Go library SQL interface. This library trades conformity with the
standard interface for ease of use and the power that is available when
working directly with PostgreSQL.

## Features

Below are some of the standout features of pgx.

### Simple Query Interface

Pgx has easy to use functions for common query operations like SelectValue,
SelectValues, SelectRow, and SelectRows. These can be easier to use than the
standard Scan interface. These directly return interface{}, []interface{},
map[string]interface{}, and []map[string]interface{} respectively. SelectFunc
offers custom row by row processing.

```go
if widgets, err := conn.SelectRows("select name, weight from widgets where type=$1", type); err != nil {
    for w := range widgets {
        fmt.Printf("%v has a weight of %v.", widgets["name"], widgets["weight"])
    }
}
```

### Prepared Statements

Prepared statements are easy to use in pgx. Just call Prepare with the name of
the statement and the SQL. To execute a prepared statement just pass the name
of the statement into a Select* or Execute command as the SQL text. It will
automatically detect that it is the name of a prepared statement and execute
it.

```go
if err := conn.Prepare("getTime", "select now()"); err == nil {
    // handle err
}
if time, err := conn.SelectValue("getTime"); err != nil {
    // do something with time
}
```

Prepared statements will use the binary transmission format for types that
have a binary transcoder available (this can substantially reduce overhead
when using the bytea type).

### Explicit Connection Pool

Connection pool usage is explicit and configurable. The standard Go SQL
interface automatically uses a connection pool, and does not provide a way to
control the maximum number of connections (hopefully soon to change --
https://code.google.com/p/go/issues/detail?id=4805). In pgx, a connection can
be created and managed directly, or a connection pool with a configurable
maximum connections can be used. Also, the connection pool offers an after
connect hook that allows every connection to be automatically setup before
being made available in the connection pool. This is especially useful to
ensure all connections have the same prepared statements available or to
change any other connection settings.

It also delegates Select* and Execute functions to an automatically checked
out and released connection so you can avoid manually acquiring and releasing
connections when you do not need that level of control.

```go
if widgets, err := pool.SelectRows("select * from widgets where type=$1", type); err != nil {
    // do something with widgets
}
```

### Transactions

Transactions are are used by passing a function to the Transaction function.
This function ensures that the transaction is committed or rolled back
automatically. The TransactionIso variant creates a transaction with a
specified isolation level.

```go
committed, err := conn.TransactionIso("serializable", func() bool {
    // do something with transaction
    return true // return true to commit / false to rollback<commit_msg>Update README.md for Go 1.2<commit_after># pgx

PostgreSQL client library for Go

## Description

Pgx is a database connection library designed specifically for PostgreSQL.
There are features of PostgreSQL that are difficult or impossible to use with
the standard Go library SQL interface. This library trades conformity with the
standard interface for ease of use and the power that is available when
working directly with PostgreSQL.

## Features

Below are some of the standout features of pgx.

### Simple Query Interface

Pgx has easy to use functions for common query operations like SelectValue,
SelectValues, SelectRow, and SelectRows. These can be easier to use than the
standard Scan interface. These directly return interface{}, []interface{},
map[string]interface{}, and []map[string]interface{} respectively. SelectFunc
offers custom row by row processing.

```go
if widgets, err := conn.SelectRows("select name, weight from widgets where type=$1", type); err != nil {
    for w := range widgets {
        fmt.Printf("%v has a weight of %v.", widgets["name"], widgets["weight"])
    }
}
```

### Prepared Statements

Prepared statements are easy to use in pgx. Just call Prepare with the name of
the statement and the SQL. To execute a prepared statement just pass the name
of the statement into a Select* or Execute command as the SQL text. It will
automatically detect that it is the name of a prepared statement and execute
it.

```go
if err := conn.Prepare("getTime", "select now()"); err == nil {
    // handle err
}
if time, err := conn.SelectValue("getTime"); err != nil {
    // do something with time
}
```

Prepared statements will use the binary transmission format for types that
have a binary transcoder available (this can substantially reduce overhead
when using the bytea type).

### Explicit Connection Pool

Connection pool usage is explicit and configurable. In pgx, a connection can
be created and managed directly, or a connection pool with a configurable
maximum connections can be used. Also, the connection pool offers an after
connect hook that allows every connection to be automatically setup before
being made available in the connection pool. This is especially useful to
ensure all connections have the same prepared statements available or to
change any other connection settings.

It also delegates Select* and Execute functions to an automatically checked
out and released connection so you can avoid manually acquiring and releasing
connections when you do not need that level of control.

```go
if widgets, err := pool.SelectRows("select * from widgets where type=$1", type); err != nil {
    // do something with widgets
}
```

### Transactions

Transactions are are used by passing a function to the Transaction function.
This function ensures that the transaction is committed or rolled back
automatically. The TransactionIso variant creates a transaction with a
specified isolation level.

```go
committed, err := conn.TransactionIso("serializable", func() bool {
    // do something with transaction
    return true // return true to commit / false to rollback
{'fraction_non_alphanumeric': 0.06481193658688218, 'fraction_numerical': 0.001554243083618278, 'mean_word_length': 4.5141388174807195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3885620', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1518, 'n_words': 891}