More readme tweaks and proofreading

pgx-vs-pq
Jack Christensen 2013-07-30 18:06:26 -05:00
parent ff9cab7471
commit 91e841bddd
1 changed files with 20 additions and 18 deletions

View File

@ -65,8 +65,8 @@ ensure all connections have the same prepared statements available or to
change any other connection settings. change any other connection settings.
It also delegates Select* and Execute functions to an automatically checked It also delegates Select* and Execute functions to an automatically checked
out and released connection so you can have as much or as little control of out and released connection so you can avoid manually acquiring and releasing
the connection pool as you need.. connections when you do not need that level of control.
```go ```go
if widgets, err := pool.SelectRows("select * from widgets where type=$1", type); err != nil { if widgets, err := pool.SelectRows("select * from widgets where type=$1", type); err != nil {
@ -105,31 +105,33 @@ if notification, err := conn.WaitForNotification(time.Second); err != nil {
Pgx includes transcoders for the common data types like integers, floats, Pgx includes transcoders for the common data types like integers, floats,
strings, dates, and times that have direct mappings between Go and SQL. strings, dates, and times that have direct mappings between Go and SQL.
Transcoders can be added for additional types like point, hstore, numeric, Transcoders can be added for additional types like point, hstore, numeric,
etc. that do not have direct mappings in Go. Pgx has a map of PostgreSQL OID's etc. that do not have direct mappings in Go. pgx.ValueTranscoders is a map of
to transcoders. All that is needed to add or change how a data type is to set PostgreSQL OID's to transcoders. All that is needed to add or change how a
that OID's transcoder. See example_value_transcoder_test.go for an example of data type is to set that OID's transcoder. See
a custom transcoder for the PostgreSQL point type. example_value_transcoder_test.go for an example of a custom transcoder for the
PostgreSQL point type.
### SelectValueTo ### SelectValueTo
There are some cases where go is used as an HTTP server that is directly There are some cases where Go is used as an HTTP server that is directly
relaying single values from PostgreSQL (such as JSON r binary blobs). relaying single values from PostgreSQL (such as JSON or binary blobs).
SelectValueTo copies the single returned value directly from PostgreSQL to a SelectValueTo copies the single returned value directly from PostgreSQL to a
io.Writer. This can be faster especially when the values are at least many KB io.Writer. This can be faster than SelectValue then write especially when the
in size. values are at least many KB in size.
### Null Mapping ### Null Mapping
As pgx uses interface{} for all values SQL nulls are mapped to nil. This As pgx uses interface{} for all values SQL nulls are mapped to nil. This
eliminates the need for wrapping values in structs that include a boolean for eliminates the need for wrapping values in structs that include a boolean for
the null possibility. On the downside, this does present difficulties dealing the null possibility. On the other hand, returned values usually must be type
with complex types such as arrays. pgx directly maps a Go []int32 to a asserted before use. It also presents difficulties dealing with complex types
PostgreSQL int4[]. The problem is the PostgreSQL array can include nulls, but such as arrays. pgx directly maps a Go []int32 to a PostgreSQL int4[]. The
the Go slice cannot. Because of this array transcoding should be considered problem is the PostgreSQL array can include nulls, but the Go slice cannot.
experimental. On the plus side, because of the pluggable transcoder support, Array transcoding should be considered experimental. On the plus side, because
an application that wished to handle arrays (or any types) differently can of the pluggable transcoder support, an application that wished to handle
easily override the default transcoding (so even using a strict with value and arrays (or any types) differently can easily override the default transcoding
null fields would simply be a matter of changing transcoders). (so even using a strict with value and null fields would simply be a matter of
changing transcoders).
## Testing ## Testing