mirror of https://github.com/jackc/pgx.git
parent
17f8f7af63
commit
279c3c0a20
|
@ -1,6 +1,7 @@
|
||||||
package pgtype
|
package pgtype
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -82,6 +83,13 @@ func (JSONCodec) PlanScan(m *Map, oid uint32, format int16, target any) ScanPlan
|
||||||
return scanPlanJSONToByteSlice{}
|
return scanPlanJSONToByteSlice{}
|
||||||
case BytesScanner:
|
case BytesScanner:
|
||||||
return scanPlanBinaryBytesToBytesScanner{}
|
return scanPlanBinaryBytesToBytesScanner{}
|
||||||
|
|
||||||
|
// Cannot rely on sql.Scanner being handled later because scanPlanJSONToJSONUnmarshal will take precedence.
|
||||||
|
//
|
||||||
|
// https://github.com/jackc/pgx/issues/1418
|
||||||
|
case sql.Scanner:
|
||||||
|
return &scanPlanSQLScanner{formatCode: format}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return scanPlanJSONToJSONUnmarshal{}
|
return scanPlanJSONToJSONUnmarshal{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package pgtype_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
pgx "github.com/jackc/pgx/v5"
|
pgx "github.com/jackc/pgx/v5"
|
||||||
|
@ -48,6 +49,9 @@ func TestJSONCodec(t *testing.T) {
|
||||||
{map[string]any(nil), new([]byte), isExpectedEqBytes([]byte(nil))},
|
{map[string]any(nil), new([]byte), isExpectedEqBytes([]byte(nil))},
|
||||||
{[]byte(nil), new([]byte), isExpectedEqBytes([]byte(nil))},
|
{[]byte(nil), new([]byte), isExpectedEqBytes([]byte(nil))},
|
||||||
{nil, new([]byte), isExpectedEqBytes([]byte(nil))},
|
{nil, new([]byte), isExpectedEqBytes([]byte(nil))},
|
||||||
|
|
||||||
|
// Test sql.Scanner. (https://github.com/jackc/pgx/issues/1418)
|
||||||
|
{"42", new(sql.NullInt64), isExpectedEq(sql.NullInt64{Int64: 42, Valid: true})},
|
||||||
})
|
})
|
||||||
|
|
||||||
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, pgxtest.KnownOIDQueryExecModes, "json", []pgxtest.ValueRoundTripTest{
|
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, pgxtest.KnownOIDQueryExecModes, "json", []pgxtest.ValueRoundTripTest{
|
||||||
|
|
Loading…
Reference in New Issue