mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Allow setting nil to pgtype.Bool
This commit is contained in:
parent
f42b0f65fc
commit
1149b0f015
@ -13,6 +13,11 @@ type Bool struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dst *Bool) Set(src interface{}) error {
|
func (dst *Bool) Set(src interface{}) error {
|
||||||
|
if src == nil {
|
||||||
|
*dst = Bool{Status: Null}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
switch value := src.(type) {
|
switch value := src.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
*dst = Bool{Bool: value, Status: Present}
|
*dst = Bool{Bool: value, Status: Present}
|
||||||
|
@ -29,6 +29,7 @@ func TestBoolSet(t *testing.T) {
|
|||||||
{source: "f", result: pgtype.Bool{Bool: false, Status: pgtype.Present}},
|
{source: "f", result: pgtype.Bool{Bool: false, Status: pgtype.Present}},
|
||||||
{source: _bool(true), result: pgtype.Bool{Bool: true, Status: pgtype.Present}},
|
{source: _bool(true), result: pgtype.Bool{Bool: true, Status: pgtype.Present}},
|
||||||
{source: _bool(false), result: pgtype.Bool{Bool: false, Status: pgtype.Present}},
|
{source: _bool(false), result: pgtype.Bool{Bool: false, Status: pgtype.Present}},
|
||||||
|
{source: nil, result: pgtype.Bool{Status: pgtype.Null}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range successfulTests {
|
for i, tt := range successfulTests {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user