Documentation ¶
Index ¶
- Variables
- type ListType
- type Record
- type RecordList
- type RecordType
- type Thing
- func (thing *Thing) AsTypeThing() string
- func (thing *Thing) AsTypeThingParam(paramName string) string
- func (thing *Thing) Id() string
- func (thing *Thing) MarshalJSON() ([]byte, error)
- func (thing *Thing) Table() string
- func (thing *Thing) UnmarshalJSON(data []byte) error
- func (thing *Thing) Value() string
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidThing = fmt.Errorf("invalid thing")
Functions ¶
This section is empty.
Types ¶
type Record ¶
type Record[T any] struct { // contains filtered or unexported fields }
func NewRecord ¶ added in v0.0.5
NewRecord creates a new Record[T] instance. Either the id or the value must be set.
func (*Record[T]) MarshalJSON ¶
func (*Record[T]) UnmarshalJSON ¶
type RecordList ¶
func (*RecordList[T]) IdMap ¶
func (d *RecordList[T]) IdMap() map[string]*T
IdMap returns the ids in the list(this would be used when we haven't fetched the records)
func (*RecordList[T]) Ids ¶
func (d *RecordList[T]) Ids() []string
Ids return an array of all ids in the list
func (*RecordList[T]) IsResolved ¶
func (d *RecordList[T]) IsResolved() bool
IsResolved check if the list has been resolved/initiated
func (*RecordList[T]) Items ¶
func (d *RecordList[T]) Items() []T
Items returns the items in the list
func (*RecordList[T]) MarshalJSON ¶
func (d *RecordList[T]) MarshalJSON() ([]byte, error)
func (*RecordList[T]) UnmarshalJSON ¶
func (d *RecordList[T]) UnmarshalJSON(data []byte) error
type RecordType ¶
type RecordType string
var ( RecordTypeId RecordType = "id" RecordTypeRecord RecordType = "record" )
type Thing ¶
type Thing struct {
// contains filtered or unexported fields
}
func NewThing ¶
NewThing Creates a new thing If we pass a single value, it will split it and validate. For example:
// Single thing value string thing := NewThing("table:id") // Table and id separately thing := NewThing("table", "id")
func (*Thing) AsTypeThing ¶
AsTypeThing Get the value for the database, for example `type::thing('table','id')`
func (*Thing) AsTypeThingParam ¶
AsTypeThingParam Get the value for the database, like AsTypeThing, but it will use a param for the value instead. This will automatically add the $ to the param, for example:
thing := NewThing("user", "31367126") thing.AsTypeThingParam("id") // type::thing('user', $id) db.Query(fmt.Sprintf("select * from %s", thing.AsTypeThingParam("id")), map[string]any{ "id": thing.Id(), })
Will output the query:
select * from type::thing('user', $id)