diff --git a/example_json_test.go b/example_json_test.go index 513cc90b..631430b8 100644 --- a/example_json_test.go +++ b/example_json_test.go @@ -12,7 +12,7 @@ func Example_JSON() { return } - if _, ok := conn.PgTypes[pgx.JsonOID]; !ok { + if _, ok := conn.PgTypes[pgx.JSONOID]; !ok { // No JSON type -- must be running against very old PostgreSQL // Pretend it works fmt.Println("John", 42) diff --git a/query.go b/query.go index abe9860e..34035794 100644 --- a/query.go +++ b/query.go @@ -298,7 +298,7 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) { if err != nil { rows.Fatal(scanArgError{col: i, err: err}) } - } else if vr.Type().DataType == JsonOID || vr.Type().DataType == JsonbOID { + } else if vr.Type().DataType == JSONOID || vr.Type().DataType == JSONBOID { // Because the argument passed to decodeJSON will escape the heap. // This allows d to be stack allocated and only copied to the heap when // we actually are decoding JSON. This saves one memory allocation per @@ -387,11 +387,11 @@ func (rows *Rows) Values() ([]interface{}, error) { values = append(values, decodeTimestamp(vr)) case InetOID, CidrOID: values = append(values, decodeInet(vr)) - case JsonOID: + case JSONOID: var d interface{} decodeJSON(vr, &d) values = append(values, d) - case JsonbOID: + case JSONBOID: var d interface{} decodeJSON(vr, &d) values = append(values, d) diff --git a/v3.md b/v3.md index fdf8dcac..5bb7162a 100644 --- a/v3.md +++ b/v3.md @@ -1,3 +1,5 @@ # V3 Changes Rename Oid to OID in accordance with Go conventions. + +Rename Json(b) to JSON(B) in accordance with Go conventions. diff --git a/values.go b/values.go index e49721ff..4fecbf74 100644 --- a/values.go +++ b/values.go @@ -22,7 +22,7 @@ const ( Int4OID = 23 TextOID = 25 OIDOID = 26 - JsonOID = 114 + JSONOID = 114 CidrOID = 650 CidrArrayOID = 651 Float4OID = 700 @@ -47,7 +47,7 @@ const ( TimestampTzArrayOID = 1185 RecordOID = 2249 UuidOID = 2950 - JsonbOID = 3802 + JSONBOID = 3802 ) // PostgreSQL format codes @@ -627,7 +627,7 @@ func Encode(wbuf *WriteBuf, oid OID, arg interface{}) error { } } - if oid == JsonOID || oid == JsonbOID { + if oid == JSONOID || oid == JSONBOID { return encodeJSON(wbuf, oid, arg) } @@ -1463,7 +1463,7 @@ func decodeJSON(vr *ValueReader, d interface{}) error { return nil } - if vr.Type().DataType != JsonOID && vr.Type().DataType != JsonbOID { + if vr.Type().DataType != JSONOID && vr.Type().DataType != JSONBOID { vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into json", vr.Type().DataType))) } @@ -1476,7 +1476,7 @@ func decodeJSON(vr *ValueReader, d interface{}) error { } func encodeJSON(w *WriteBuf, oid OID, value interface{}) error { - if oid != JsonOID && oid != JsonbOID { + if oid != JSONOID && oid != JSONBOID { return fmt.Errorf("cannot encode JSON into oid %v", oid) } diff --git a/values_test.go b/values_test.go index 9d7d1700..2ef9c774 100644 --- a/values_test.go +++ b/values_test.go @@ -78,30 +78,30 @@ func TestTimestampTzTranscode(t *testing.T) { } } -func TestJsonAndJsonbTranscode(t *testing.T) { +func TestJSONAndJSONBTranscode(t *testing.T) { t.Parallel() conn := mustConnect(t, *defaultConnConfig) defer closeConn(t, conn) - for _, oid := range []pgx.OID{pgx.JsonOID, pgx.JsonbOID} { + for _, oid := range []pgx.OID{pgx.JSONOID, pgx.JSONBOID} { if _, ok := conn.PgTypes[oid]; !ok { return // No JSON/JSONB type -- must be running against old PostgreSQL } typename := conn.PgTypes[oid].Name - testJsonString(t, conn, typename) - testJsonStringPointer(t, conn, typename) - testJsonSingleLevelStringMap(t, conn, typename) - testJsonNestedMap(t, conn, typename) - testJsonStringArray(t, conn, typename) - testJsonInt64Array(t, conn, typename) - testJsonInt16ArrayFailureDueToOverflow(t, conn, typename) - testJsonStruct(t, conn, typename) + testJSONString(t, conn, typename) + testJSONStringPointer(t, conn, typename) + testJSONSingleLevelStringMap(t, conn, typename) + testJSONNestedMap(t, conn, typename) + testJSONStringArray(t, conn, typename) + testJSONInt64Array(t, conn, typename) + testJSONInt16ArrayFailureDueToOverflow(t, conn, typename) + testJSONStruct(t, conn, typename) } } -func testJsonString(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONString(t *testing.T, conn *pgx.Conn, typename string) { input := `{"key": "value"}` expectedOutput := map[string]string{"key": "value"} var output map[string]string @@ -117,7 +117,7 @@ func testJsonString(t *testing.T, conn *pgx.Conn, typename string) { } } -func testJsonStringPointer(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONStringPointer(t *testing.T, conn *pgx.Conn, typename string) { input := `{"key": "value"}` expectedOutput := map[string]string{"key": "value"} var output map[string]string @@ -133,7 +133,7 @@ func testJsonStringPointer(t *testing.T, conn *pgx.Conn, typename string) { } } -func testJsonSingleLevelStringMap(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONSingleLevelStringMap(t *testing.T, conn *pgx.Conn, typename string) { input := map[string]string{"key": "value"} var output map[string]string err := conn.QueryRow("select $1::"+typename, input).Scan(&output) @@ -148,7 +148,7 @@ func testJsonSingleLevelStringMap(t *testing.T, conn *pgx.Conn, typename string) } } -func testJsonNestedMap(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONNestedMap(t *testing.T, conn *pgx.Conn, typename string) { input := map[string]interface{}{ "name": "Uncanny", "stats": map[string]interface{}{"hp": float64(107), "maxhp": float64(150)}, @@ -167,7 +167,7 @@ func testJsonNestedMap(t *testing.T, conn *pgx.Conn, typename string) { } } -func testJsonStringArray(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONStringArray(t *testing.T, conn *pgx.Conn, typename string) { input := []string{"foo", "bar", "baz"} var output []string err := conn.QueryRow("select $1::"+typename, input).Scan(&output) @@ -180,7 +180,7 @@ func testJsonStringArray(t *testing.T, conn *pgx.Conn, typename string) { } } -func testJsonInt64Array(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONInt64Array(t *testing.T, conn *pgx.Conn, typename string) { input := []int64{1, 2, 234432} var output []int64 err := conn.QueryRow("select $1::"+typename, input).Scan(&output) @@ -193,7 +193,7 @@ func testJsonInt64Array(t *testing.T, conn *pgx.Conn, typename string) { } } -func testJsonInt16ArrayFailureDueToOverflow(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONInt16ArrayFailureDueToOverflow(t *testing.T, conn *pgx.Conn, typename string) { input := []int{1, 2, 234432} var output []int16 err := conn.QueryRow("select $1::"+typename, input).Scan(&output) @@ -202,7 +202,7 @@ func testJsonInt16ArrayFailureDueToOverflow(t *testing.T, conn *pgx.Conn, typena } } -func testJsonStruct(t *testing.T, conn *pgx.Conn, typename string) { +func testJSONStruct(t *testing.T, conn *pgx.Conn, typename string) { type person struct { Name string `json:"name"` Age int `json:"age"`