types

package
v0.0.0-...-c9d2023 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NullBoolFrom

func NullBoolFrom(v bool) sql.NullBool

NullBoolFrom creates a valid NullBool Deprecated: will be renamed in future version, use `ToNullBool`

func NullFloat64From

func NullFloat64From(v float64) sql.NullFloat64

NullFloat64From creates a valid NullFloat64 Deprecated: will be renamed in future version, use `ToNullFloat64`

func NullInt64From

func NullInt64From(v int64) sql.NullInt64

NullInt64From creates a valid NullInt64 Deprecated: will be renamed in future version, use `ToNullInt64`

func NullStringFrom

func NullStringFrom(v string) sql.NullString

NullStringFrom creates a valid NullString Deprecated: will be renamed in future version, use `ToNullString`

Types

type BoolSlice

type BoolSlice []bool

BoolSlice makes easy to handle JSON encoded bool lists stored at database's text fields(like VARCHAR,CHAR,TEXT) and blob fields

func (*BoolSlice) Scan

func (ss *BoolSlice) Scan(src interface{}) error

Scan stores the value as BoolSlice. Value can be string, []byte or or nil.

func (BoolSlice) Value

func (ss BoolSlice) Value() (driver.Value, error)

Value returns value. If value is invalid value, it returns an error.

type CompactJSONStr

type CompactJSONStr json.RawMessage

CompactJSONStr is same as JSONStr except, whitespaces are remove from JSON formatted data while saving to database. It is useless if data is hold in database specific json typed field(like PostgreSQL's JSONB field). NullCompactJSONStr is nullable version of CompactJSONStr.

CompactJSONStr is `json.RawMessage` (`[]byte`) type, adding `Value()` and `Scan()` methods for db access and `MarshalJSON`, `UnmarshalJSON` for json serializing.

This type make use of DB binary or string fields like a JSON container. DB field type can be text types like CHAR, STRING, CHARACTER VARYING, TEXT or binary types like JSONB, BYTEA, BLOB...

JSON data is hold as "compacted" mode in database.

For performance binary db field use is advised.

func (CompactJSONStr) MarshalJSON

func (js CompactJSONStr) MarshalJSON() ([]byte, error)

MarshalJSON returns JSON encoding

func (*CompactJSONStr) Scan

func (js *CompactJSONStr) Scan(src interface{}) error

Scan stores the value as CompactJSONStr. Value can be string, []byte or or nil.

func (CompactJSONStr) String

func (js CompactJSONStr) String() string

String does pretty printing

func (*CompactJSONStr) Unmarshal

func (js *CompactJSONStr) Unmarshal(v interface{}) error

Unmarshal unmarshal's using json.Unmarshal.

func (*CompactJSONStr) UnmarshalJSON

func (js *CompactJSONStr) UnmarshalJSON(data []byte) error

UnmarshalJSON sets copy of data to instance

func (CompactJSONStr) Value

func (js CompactJSONStr) Value() (driver.Value, error)

Value returns value. Validates JSON. If value is invalid json, it returns an error.

type Float64Slice

type Float64Slice []float64

Float64Slice makes easy to handle JSON encoded float64 lists stored at database's text fields(like VARCHAR,CHAR,TEXT) and blob fields

func (*Float64Slice) Scan

func (ss *Float64Slice) Scan(src interface{}) error

Scan stores the value as Float64Slice. Value can be string, []byte or or nil.

func (Float64Slice) Value

func (ss Float64Slice) Value() (driver.Value, error)

Value returns value. If value is invalid value, it returns an error.

type Int64Slice

type Int64Slice []int64

Int64Slice makes easy to handle JSON encoded int64 lists stored at database's text fields(like VARCHAR,CHAR,TEXT) and blob fields

func (*Int64Slice) Scan

func (ss *Int64Slice) Scan(src interface{}) error

Scan stores the value as Int64Slice. Value can be string, []byte or or nil.

func (Int64Slice) Value

func (ss Int64Slice) Value() (driver.Value, error)

Value returns value. If value is invalid value, it returns an error.

type JSONStr

type JSONStr json.RawMessage

JSONStr makes easy to handle JSON data at database's text fields(like VARCHAR,CHAR,TEXT) and blob fields

func (JSONStr) MarshalJSON

func (js JSONStr) MarshalJSON() ([]byte, error)

MarshalJSON returns JSON encoding

func (*JSONStr) Scan

func (js *JSONStr) Scan(src interface{}) error

Scan stores the value as JSONStr. Value can be string, []byte or or nil.

func (JSONStr) String

func (js JSONStr) String() string

String does pretty printing

func (*JSONStr) Unmarshal

func (js *JSONStr) Unmarshal(v interface{}) error

Unmarshal unmarshal's using json.Unmarshal.

func (*JSONStr) UnmarshalJSON

func (js *JSONStr) UnmarshalJSON(data []byte) error

UnmarshalJSON sets copy of data to instance

func (JSONStr) Value

func (js JSONStr) Value() (driver.Value, error)

Value returns value. Validates JSON. If value is invalid json, it returns an error.

type Map

type Map map[string]interface{}

Map makes easy to handle JSON encoded map stored at database's text fields(like VARCHAR,CHAR,TEXT) and blob fields

func (*Map) Scan

func (ss *Map) Scan(src interface{}) error

Scan stores the value as Map. Value can be string, []byte or or nil.

func (Map) String

func (ss Map) String() string

String does pretty printing

func (Map) Value

func (ss Map) Value() (driver.Value, error)

Value returns value. If value is invalid value, it returns an error.

type NullBool

type NullBool struct {
	sql.NullBool
}

NullBool is a type that can be null or a bool, wrapped for JSON encoding/decoding

func ToNullBool

func ToNullBool(v bool) NullBool

ToNullBool creates a valid NullBool

func (NullBool) MarshalJSON

func (n NullBool) MarshalJSON() ([]byte, error)

MarshalJSON serializes a NullBool to JSON

func (*NullBool) UnmarshalJSON

func (n *NullBool) UnmarshalJSON(b []byte) error

UnmarshalJSON parses NullBool from JSON

type NullBytes

type NullBytes struct {
	Bytes []byte
	Valid bool // Valid is true if Bytes is not NULL
}

NullBytes can be an []byte or a null value.

func NullBytesFrom

func NullBytesFrom(v []byte) NullBytes

NullBytesFrom creates a valid NullBytes Deprecated: will be renamed in future version, use `ToNullBytes`

func ToNullBytes

func ToNullBytes(v []byte) NullBytes

ToNullBytes creates a valid NullBytes

func (*NullBytes) Scan

func (n *NullBytes) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullBytes) Value

