Documentation ¶
Index ¶
- type Collection
- func (sc *Collection) AddFieldName(field string)
- func (sc *Collection) Bool(field string, value *bool) bool
- func (sc *Collection) Int(field string, value *int) int
- func (sc *Collection) NonNilFieldNames() []any
- func (sc *Collection) NullStringEmptyNull(field string, value *string) null.String
- func (sc *Collection) String(field string, value *string) string
- func (sc *Collection) Uint(field string, value *uint) uint
- func (sc *Collection) UintPtrZeroNil(field string, value *uint) *uint
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection stores field names of non-nil values. Meant to be used with the GORM .Where() clause.
Example ¶
package main import ( "fmt" "github.com/iver-wharf/wharf-api/v5/internal/wherefields" "gorm.io/gorm" ) func main() { db := &gorm.DB{} // placeholder GORM DB reference type Project struct { ProjectID uint Name string GroupName string } params := struct { ProjectID *uint Name *string GroupName *string }{} var where wherefields.Collection var dbProjects []Project err := db. Where(&Project{ ProjectID: where.Uint("ProjectID", params.ProjectID), Name: where.String("Name", params.Name), GroupName: where.String("GroupName", params.GroupName), }, where.NonNilFieldNames()...). Find(&dbProjects). Error if err != nil { fmt.Println("Err:", err) return } fmt.Println("Found projects:", dbProjects) }
Output:
func (*Collection) AddFieldName ¶
func (sc *Collection) AddFieldName(field string)
AddFieldName adds a string that will be returned later by NonNilFieldNames.
func (*Collection) Bool ¶
func (sc *Collection) Bool(field string, value *bool) bool
Bool stores the field name if the value was non-nil and returns the value of the field, or false if it was nil.
func (*Collection) Int ¶
func (sc *Collection) Int(field string, value *int) int
Int stores the field name if the value was non-nil and returns the value of the field, or zero (0) if it was nil.
func (*Collection) NonNilFieldNames ¶
func (sc *Collection) NonNilFieldNames() []any
NonNilFieldNames returns the slice of field names. Meant to be used as the trailing arguments to the GORM .Where() clause.
func (*Collection) NullStringEmptyNull ¶
func (sc *Collection) NullStringEmptyNull(field string, value *string) null.String
NullStringEmptyNull stores the field name if the value was non-nil and returns the value of the field and translates empty ("") to null.
func (*Collection) String ¶
func (sc *Collection) String(field string, value *string) string
String stores the field name if the value was non-nil and returns the value of the field, or empty string ("") if it was nil.
func (*Collection) Uint ¶
func (sc *Collection) Uint(field string, value *uint) uint
Uint stores the field name if the value was non-nil and returns the value of the field, or zero (0) if it was nil.
func (*Collection) UintPtrZeroNil ¶
func (sc *Collection) UintPtrZeroNil(field string, value *uint) *uint
UintPtrZeroNil stores the field name if the value was non-nil and returns the value of the field and translates zero (0) to nil.