Documentation ¶
Overview ¶
Package types implements some commonly used db serializable types like datetime, json, etc.
Index ¶
Constants ¶
const DefaultDateLayout = "2006-01-02 15:04:05.000Z"
DefaultDateLayout specifies the default app date strings layout.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DateTime ¶
type DateTime struct {
// contains filtered or unexported fields
}
DateTime represents a time.Time instance in UTC that is wrapped and serialized using the app default date layout.
func NowDateTime ¶
func NowDateTime() DateTime
NowDateTime returns new DateTime instance with the current local time.
func ParseDateTime ¶
ParseDateTime creates a new DateTime from the provided value (could be cast.ToTime supported string, time.Time, etc.).
func (DateTime) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*DateTime) Scan ¶
Scan implements [sql.Scanner] interface to scan the provided value into the current DateTime instance.
func (DateTime) String ¶
String serializes the current DateTime instance into a formatted UTC date string.
The zero value is serialized to an empty string.
func (*DateTime) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type JsonArray ¶
type JsonArray[T any] []T
JsonArray defines a slice that is safe for json and db read/write.
func (JsonArray[T]) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type JsonMap ¶
JsonMap defines a map that is safe for json and db read/write.
func (JsonMap) Get ¶ added in v0.17.0
Get retrieves a single value from the current JsonMap.
This helper was added primarily to assist the goja integration since custom map types don't have direct access to the map keys (https://pkg.go.dev/github.com/dop251/goja#hdr-Maps_with_methods).
func (JsonMap) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*JsonMap) Scan ¶
Scan implements [sql.Scanner] interface to scan the provided value into the current `JsonMap` instance.
func (JsonMap) Set ¶ added in v0.17.0
Set sets a single value in the current JsonMap.
This helper was added primarily to assist the goja integration since custom map types don't have direct access to the map keys (https://pkg.go.dev/github.com/dop251/goja#hdr-Maps_with_methods).
type JsonRaw ¶
type JsonRaw []byte
JsonRaw defines a json value type that is safe for db read/write.
func ParseJsonRaw ¶
ParseJsonRaw creates a new JsonRaw instance from the provided value (could be JsonRaw, int, float, string, []byte, etc.).
func (JsonRaw) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*JsonRaw) Scan ¶
Scan implements [sql.Scanner] interface to scan the provided value into the current JsonRaw instance.
func (*JsonRaw) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.