Documentation ¶
Index ¶
- func JSONScan(dst interface{}, value interface{}) error
- func JSONValue(src interface{}) (driver.Value, error)
- func NamedInsertArguments(t interface{}, exclude ...string) (columns string, arguments string)
- func NamedUpdateArguments(t interface{}, exclude ...string) string
- type Duration
- type JSONArrayRawMessage
- type JSONRawMessage
- type MapStringInterface
- type NullBool
- type NullDuration
- type NullInt64
- type NullJSONRawMessage
- type NullString
- type NullTime
- type StringSliceJSONFormat
- type StringSlicePipeDelimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONScan ¶
func JSONScan(dst interface{}, value interface{}) error
JSONScan is a generic helper for storing a value as a JSON blob in SQL.
func NamedInsertArguments ¶
NamedInsertArguments returns columns and arguments for SQL INSERT statements based on a struct's tags. Does not work with nested structs or maps!
type st struct { Foo string `db:"foo"` Bar string `db:"bar,omitempty"` Baz string `db:"-"` Zab string } columns, arguments := NamedInsertArguments(new(st)) query := fmt.Sprintf("INSERT INTO foo (%s) VALUES (%s)", columns, arguments) // INSERT INTO foo (foo, bar) VALUES (:foo, :bar)
func NamedUpdateArguments ¶
NamedUpdateArguments returns columns and arguments for SQL UPDATE statements based on a struct's tags. Does not work with nested structs or maps!
type st struct { Foo string `db:"foo"` Bar string `db:"bar,omitempty"` Baz string `db:"-"` Zab string } query := fmt.Sprintf("UPDATE foo SET %s", NamedUpdateArguments(new(st))) // UPDATE foo SET foo=:foo, bar=:bar
Types ¶
type Duration ¶
Duration represents a JSON and SQL compatible time.Duration. swagger:type string
func (Duration) MarshalJSON ¶
MarshalJSON returns m as the JSON encoding of m.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON sets *m to a copy of data.
type JSONArrayRawMessage ¶
type JSONArrayRawMessage json.RawMessage
JSONArrayRawMessage represents a json.RawMessage which only accepts arrays that works well with JSON, SQL, and Swagger.
func (*JSONArrayRawMessage) Scan ¶
func (m *JSONArrayRawMessage) Scan(value interface{}) error
Scan implements the Scanner interface.
type JSONRawMessage ¶
type JSONRawMessage json.RawMessage
JSONRawMessage represents a json.RawMessage that works well with JSON, SQL, and Swagger.
func (JSONRawMessage) MarshalJSON ¶
func (m JSONRawMessage) MarshalJSON() ([]byte, error)
MarshalJSON returns m as the JSON encoding of m.
func (*JSONRawMessage) Scan ¶
func (m *JSONRawMessage) Scan(value interface{}) error
Scan implements the Scanner interface.
func (*JSONRawMessage) UnmarshalJSON ¶
func (m *JSONRawMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON sets *m to a copy of data.
type MapStringInterface ¶
type MapStringInterface map[string]interface{}
MapStringInterface represents a map[string]interface that works well with JSON, SQL, and Swagger.
func (*MapStringInterface) Scan ¶
func (n *MapStringInterface) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullBool ¶
NullBool represents a bool that may be null. NullBool implements the Scanner interface so swagger:type bool swagger:model nullBool
func (NullBool) MarshalJSON ¶
MarshalJSON returns m as the JSON encoding of m.
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON sets *m to a copy of data.
type NullDuration ¶
NullDuration represents a nullable JSON and SQL compatible time.Duration.
swagger:type string swagger:model nullDuration
func (NullDuration) MarshalJSON ¶
func (ns NullDuration) MarshalJSON() ([]byte, error)
MarshalJSON returns m as the JSON encoding of m.
func (*NullDuration) Scan ¶
func (ns *NullDuration) Scan(value interface{}) error
Scan implements the Scanner interface.
func (*NullDuration) UnmarshalJSON ¶
func (ns *NullDuration) UnmarshalJSON(data []byte) error
UnmarshalJSON sets *m to a copy of data.
type NullInt64 ¶
NullInt64 represents an int64 that may be null. swagger:model nullInt64
func (NullInt64) MarshalJSON ¶
MarshalJSON returns m as the JSON encoding of m.
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON sets *m to a copy of data.
type NullJSONRawMessage ¶
type NullJSONRawMessage json.RawMessage
NullJSONRawMessage represents a json.RawMessage that works well with JSON, SQL, and Swagger and is NULLable-
swagger:model nullJsonRawMessage
func (NullJSONRawMessage) MarshalJSON ¶
func (m NullJSONRawMessage) MarshalJSON() ([]byte, error)
MarshalJSON returns m as the JSON encoding of m.
func (*NullJSONRawMessage) Scan ¶
func (m *NullJSONRawMessage) Scan(value interface{}) error
Scan implements the Scanner interface.
func (*NullJSONRawMessage) UnmarshalJSON ¶
func (m *NullJSONRawMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON sets *m to a copy of data.
type NullString ¶
type NullString string
swagger:type string swagger:model nullString
func (NullString) MarshalJSON ¶
func (ns NullString) MarshalJSON() ([]byte, error)
MarshalJSON returns m as the JSON encoding of m.
func (*NullString) Scan ¶
func (ns *NullString) Scan(value interface{}) error
Scan implements the Scanner interface.
func (NullString) String ¶
func (ns NullString) String() string
String implements the Stringer interface.
func (*NullString) UnmarshalJSON ¶
func (ns *NullString) UnmarshalJSON(data []byte) error
UnmarshalJSON sets *m to a copy of data.
type NullTime ¶
NullTime implements sql.NullTime functionality.
swagger:model nullTime required: false
func (NullTime) MarshalJSON ¶
MarshalJSON returns m as the JSON encoding of m.
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON sets *m to a copy of data.
type StringSliceJSONFormat ¶
type StringSliceJSONFormat []string
StringSliceJSONFormat represents []string{} which is encoded to/from JSON for SQL storage.
func (*StringSliceJSONFormat) Scan ¶
func (m *StringSliceJSONFormat) Scan(value interface{}) error
Scan implements the Scanner interface.
type StringSlicePipeDelimiter ¶
type StringSlicePipeDelimiter []string
StringSlicePipeDelimiter de/encodes the string slice to/from a SQL string.
func (*StringSlicePipeDelimiter) Scan ¶
func (n *StringSlicePipeDelimiter) Scan(value interface{}) error
Scan implements the Scanner interface.