mirror of https://github.com/jackc/pgx.git
Add docs and example for JSON
parent
fff5b9759b
commit
5ea6b04624
|
@ -1,3 +1,7 @@
|
||||||
|
# Master
|
||||||
|
|
||||||
|
* Add JSON and JSONB type support (Joseph Glanville)
|
||||||
|
|
||||||
# 2.6.0 (September 3, 2015)
|
# 2.6.0 (September 3, 2015)
|
||||||
|
|
||||||
* Add inet and cidr type support
|
* Add inet and cidr type support
|
||||||
|
|
|
@ -19,6 +19,7 @@ Pgx supports many additional features beyond what is available through database/
|
||||||
* Configurable connection pool with after connect hooks to do arbitrary connection setup
|
* Configurable connection pool with after connect hooks to do arbitrary connection setup
|
||||||
* PostgreSQL array to Go slice mapping for integers, floats, and strings
|
* PostgreSQL array to Go slice mapping for integers, floats, and strings
|
||||||
* Hstore support
|
* Hstore support
|
||||||
|
* JSON and JSONB support
|
||||||
* Maps inet and cidr PostgreSQL types to net.IPNet
|
* Maps inet and cidr PostgreSQL types to net.IPNet
|
||||||
* Large object support
|
* Large object support
|
||||||
|
|
||||||
|
|
5
doc.go
5
doc.go
|
@ -137,6 +137,11 @@ pgx includes an Hstore type and a NullHstore type. Hstore is simply a
|
||||||
map[string]string and is preferred when the hstore contains no nulls. NullHstore
|
map[string]string and is preferred when the hstore contains no nulls. NullHstore
|
||||||
follows the Null* pattern and supports null values.
|
follows the Null* pattern and supports null values.
|
||||||
|
|
||||||
|
JSON and JSONB Mapping
|
||||||
|
|
||||||
|
pgx includes built-in support to marshal and unmarshal between Go types and
|
||||||
|
the PostgreSQL JSON and JSONB.
|
||||||
|
|
||||||
Custom Type Support
|
Custom Type Support
|
||||||
|
|
||||||
pgx includes support for the common data types like integers, floats, strings,
|
pgx includes support for the common data types like integers, floats, strings,
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package pgx_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/jackc/pgx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Example_JSON() {
|
||||||
|
conn, err := pgx.Connect(*defaultConnConfig)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Unable to establish connection: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type person struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Age int `json:"age"`
|
||||||
|
}
|
||||||
|
|
||||||
|
input := person{
|
||||||
|
Name: "John",
|
||||||
|
Age: 42,
|
||||||
|
}
|
||||||
|
|
||||||
|
var output person
|
||||||
|
|
||||||
|
err = conn.QueryRow("select $1::json", input).Scan(&output)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(output.Name, output.Age)
|
||||||
|
// Output:
|
||||||
|
// John 42
|
||||||
|
}
|
Loading…
Reference in New Issue