Documentation ¶
Overview ¶
Package qb has Query Builder for manipulate SQL-queryes & check in databases schema her parameters
Index ¶
- func SelectToMultidimension(sql string, args ...interface{}) (arrJSON []map[string]interface{}, err error)
- type ErrNotFoundParam
- type QBField
- type QBTable
- type QueryBuilder
- func (qb *QueryBuilder) AddArg(arg interface{}) *QueryBuilder
- func (qb *QueryBuilder) AddArgs(args ...interface{}) *QueryBuilder
- func (qb *QueryBuilder) AddTable(alias, name string) *QBTable
- func (qb *QueryBuilder) AddTables(names map[string]string) *QueryBuilder
- func (qb *QueryBuilder) AddUnion(union *QueryBuilder) *QueryBuilder
- func (qb *QueryBuilder) ConvertDataNotChangeType(rows *sql.Rows) (arrJSON []map[string]interface{}, err error)
- func (qb *QueryBuilder) ConvertDataToJson(rows *sql.Rows) (arrJSON []map[string]interface{}, err error)
- func (qb *QueryBuilder) FindTable(name string) *QBTable
- func (qb *QueryBuilder) GetDataSql() (rows *sql.Rows, err error)
- func (qb *QueryBuilder) GetFields() (schTable QBTable)
- func (qb *QueryBuilder) GetSelectToNotChangeBoolean() (arrJSON []map[string]interface{}, err error)
- func (qb *QueryBuilder) InnerJoin(alias, name, usingOrOn string) *QBTable
- func (qb *QueryBuilder) Join(alias, name, usingOrOn string) *QBTable
- func (qb *QueryBuilder) JoinTable(alias, name, join, usingOrOn string) *QBTable
- func (qb *QueryBuilder) LeftJoin(alias, name, usingOrOn string) *QBTable
- func (qb *QueryBuilder) PrintToLogs() string
- func (qb *QueryBuilder) RightJoin(alias, name, usingOrOn string) *QBTable
- func (qb *QueryBuilder) SelectRunFunc(onReadRow func(fields []*QBField) error) error
- func (qb *QueryBuilder) SelectToMultidimension() (arrJSON []map[string]interface{}, err error)
- func (qb *QueryBuilder) SetArgs(args ...interface{}) *QueryBuilder
- func (qb *QueryBuilder) SetWhere(where string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SelectToMultidimension ¶
func SelectToMultidimension(sql string, args ...interface{}) (arrJSON []map[string]interface{}, err error)
SelectToMultidimension - create qBuilder from sql-string, run & write result to map
Types ¶
type ErrNotFoundParam ¶
type ErrNotFoundParam struct {
Param string
}
ErrNotFoundParam for errors not found requared parameters
func (ErrNotFoundParam) Error ¶
func (err ErrNotFoundParam) Error() string
type QBField ¶
type QBField struct { Name string Alias string Schema *schema.FieldStructure Value sql.RawBytes SelectValues map[int]string Table *QBTable ChildQB *QueryBuilder SelectQB *QueryBuilder }
field in QB for incapsulate SQL & Schema propertyes may have children QB for getting data on child tables
func (QBField) GetNativeValue ¶
GetNativeValue возвращает значение поля типа соответствующего типы поля в БД
func (*QBField) GetSchema ¶
func (field *QBField) GetSchema() *schema.FieldStructure
GetSchema возвращает схему поля, взятую из БД
func (*QBField) GetSelectedValues ¶
func (field *QBField) GetSelectedValues()
GetSelectedValues записываем лист значений для поля, чтобы показывать список на форме
type QBTable ¶
type QBTable struct { Name string Alias string Join string Using string Fields map[string]*QBField // contains filtered or unexported fields }
table in QB for incapsulate SQL & Schema propertyes ha map columns as links field query
func (*QBTable) GetSchema ¶
func (table *QBTable) GetSchema() *schema.FieldsTable
GetSchema return DB schema from table
type QueryBuilder ¶
type QueryBuilder struct { Tables []*QBTable Args []interface{} Aliases []string Prepared *sql.Stmt PostParams map[string][]string Where, GroupBy, OrderBy, Limits string // may be defined outside // contains filtered or unexported fields }
inline SQL query recheck in DB Schema queryes tables&fields may be has parent - link to parent QB
func Create ¶
func Create(where, groupBy, orderBy string) *QueryBuilder
Create - constructor from some parameters
func CreateFromSQL ¶
func CreateFromSQL(sqlCommand string) *QueryBuilder
CreateFromSQL construct QueryBuilder from sql-query string
func (*QueryBuilder) AddArg ¶
func (qb *QueryBuilder) AddArg(arg interface{}) *QueryBuilder
addding arguments
func (*QueryBuilder) AddArgs ¶
func (qb *QueryBuilder) AddArgs(args ...interface{}) *QueryBuilder
func (*QueryBuilder) AddTable ¶
func (qb *QueryBuilder) AddTable(alias, name string) *QBTable
AddTable - add Table to list, returns object table
func (*QueryBuilder) AddTables ¶
func (qb *QueryBuilder) AddTables(names map[string]string) *QueryBuilder
AddTables adding table from map to list, returns qB
func (*QueryBuilder) AddUnion ¶
func (qb *QueryBuilder) AddUnion(union *QueryBuilder) *QueryBuilder
func (*QueryBuilder) ConvertDataNotChangeType ¶
func (qb *QueryBuilder) ConvertDataNotChangeType(rows *sql.Rows) (arrJSON []map[string]interface{}, err error)
ConvertDataNotChangeType - analog ConvertDataNotChange Not Convert BooleanType
func (*QueryBuilder) ConvertDataToJson ¶
func (qb *QueryBuilder) ConvertDataToJson(rows *sql.Rows) (arrJSON []map[string]interface{}, err error)
ConvertDataToJson return map data from query rows
func (*QueryBuilder) FindTable ¶
func (qb *QueryBuilder) FindTable(name string) *QBTable
FindTable search table by {name} in list
func (*QueryBuilder) GetDataSql ¶
func (qb *QueryBuilder) GetDataSql() (rows *sql.Rows, err error)
GetDataSql - run query (prepare is need) & return rows
func (*QueryBuilder) GetFields ¶
func (qb *QueryBuilder) GetFields() (schTable QBTable)
GetFields return Schema for render standart methods
func (*QueryBuilder) GetSelectToNotChangeBoolean ¶
func (qb *QueryBuilder) GetSelectToNotChangeBoolean() (arrJSON []map[string]interface{}, err error)
GetSelectToNotChangeBoolean Get rows not convert tinyInt fields
func (*QueryBuilder) InnerJoin ¶
func (qb *QueryBuilder) InnerJoin(alias, name, usingOrOn string) *QBTable
func (*QueryBuilder) Join ¶
func (qb *QueryBuilder) Join(alias, name, usingOrOn string) *QBTable
func (*QueryBuilder) JoinTable ¶
func (qb *QueryBuilder) JoinTable(alias, name, join, usingOrOn string) *QBTable
add table with join
func (*QueryBuilder) LeftJoin ¶
func (qb *QueryBuilder) LeftJoin(alias, name, usingOrOn string) *QBTable
func (*QueryBuilder) PrintToLogs ¶
func (qb *QueryBuilder) PrintToLogs() string
for compatabilies interface logsType
func (*QueryBuilder) RightJoin ¶
func (qb *QueryBuilder) RightJoin(alias, name, usingOrOn string) *QBTable
func (*QueryBuilder) SelectRunFunc ¶
func (qb *QueryBuilder) SelectRunFunc(onReadRow func(fields []*QBField) error) error
SelectRunFunc обход результатов запроса и передача callback func данных каждой строки для обработки
func (*QueryBuilder) SelectToMultidimension ¶
func (qb *QueryBuilder) SelectToMultidimension() (arrJSON []map[string]interface{}, err error)
SelectToMultidimension предназначен для получения данных в формате JSON
func (*QueryBuilder) SetArgs ¶
func (qb *QueryBuilder) SetArgs(args ...interface{}) *QueryBuilder