2
0

Add docs and example for JSON

This commit is contained in:
Jack Christensen
2015-09-04 14:00:21 -05:00
parent fff5b9759b
commit 5ea6b04624
4 changed files with 46 additions and 0 deletions
+36
View File
@@ -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
}