2
0

Add JSON/JSONB support

This commit is contained in:
Joseph Glanville
2015-09-04 05:51:57 +10:00
parent fee3679cb9
commit 0013733535
4 changed files with 85 additions and 1 deletions
+40
View File
@@ -65,6 +65,46 @@ func TestTimestampTzTranscode(t *testing.T) {
}
}
func TestJsonTranscode(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn)
m := map[string]string{
"key": "value",
}
var outputJson map[string]string
err := conn.QueryRow("select $1::json", m).Scan(&outputJson)
if err != nil {
t.Fatalf("QueryRow Scan failed: %v", err)
}
if m["key"] != outputJson["key"] {
t.Errorf("Did not transcode json successfully: %v is not %v", outputJson["key"], m["key"])
}
}
func TestJsonbTranscode(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn)
m := map[string]string{
"key": "value",
}
var outputJson map[string]string
err := conn.QueryRow("select $1::jsonb", m).Scan(&outputJson)
if err != nil {
t.Fatalf("QueryRow Scan failed: %v", err)
}
if m["key"] != outputJson["key"] {
t.Errorf("Did not transcode jsonb successfully: %v is not %v", outputJson["key"], m["key"])
}
}
func mustParseCIDR(t *testing.T, s string) net.IPNet {
_, ipnet, err := net.ParseCIDR(s)
if err != nil {