qb

package
v1.0.339 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package qb has Query Builder for manipulate SQL-queryes & check in databases schema her parameters

Index

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

func (field QBField) GetNativeValue(tinyAsBool bool) interface{}

GetNativeValue возвращает значение поля типа соответствующего типы поля в БД

func (*QBField) GetSchema

func (field *QBField) GetSchema() *schema.FieldStructure

GetSchema возвращает схему поля, взятую из БД

func (*QBField) GetSelectedValues

func (field *QBField) GetSelectedValues()

GetSelectedValues записываем лист значений для поля, чтобы показывать список на форме

func (QBField) String

func (field QBField) String() string

String for compatabilies interface LogsType

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) AddField

func (table *QBTable) AddField(alias, name string) *QBTable

AddField add field and returns table object

func (*QBTable) AddFields

func (table *QBTable) AddFields(fields map[string]string) *QBTable

AddFields adding fieldsfrom map into qB

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 CreateEmpty

func CreateEmpty() *QueryBuilder

CreateEmpty construct empty QueryBuilder

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

func (*QueryBuilder) SetWhere

func (qb *QueryBuilder) SetWhere(where string)

replace where clause

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL