Documentation
¶
Index ¶
- Constants
- type Controller
- func (c *Controller) AddSQLGenerator(obj interface{}, parentObj interface{}, overwrite bool, forceName string, ...) error
- func (c Controller) CreateTable(obj interface{}) error
- func (c Controller) CreateTables(xobj ...interface{}) error
- func (c Controller) Delete(obj interface{}, options DeleteOptions) error
- func (c Controller) DeleteMultiple(obj interface{}, options DeleteMultipleOptions) error
- func (c Controller) DropTable(obj interface{}) error
- func (c Controller) DropTables(xobj ...interface{}) error
- func (c Controller) Get(newObjFunc func() interface{}, options GetOptions) ([]interface{}, error)
- func (c Controller) GetCount(newObjFunc func() interface{}, options GetCountOptions) (int64, error)
- func (c *Controller) GetFieldNameFromDBCol(obj interface{}, dbCol string) (string, error)
- func (c Controller) GetFiltersInterfaces(mf map[string]interface{}) []interface{}
- func (c Controller) GetObjFieldInterfaces(obj interface{}, includeID bool) []interface{}
- func (c *Controller) GetObjIDInterface(obj interface{}) interface{}
- func (c *Controller) GetObjIDValue(obj interface{}) int64
- func (c Controller) Load(obj interface{}, id string, options LoadOptions) error
- func (c Controller) ResetFields(obj interface{})
- func (c Controller) Save(obj interface{}, options SaveOptions) error
- func (c *Controller) SetObjCreated(obj interface{}, at int64, by int64)
- func (c *Controller) SetObjLastModified(obj interface{}, at int64, by int64)
- func (c *Controller) StringToFieldValues(obj interface{}, values map[string]interface{}) map[string]interface{}
- func (c Controller) UpdateMultiple(obj interface{}, values map[string]interface{}, options UpdateMultipleOptions) error
- func (c Controller) Validate(obj interface{}, filters map[string]interface{}) (bool, map[string]int, error)
- type ControllerConfig
- type DeleteMultipleOptions
- type DeleteOptions
- type ErrController
- type ErrValidation
- type GetCountOptions
- type GetOptions
- type LoadOptions
- type SaveOptions
- type UpdateMultipleOptions
Constants ¶
const RawConjuctionAND = 2
const RawConjuctionOR = 1
const VERSION = "0.7.0"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is the main component that gets and saves objects in the database.
func NewController ¶
func NewController(dbConn *sql.DB, tblPrefix string, cfg *ControllerConfig) *Controller
NewController returns new Controller object
func (*Controller) AddSQLGenerator ¶
func (c *Controller) AddSQLGenerator(obj interface{}, parentObj interface{}, overwrite bool, forceName string, parentOnlyRoot bool) error
AddSQLGenerator adds StructSQL object to sqlGenerators
func (Controller) CreateTable ¶
func (c Controller) CreateTable(obj interface{}) error
CreateTable creates database table to store specified type of objects. It takes struct name and its fields, converts them into table and columns names (all lowercase with underscore), assigns column type based on the field type, and then executes "CREATE TABLE" query on attached DB connection
func (Controller) CreateTables ¶
func (c Controller) CreateTables(xobj ...interface{}) error
CreateTables creates tables in the database for specified objects (see CreateTable for a single struct)
func (Controller) Delete ¶
func (c Controller) Delete(obj interface{}, options DeleteOptions) error
Delete removes object from the database table and it does that only when ID field is set (greater than 0). Once deleted from the DB, all field values are zeroed TODO: Error handling probably needs re-designing
func (Controller) DeleteMultiple ¶
func (c Controller) DeleteMultiple(obj interface{}, options DeleteMultipleOptions) error
DeleteMultiple removes objects from the database based on specified filters
func (Controller) DropTable ¶
func (c Controller) DropTable(obj interface{}) error
DropTable drops database table used to store specified type of objects. It just takes struct name, converts it to lowercase-with-underscore table name and executes "DROP TABLE" query using attached DB connection
func (Controller) DropTables ¶
func (c Controller) DropTables(xobj ...interface{}) error
DropTables drop tables in the database for specified objects (see DropTable for a single struct)
func (Controller) Get ¶
func (c Controller) Get(newObjFunc func() interface{}, options GetOptions) ([]interface{}, error)
Get runs a select query on the database with specified filters, order, limit and offset and returns a list of objects
func (Controller) GetCount ¶
func (c Controller) GetCount(newObjFunc func() interface{}, options GetCountOptions) (int64, error)
GetCount runs a 'SELECT COUNT(*)' query on the database with specified filters, order, limit and offset and returns count of rows
func (*Controller) GetFieldNameFromDBCol ¶
func (c *Controller) GetFieldNameFromDBCol(obj interface{}, dbCol string) (string, error)
GetDBCol returns column name used in the database
func (Controller) GetFiltersInterfaces ¶
func (c Controller) GetFiltersInterfaces(mf map[string]interface{}) []interface{}
GetFiltersInterfaces returns list of interfaces from filters map (used in querying)
func (Controller) GetObjFieldInterfaces ¶
func (c Controller) GetObjFieldInterfaces(obj interface{}, includeID bool) []interface{}
GetObjFieldInterfaces return list of interfaces to object's fields Argument includeID tells it to include or omit the ID field
func (*Controller) GetObjIDInterface ¶
func (c *Controller) GetObjIDInterface(obj interface{}) interface{}
GetObjIDInterface returns an interface{} to ID field of an object
func (*Controller) GetObjIDValue ¶
func (c *Controller) GetObjIDValue(obj interface{}) int64
GetObjIDValue returns value of ID field (int64) of an object
func (Controller) Load ¶
func (c Controller) Load(obj interface{}, id string, options LoadOptions) error
Load sets object's fields with values from the database table with a specific id. If record does not exist in the database, all field values in the struct are zeroed TODO: Should it return an ErrNotExist?
func (Controller) ResetFields ¶
func (c Controller) ResetFields(obj interface{})
ResetFields zeroes object's field values
func (Controller) Save ¶
func (c Controller) Save(obj interface{}, options SaveOptions) error
Save takes 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 (*Controller) SetObjCreated ¶
func (c *Controller) SetObjCreated(obj interface{}, at int64, by int64)
SetObjCreated sets object's CreatedAt and CreatedBy fields
func (*Controller) SetObjLastModified ¶
func (c *Controller) SetObjLastModified(obj interface{}, at int64, by int64)
SetObjLastModified sets object's LastModifiedAt and LastModifiedBy fields
func (*Controller) StringToFieldValues ¶
func (c *Controller) StringToFieldValues(obj interface{}, values map[string]interface{}) map[string]interface{}
StringToFieldValues converts map of field values which are in string to values of the same kind of fields are
func (Controller) UpdateMultiple ¶
func (c Controller) UpdateMultiple(obj interface{}, values map[string]interface{}, options UpdateMultipleOptions) error
UpdateMultiple updates specific fields in objects from the database based on specified filters
type ControllerConfig ¶
type ControllerConfig struct {
TagName string
}
type DeleteMultipleOptions ¶
type DeleteOptions ¶
type DeleteOptions struct {
Constructors map[string]func() interface{}
}
type ErrController ¶
ErrController wraps original error that occurred in Err with name of the operation/step that failed, which is in Op field
func (ErrController) Error ¶
func (e ErrController) Error() string
func (ErrController) Unwrap ¶
func (e ErrController) Unwrap() error
type ErrValidation ¶
ErrValidation wraps error occurring during object validation
func (ErrValidation) Error ¶
func (e ErrValidation) Error() string
func (ErrValidation) Unwrap ¶
func (e ErrValidation) Unwrap() error
type GetCountOptions ¶
type GetCountOptions struct {
Filters map[string]interface{}
}
type GetOptions ¶
type LoadOptions ¶
type LoadOptions struct {
Unused bool
}