Documentation ¶
Index ¶
- Constants
- Variables
- func IntValue[T constraints.Signed](i T) (driver.Value, error)
- func JSONValue(j JSON) (driver.Value, error)
- func MapValue[V any](m Map[V]) (driver.Value, error)
- func MarshalInt[T constraints.Signed](i T) ([]byte, error)
- func MarshalJSON(j JSON) ([]byte, error)
- func MarshalMap[V any](m Map[V]) ([]byte, error)
- func MarshalString[T ~string](s T) ([]byte, error)
- func ScanInt[T constraints.Signed](value any, i *T) error
- func ScanJSON(value any, j *JSON) error
- func ScanMap[V any](value any, m *Map[V]) error
- func ScanString[T ~string](value any, s *T) error
- func StringValue[T ~string](s T) (driver.Value, error)
- func UnmarshalInt[T constraints.Signed](b []byte, i *T) error
- func UnmarshalJSON(data []byte, j *JSON) error
- func UnmarshalMap[V any](data []byte, m *Map[V]) error
- func UnmarshalString[T ~string](b []byte, s *T) error
- type Int
- type Int64
- type JSON
- type Map
- type String
Constants ¶
const NullInt = Int(0)
NullInt is our constant for an Int value that will be written as null
const NullInt64 = Int64(0)
NullInt64 is our constant for an Int64 value that will be written as null
const NullString = String("")
NullString is our constant for an String value that will be written as null
Variables ¶
var NullJSON = JSON(`null`)
Functions ¶
func IntValue ¶
func IntValue[T constraints.Signed](i T) (driver.Value, error)
IntValue converts an int type value to NULL if it is zero.
func MarshalInt ¶
func MarshalInt[T constraints.Signed](i T) ([]byte, error)
MarshalJSON marshals an int type to JSON, using null for zero.
func MarshalJSON ¶
func MarshalMap ¶
MarshalMap marshals a map, returning null for an empty map.
func MarshalString ¶
MarshalJSON marshals a string type to JSON, using null for empty strings.
func ScanInt ¶
func ScanInt[T constraints.Signed](value any, i *T) error
ScanInt scans a nullable INT into an int type, using zero for NULL.
func ScanString ¶
ScanString scans a nullable CHAR/TEXT into a string type, using empty string for NULL.
func StringValue ¶
StringValue converts a string type value to NULL if it is empty
func UnmarshalInt ¶
func UnmarshalInt[T constraints.Signed](b []byte, i *T) error
UnmarshalInt unmarshals an int type from JSON, using zero for null.
func UnmarshalJSON ¶
func UnmarshalString ¶
UnmarshalString unmarshals a string type from JSON, using empty string for null.
Types ¶
type Int ¶
type Int int
Int is an int that will write as null when it is zero both to databases and JSON null values when unmarshalled or scanned from a DB will result in a zero value.
func (Int) MarshalJSON ¶
MarshalJSON implements the Marshaller interface
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaller interface
type Int64 ¶
type Int64 int64
Int64 is an int64 that will write as null when it is zero both to databases and JSON null values when unmarshalled or scanned from a DB will result in a zero value.
func (Int64) MarshalJSON ¶
MarshalJSON implements the Marshaller interface
func (*Int64) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaller interface
type JSON ¶
type JSON json.RawMessage
JSON is a json.RawMessage that will marshall as null when empty or nil.
func (JSON) MarshalJSON ¶
MarshalJSON implements the Marshaller interface
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaller interface
type Map ¶
Map is a generic map which is written to the database as JSON.
func (Map[V]) MarshalJSON ¶
MarshalJSON implements the Marshaller interface
func (*Map[V]) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaller interface
type String ¶
type String string
String is string that will write as null when it is empty, both to databases and JSON null values when unmarshalled or scanned from a DB will result in an empty string value.
func (String) MarshalJSON ¶
MarshalJSON implements the Marshaller interface
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaller interface