goql: github.com/rgamba/goql Index | Files

package goql

import "github.com/rgamba/goql"

Index

Package Files

goql.go

Variables

var Testing = false

Testing is a simple testing flag.

func Delete Uses

func Delete(Db interface{}, table string, obj interface{}) (sql.Result, error)

Delete function deletes the structure based on the pk tag of the attribute

func GetFieldPointers Uses

func GetFieldPointers(obj interface{}) []interface{}

GetFieldPointers is used to get the pointer position for the mapped parameters in a struct, useful for passing these pointers to a scanner function such as Db.Scan(db.GetFieldPointers(&a)...) NOTE that obj must be a pointer to the structure

func Insert Uses

func Insert(Db interface{}, table string, obj interface{}) (sql.Result, error)

Insert inserts a new record in a table The fields in the structure obj must be added the "db" tag in the declaration of the structure

func Update Uses

func Update(Db interface{}, table string, obj interface{}) (sql.Result, error)

Update updates a record. Note that this only works for atomic updates and not for massive updates. The field with primary tag will serve as update reference, in case there is no field with primary, the update will fail

type QueryBuilder Uses

type QueryBuilder struct {
    Sql string
    // The select by struct will add qb alias to the sql id added
    SelectAlias string
    // If set to true, the select will ignore fields with sql tag
    IgnoreDynamic bool
    // contains filtered or unexported fields
}

QueryBuilder is the main structure.

func (*QueryBuilder) Build Uses

func (qb *QueryBuilder) Build() string

Build generates the resulting SQL of the query builder

func (*QueryBuilder) BuildCount Uses

func (qb *QueryBuilder) BuildCount() string

BuildCount is the same as Build() with the difference that it ignores the values passed to Select() function and replaces it with COUNT(*)

func (*QueryBuilder) From Uses

func (qb *QueryBuilder) From(from string) (ret *QueryBuilder)

From tells the compiler where to load the results from (table name)

func (*QueryBuilder) GetValues Uses

func (qb *QueryBuilder) GetValues() []interface{}

GetValues gets the values passed to Where() in the second parameter. qb is used when building the query, for example: queryBuilder.Select("name").From("user").Where("id_user = $?", id) DB.QueryRow(queryBuilder.Build(), queryBuilder.GetValues()...)

func (*QueryBuilder) GroupBy Uses

func (qb *QueryBuilder) GroupBy(group string) (ret *QueryBuilder)

GroupBy for SQL GROUP BY

func (*QueryBuilder) Having Uses

func (qb *QueryBuilder) Having(having string) (ret *QueryBuilder)

Having performs having SQL statement

func (*QueryBuilder) InnerJoin Uses

func (qb *QueryBuilder) InnerJoin(from string) (ret *QueryBuilder)

InnerJoin is used if we want to user SQL joins Can be used multiple times each one for each join

func (*QueryBuilder) LeftJoin Uses

func (qb *QueryBuilder) LeftJoin(from string) (ret *QueryBuilder)

LeftJoin for building left joins

func (*QueryBuilder) Limit Uses

func (qb *QueryBuilder) Limit(limit string) (ret *QueryBuilder)

Limit is used for LIMIT SQL query

func (*QueryBuilder) OrderBy Uses

func (qb *QueryBuilder) OrderBy(order string) (ret *QueryBuilder)

OrderBy for SQL ORDER BY

func (*QueryBuilder) Query Uses

func (qb *QueryBuilder) Query(Db *sql.DB) (*sql.Rows, error)

Query is a shortcut for building the query, passing it to the DB driver and passing it the values

func (*QueryBuilder) QueryAndScan Uses

func (qb *QueryBuilder) QueryAndScan(Db *sql.DB, obj interface{}) error

QueryAndScan is used for executing a query and scanning it's result into the struct's parameters passed in obj.

func (*QueryBuilder) Select Uses

func (qb *QueryBuilder) Select(col interface{}) (ret *QueryBuilder)

Select selects the columns of the query col parameter must be either a string or a struct with at least one parameter with the "db" tag set

func (*QueryBuilder) Where Uses

func (qb *QueryBuilder) Where(where string, vals ...interface{}) (ret *QueryBuilder)

Where for filtering using WHERE sql statement Can be used multiple times for multiple filters IMPORTANT: wilcards MUST be passed as $? in the where string, for example: queryBuilder.Where("id = $?", myId)

type QueryStructInfo Uses

type QueryStructInfo struct {
    Positions        []string
    Fields           []string
    FieldsForUpdate  []string
    Values           []interface{}
    PrimaryKeys      string
    PrimaryKeyQuery  []string
    PrimaryKeyValues []interface{}
}

QueryStructInfo represents a parsed information that holds metadata of the object after parsing tags, position of each field and actual values of the structure in each field.

Package goql imports 8 packages (graph). Updated 2017-08-17. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).