-
Notifications
You must be signed in to change notification settings - Fork 1
/
nullboolarray.go
43 lines (35 loc) · 1.15 KB
/
nullboolarray.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package nullable
import (
"database/sql"
"database/sql/driver"
"fmt"
"github.com/domonda/go-types/notnull"
)
// NullBoolArray implements the sql.Scanner and driver.Valuer interfaces
// for a slice of sql.NullBool.
// A nil slice is mapped to the SQL NULL value,
// and a non nil zero length slice to an empty SQL array '{}'.
type NullBoolArray []sql.NullBool
// IsNull returns true if a is nil.
// IsNull implements the Nullable interface.
func (a NullBoolArray) IsNull() bool { return a == nil }
// Bools returns all NullBoolArray elements as []bool with NULL elements set to false.
func (a NullBoolArray) Bools() []bool {
return notnull.NullBoolArray(a).Bools()
}
// String implements the fmt.Stringer interface.
func (a NullBoolArray) String() string {
value, _ := a.Value()
return fmt.Sprintf("NullBoolArray%v", value)
}
// Value implements the database/sql/driver.Valuer interface
func (a NullBoolArray) Value() (driver.Value, error) {
if a == nil {
return nil, nil
}
return notnull.NullBoolArray(a).Value()
}
// Scan implements the sql.Scanner interface
func (a *NullBoolArray) Scan(src any) error {
return (*notnull.NullBoolArray)(a).Scan(src)
}