Documentation
¶
Index ¶
- Constants
- func ObjFieldInterfaces(obj interface{}, includeID bool) []interface{}
- func ObjFieldValue(obj interface{}, fieldName string) interface{}
- func ObjIDInterface(obj interface{}) interface{}
- func ObjIDValue(obj interface{}) uint64
- func ObjSetIDValue(obj interface{}, id uint64)
- func SetObjCreated(obj interface{}, at int64, by uint64)
- func SetObjModified(obj interface{}, at int64, by uint64)
- func SetObjStringField(obj interface{}, passField, hashField string)
- func Validate(obj interface{}, restrictFields map[string]bool, tagName string) (bool, map[string]uint64, error)
- func ValidateFilters(obj interface{}, filters *sqlfilters.Filters, tagName string) error
- func ZeroObjFields(obj interface{})
- type CRUD
- func (c *CRUD) CreateTable(ctx context.Context, obj interface{}) error
- func (c *CRUD) Delete(ctx context.Context, obj interface{}, options DeleteOptions) error
- func (c *CRUD) DeleteMultiple(ctx context.Context, obj interface{}, options DeleteMultipleOptions) error
- func (c *CRUD) DropTable(ctx context.Context, obj interface{}) error
- func (c *CRUD) Get(ctx context.Context, newObjFunc func() interface{}, options GetOptions) ([]interface{}, map[string]int, error)
- func (c *CRUD) GetCount(ctx context.Context, obj interface{}, options GetCountOptions) (uint64, error)
- func (c *CRUD) Load(ctx context.Context, obj interface{}, id string, options LoadOptions) *LoadOutput
- func (c *CRUD) PasswordFieldsFor(obj interface{}) []string
- func (c *CRUD) Save(ctx context.Context, obj interface{}, options SaveOptions) error
- func (c *CRUD) SetFlag(flag uint64)
- func (c *CRUD) UpdateMultiple(ctx context.Context, obj interface{}, fieldsToUpdate map[string]interface{}, ...) error
- type CRUDError
- type DeleteMultipleOptions
- type DeleteOptions
- type GetCountOptions
- type GetOptions
- type LoadOptions
- type LoadOutput
- type Options
- type SaveOptions
- type UniqError
- type UpdateMultipleOptions
- type ValidationError
Constants ¶
const ( PassOK = iota PassInvalid )
const ( DialectPostgres = "postgres" DialectSQLite = "sqlite" )
const (
GetCountOnUniq = 1
)
const (
IDField = "ID"
)
Variables ¶
This section is empty.
Functions ¶
func ObjFieldInterfaces ¶
func ObjFieldInterfaces(obj interface{}, includeID bool) []interface{}
ObjFieldInterfaces returns a list of interfaces to object's fields Argument includeID tells it to include or omit the ID field
func ObjFieldValue ¶
func ObjFieldValue(obj interface{}, fieldName string) interface{}
func ObjIDInterface ¶
func ObjIDInterface(obj interface{}) interface{}
func ObjIDValue ¶
func ObjIDValue(obj interface{}) uint64
func ObjSetIDValue ¶
func ObjSetIDValue(obj interface{}, id uint64)
func SetObjCreated ¶
func SetObjModified ¶
func SetObjStringField ¶
func SetObjStringField(obj interface{}, passField, hashField string)
func ValidateFilters ¶
func ValidateFilters(obj interface{}, filters *sqlfilters.Filters, tagName string) error
func ZeroObjFields ¶
func ZeroObjFields(obj interface{})
Types ¶
type CRUD ¶
type CRUD struct {
// contains filtered or unexported fields
}
func (*CRUD) CreateTable ¶
CreateTable creates a database table for the specified object.
func (*CRUD) Delete ¶
func (c *CRUD) Delete(ctx context.Context, obj interface{}, options DeleteOptions) error
Delete removes an object from the database table only when ID field is set (greater than 0). Once deleted from the DB, all field values are zeroed
func (*CRUD) DeleteMultiple ¶
func (c *CRUD) DeleteMultiple(ctx context.Context, obj interface{}, options DeleteMultipleOptions) error
DeleteMultiple removes objects from the database based on specified filters
func (*CRUD) Get ¶
func (c *CRUD) Get(ctx context.Context, newObjFunc func() interface{}, options GetOptions) ([]interface{}, map[string]int, error)
Get returns the matching records and, for every password field that also appears in options.VerifyPasswordFields, either PassOK or PassInvalid — but only when exactly one record was found. Keys in VerifyPasswordFields that do not name an actual password field are ignored.
func (*CRUD) GetCount ¶
func (c *CRUD) GetCount(ctx context.Context, obj interface{}, options GetCountOptions) (uint64, error)
GetCount runs a 'SELECT COUNT(*)' query on the database with specified filters, order, limit and offset and returns count of rows
func (*CRUD) Load ¶
func (c *CRUD) Load(ctx context.Context, obj interface{}, id string, options LoadOptions) *LoadOutput
func (*CRUD) PasswordFieldsFor ¶
PasswordFieldsFor returns the struct field names tagged as passwords for the type of obj. Returns nil if obj has no password fields.
func (*CRUD) Save ¶
func (c *CRUD) Save(ctx context.Context, obj interface{}, options SaveOptions) error
Save takes an object, validates its field values, and saves it in the database. If ID is not present, then an INSERT will be performed. If ID is set, then an "upsert" is performed.
func (*CRUD) UpdateMultiple ¶
type DeleteMultipleOptions ¶
type DeleteMultipleOptions struct {
Filters *sqlfilters.Filters
}
type DeleteOptions ¶
type DeleteOptions struct{}
type GetCountOptions ¶
type GetCountOptions struct {
Filters *sqlfilters.Filters
ConvertFiltersFromString bool
}
type GetOptions ¶
type GetOptions struct {
Order []string
Limit int
Offset int
Filters *sqlfilters.Filters
RowObjTransformFunc func(interface{}) interface{}
ConvertFiltersFromString bool
// VerifyPasswordFields maps a struct field name to a plaintext password
// to verify against the bcrypt hash stored in that field. Verification
// only happens when the query matches exactly one record; for any other
// result count the returned map is empty.
VerifyPasswordFields map[string]string
}
type LoadOptions ¶
type LoadOutput ¶ added in v0.36.0
LoadOutput is returned by Load. PasswordFields holds, for every password field that also appears in LoadOptions.VerifyPasswordFields, either PassOK or PassInvalid. Keys in VerifyPasswordFields that do not name an actual password field are ignored.
type SaveOptions ¶
type UpdateMultipleOptions ¶
type UpdateMultipleOptions struct {
Filters *sqlfilters.Filters
ConvertValuesFromString bool
}
type ValidationError ¶
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string