Documentation
¶
Index ¶
- Constants
- func GetStructFieldNames(u interface{}) []string
- func GetStructName(u interface{}) string
- func GetStructNamesFromConstructors(objFuncs ...func() interface{}) []string
- func IsFieldKindSupported(k reflect.Kind) bool
- func IsStructField(u interface{}, field string) bool
- type ErrStructSQL
- type StructSQL
- func (h *StructSQL) Err() error
- func (h *StructSQL) GetFieldNameFromDBCol(n string) string
- func (h *StructSQL) GetFlags() int
- func (h StructSQL) GetQueryCreateTable() string
- func (h *StructSQL) GetQueryDelete(filters map[string]interface{}, filterFieldsToInclude map[string]bool) string
- func (h *StructSQL) GetQueryDeleteById() string
- func (h *StructSQL) GetQueryDeleteReturningID(filters map[string]interface{}, filterFieldsToInclude map[string]bool) string
- func (h StructSQL) GetQueryDropTable() string
- func (h *StructSQL) GetQueryInsert() string
- func (h *StructSQL) GetQueryInsertOnConflictUpdate() string
- func (h *StructSQL) GetQuerySelect(order []string, limit int, offset int, filters map[string]interface{}, ...) string
- func (h *StructSQL) GetQuerySelectById() string
- func (h *StructSQL) GetQuerySelectCount(filters map[string]interface{}, filterFieldsToInclude map[string]bool) string
- func (h *StructSQL) GetQueryUpdate(values map[string]interface{}, filters map[string]interface{}, ...) string
- func (h *StructSQL) GetQueryUpdateById() string
- func (h *StructSQL) HasModificationFields() bool
- type StructSQLOptions
Constants ¶
const RawConjuctionAND = 2
const RawConjuctionOR = 1
const VERSION = "0.7.0"
const ValueBit = 9
const ValueEqual = 1
const ValueGreater = 5
const ValueGreaterOrEqual = 7
const ValueLike = 3
const ValueLower = 6
const ValueLowerOrEqual = 8
const ValueMatch = 4
const ValueNotEqual = 2
Variables ¶
This section is empty.
Functions ¶
func GetStructFieldNames ¶
func GetStructFieldNames(u interface{}) []string
GetStructFieldNames returns list of names of fields of a struct instance, which are supported in generating SQL query.
func GetStructName ¶
func GetStructName(u interface{}) string
GetStructName returns struct name of a struct instance
func GetStructNamesFromConstructors ¶
func GetStructNamesFromConstructors(objFuncs ...func() interface{}) []string
GetStructNamesFromConstructors returns a list of struct names from a list of constructors (functions that return struct instances)
func IsFieldKindSupported ¶
IsFieldKindSupported checks if a field kind is supported by this module
func IsStructField ¶
IsStructField checks if a specific string is a name of a field
Types ¶
type ErrStructSQL ¶
ErrStructSQL wraps original error with operation/step where the error occurred and optionally with a tag when parsing "crud" failed
func (ErrStructSQL) Error ¶
func (e ErrStructSQL) Error() string
func (ErrStructSQL) Unwrap ¶
func (e ErrStructSQL) Unwrap() error
type StructSQL ¶
type StructSQL struct {
// contains filtered or unexported fields
}
StructSQL reflects the object to generate and cache PostgreSQL queries (CREATE TABLE, INSERT, UPDATE etc.). Database table and column names are lowercase with underscore and they are generated from field names. StructSQL is created within Controller and there is no need to instantiate it
func NewStructSQL ¶
func NewStructSQL(obj interface{}, options StructSQLOptions) *StructSQL
NewStructSQL takes object and database table name prefix as arguments and returns StructSQL instance.
func (*StructSQL) GetFieldNameFromDBCol ¶
GetFieldNameFromDBCol returns field name from a table column.
func (StructSQL) GetQueryCreateTable ¶
GetQueryCreateTable return a CREATE TABLE query. Columns in the query are ordered the same way as they are defined in the struct, eg. SELECT field1_column, field2_column, ... etc.
func (*StructSQL) GetQueryDelete ¶
func (h *StructSQL) GetQueryDelete(filters map[string]interface{}, filterFieldsToInclude map[string]bool) string
GetQueryDelete return a DELETE query with WHERE condition built from 'filters' (field-value pairs). Struct fields in 'filters' argument are sorted alphabetically. Hence, when used with database connection, their values (or pointers to it) must be sorted as well.
func (*StructSQL) GetQueryDeleteById ¶
GetQueryDeleteById returns a DELETE query with WHERE condition on ID field.
func (*StructSQL) GetQueryDeleteReturningID ¶
func (h *StructSQL) GetQueryDeleteReturningID(filters map[string]interface{}, filterFieldsToInclude map[string]bool) string
GetQueryDelete return a DELETE query with WHERE condition built from 'filters' (field-value pairs) with RETURNING id. Struct fields in 'filters' argument are sorted alphabetically. Hence, when used with database connection, their values (or pointers to it) must be sorted as well.
func (StructSQL) GetQueryDropTable ¶
GetQueryDropTable returns a DROP TABLE query.
func (*StructSQL) GetQueryInsert ¶
GetQueryInsert returns an INSERT query. Columns in the INSERT query are ordered the same way as they are defined in the struct, eg. SELECT field1_column, field2_column, ... etc.
func (*StructSQL) GetQueryInsertOnConflictUpdate ¶
GetQueryInsertOnConflictUpdate returns an "upsert" query, which will INSERT data when it does not exist or UPDATE it otherwise. Columns in the query are ordered the same way as they are defined in the struct, eg. SELECT field1_column, field2_column, ... etc.
func (*StructSQL) GetQuerySelect ¶
func (h *StructSQL) GetQuerySelect(order []string, limit int, offset int, filters map[string]interface{}, orderFieldsToInclude map[string]bool, filterFieldsToInclude map[string]bool) string
GetQuerySelect returns a SELECT query with WHERE condition built from 'filters' (field-value pairs). Struct fields in 'filters' argument are sorted alphabetically. Hence, when used with database connection, their values (or pointers to it) must be sorted as well. Columns in the SELECT query are ordered the same way as they are defined in the struct, eg. SELECT field1_column, field2_column, ... etc.
func (*StructSQL) GetQuerySelectById ¶
GetQuerySelectById returns a SELECT query with WHERE condition on ID field. Columns in the SELECT query are ordered the same way as they are defined in the struct, eg. SELECT field1_column, field2_column, ... etc.
func (*StructSQL) GetQuerySelectCount ¶
func (h *StructSQL) GetQuerySelectCount(filters map[string]interface{}, filterFieldsToInclude map[string]bool) string
GetQuerySelectCount returns a SELECT COUNT(*) query to count rows with WHERE condition built from 'filters' (field-value pairs). Struct fields in 'filters' argument are sorted alphabetically. Hence, when used with database connection, their values (or pointers to it) must be sorted as well.
func (*StructSQL) GetQueryUpdate ¶
func (h *StructSQL) GetQueryUpdate(values map[string]interface{}, filters map[string]interface{}, valueFieldsToInclude map[string]bool, filterFieldsToInclude map[string]bool) string
GetQueryUpdate returns an UPDATE query where specified struct fields (columns) are updated and rows match specific WHERE condition built from 'filters' (field-value pairs). Struct fields in 'values' and 'filters' arguments, are sorted alphabetically. Hence, when used with database connection, their values (or pointers to it) must be sorted as well.
func (*StructSQL) GetQueryUpdateById ¶
GetQueryUpdateById returns an UPDATE query with WHERE condition on ID field. Columns in the UPDATE query are ordered the same way as they are defined in the struct, eg. SELECT field1_column, field2_column, ... etc.
func (*StructSQL) HasModificationFields ¶
HasModificationFields returns true if struct has all of the following int64 fields: CreatedAt, CreatedBy, LastModifiedAt, LastModifiedBy
type StructSQLOptions ¶
type StructSQLOptions struct { DatabaseTablePrefix string ForceName string TagName string Joined map[string]*StructSQL // In some cases, we might want to copy over tags from already existing StructSQL instance. Such is called Base in here. Base *StructSQL // When struct has a name like 'xx_yy' and it has joined structs, use 'xx' as a name for table and column names UseRootNameWhenJoinedPresent bool }