func (n NullBytes) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullCompactJSONStr

type NullCompactJSONStr struct {
	CompactJSONStr
	Valid bool // Valid is true if CompactJSONStr is not NULL
}

NullCompactJSONStr can be an CompactJSONStr or a null value. Can be used like `JSONStr`

func NullCompactJSONStrFrom

func NullCompactJSONStrFrom(dst []byte) NullCompactJSONStr

NullCompactJSONStrFrom creates a valid NullCompactJSONStr Deprecated: will be renamed in future version, use `ToNullCompactJSONStr`

func ToNullCompactJSONStr

func ToNullCompactJSONStr(dst []byte) NullCompactJSONStr

ToNullCompactJSONStr creates a valid NullCompactJSONStr

func (*NullCompactJSONStr) Scan

func (n *NullCompactJSONStr) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullCompactJSONStr) Value

func (n NullCompactJSONStr) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullFloat64

type NullFloat64 struct {
	sql.NullFloat64
}

NullFloat64 is a type that can be null or a float64, wrapped for JSON encoding/decoding

func ToNullFloat64

func ToNullFloat64(v float64) NullFloat64

ToNullFloat64 creates a valid NullFloat64

func (NullFloat64) MarshalJSON

func (n NullFloat64) MarshalJSON() ([]byte, error)

MarshalJSON serializes a NullFloat64 to JSON

func (*NullFloat64) UnmarshalJSON

func (n *NullFloat64) UnmarshalJSON(b []byte) error

UnmarshalJSON parses NullFloat64 from JSON

type NullInt64

type NullInt64 struct {
	sql.NullInt64
}

NullInt64 is a type that can be null or an int, wrapped for JSON encoding/decoding

func ToNullInt64

func ToNullInt64(v int64) NullInt64

ToNullInt64 creates a valid NullInt64

func (NullInt64) MarshalJSON

func (n NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON NullInt64 to JSON

func (*NullInt64) UnmarshalJSON

func (n *NullInt64) UnmarshalJSON(b []byte) error

UnmarshalJSON parses NullInt64 from JSON

type NullJSONStr

type NullJSONStr struct {
	JSONStr
	Valid bool // Valid is true if JSONStr is not NULL
}

NullJSONStr can be an JSONStr or a null value. Can be used like `sql.NullSting`

func NullJSONStrFrom

func NullJSONStrFrom(dst []byte) NullJSONStr

NullJSONStrFrom creates a valid NullJSONStr Deprecated: will be renamed in future version, use `ToNullJSONStr`

func ToNullJSONStr

func ToNullJSONStr(dst []byte) NullJSONStr

ToNullJSONStr creates a valid NullJSONStr

func (*NullJSONStr) Scan

func (n *NullJSONStr) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullJSONStr) Value

func (n NullJSONStr) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullString

type NullString struct {
	sql.NullString
}

NullString is a type that can be null or a string, wrapped for JSON encoding/decoding

func ToNullString

func ToNullString(v string) NullString

ToNullString creates a valid NullString

func (NullString) MarshalJSON

func (n NullString) MarshalJSON() ([]byte, error)

MarshalJSON serializes a NullString to JSON

func (*NullString) UnmarshalJSON

func (n *NullString) UnmarshalJSON(b []byte) error

UnmarshalJSON parses NullString from JSON

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

NullTime is a type that can be null or a time

func NullTimeFrom

func NullTimeFrom(v time.Time) NullTime

NullTimeFrom creates a valid NullTime Deprecated: will be renamed in future version, use `ToNullTime`

func ToNullTime

func ToNullTime(v time.Time) NullTime

ToNullTime creates a valid NullTime

func (NullTime) MarshalJSON

func (nt NullTime) MarshalJSON() ([]byte, error)

MarshalJSON serializes a NullTime to JSON.

func (*NullTime) Scan

func (nt *NullTime) Scan(value interface{}) error

Scan implements the time scanner interface.

func (*NullTime) UnmarshalJSON

func (nt *NullTime) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON deserializes a NullTime from JSON.

func (NullTime) Value

func (nt NullTime) Value() (driver.Value, error)

Value implements the time driver Valuer interface.

type StrSlice

type StrSlice []string

StrSlice makes easy to handle JSON encoded string lists stored at database's text fields(like VARCHAR,CHAR,TEXT) and blob fields

func (*StrSlice) Scan

func (ss *StrSlice) Scan(src interface{}) error

Scan stores the value as StrSlice. Value can be string, []byte or or nil.

func (StrSlice) Value

func (ss StrSlice) Value() (driver.Value, error)

Value returns value. If value is invalid value, it returns an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL