pgbuilder

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const PrimaryKey = "pk"

Variables

This section is empty.

Functions

func BatchDoList

func BatchDoList(db sqlx.DBExecutor, scanners ...DataList) (err error)

func ContextWithIgnoreDeletedAt

func ContextWithIgnoreDeletedAt(ctx context.Context) context.Context

func Excluded

func Excluded(f *builder.Column) builder.SqlExpr

func ExcludedFields

func ExcludedFields(fields ...*builder.Column) builder.Assignments

func FilterAdditions added in v1.6.0

func FilterAdditions(additions builder.Additions, filter func(a builder.Addition) bool) builder.Additions

func ToCondition

func ToCondition(db sqlx.DBExecutor, b ConditionBuilder) builder.SqlCondition

Types

type BuildSubExpr

type BuildSubExpr func() builder.SqlExpr

type Collection added in v1.7.0

type Collection struct {
	// contains filtered or unexported fields
}

func (*Collection) DoList added in v1.7.0

func (c *Collection) DoList(db sqlx.DBExecutor, pager *Pager, additions ...builder.Addition) error

func (*Collection) Init added in v1.7.0

func (c *Collection) Init(new func() interface{}, id func(v interface{}) interface{}, condition func(db sqlx.DBExecutor, ids []interface{}) builder.SqlCondition)

func (*Collection) New added in v1.7.0

func (c *Collection) New() interface{}

func (*Collection) Next added in v1.7.0

func (c *Collection) Next(v interface{}) error

func (*Collection) OnNext added in v1.7.0

func (c *Collection) OnNext(id interface{}, receivers ...Receiver)

func (*Collection) ToCondition added in v1.7.0

func (c *Collection) ToCondition(db sqlx.DBExecutor) builder.SqlCondition

type ConditionBuilder

type ConditionBuilder interface {
	ToCondition(db sqlx.DBExecutor) builder.SqlCondition
}

func AllOf added in v1.5.0

func AllOf(builders ...ConditionBuilder) ConditionBuilder

func ConditionBuilderBy added in v1.5.0

func ConditionBuilderBy(build func(db sqlx.DBExecutor) builder.SqlCondition) ConditionBuilder

func ConditionBuilderFromCondition

func ConditionBuilderFromCondition(c builder.SqlCondition) ConditionBuilder

func OneOf added in v1.5.0

func OneOf(builders ...ConditionBuilder) ConditionBuilder

func SubSelect added in v1.5.0

func SubSelect(target *builder.Column, subConditionBuilder SubConditionBuilder) ConditionBuilder

type CouldScan

type CouldScan interface {
	Scan(v interface{}) error
}

type Counter

type Counter interface {
	SetCount(i int)
}

type DataList

type DataList interface {
	sqlx.ScanIterator
	ConditionBuilder
	DoList(db sqlx.DBExecutor, pager *Pager, additions ...builder.Addition) error
}

type ModalAndWithQuery added in v1.1.0

type ModalAndWithQuery interface {
	builder.Model
	WithQuery(db sqlx.DBExecutor) builder.SqlExpr
}

func AsWithQuery added in v1.1.0

func AsWithQuery(model builder.Model, withQueryFn func(db sqlx.DBExecutor) builder.SqlExpr) ModalAndWithQuery

func AsWithRecursiveQuery added in v1.1.0

func AsWithRecursiveQuery(model builder.Model, withQueryFn func(db sqlx.DBExecutor) builder.SqlExpr) ModalAndWithQuery

type ModelWithCreatedAt

type ModelWithCreatedAt interface {
	builder.Model
	FieldCreatedAt() *builder.Column
}

type ModelWithDeletedAt

type ModelWithDeletedAt interface {
	builder.Model
	FieldDeletedAt() *builder.Column
}

type ModelWithPrimaryKey

type ModelWithPrimaryKey interface {
	builder.Model
	PrimaryKey() []string
}

type ModelWithUniqueIndexes

type ModelWithUniqueIndexes interface {
	builder.Model
	UniqueIndexes() builder.Indexes
}

type ModelWithUpdatedAt

type ModelWithUpdatedAt interface {
	builder.Model
	FieldUpdatedAt() *builder.Column
}

type Pager

type Pager struct {
	Size   int64 `name:"size,omitempty" in:"query" default:"10" validate:"@int64[-1,]"`
	Offset int64 `name:"offset,omitempty" in:"query" default:"0" validate:"@int64[0,]"`
}

type Receiver added in v1.7.0

type Receiver func(v interface{})

type RecordCollection

type RecordCollection struct {
	Columns *builder.Columns
	// contains filtered or unexported fields
}

func RecordCollectionBy

func RecordCollectionBy(collect func(rc *RecordCollection), columns ...*builder.Column) *RecordCollection

func RecordCollectionFrom

func RecordCollectionFrom(db sqlx.DBExecutor, model builder.Model, columnsCouldBeZeroValue ...*builder.Column) *RecordCollection

func RecordCollectionWith

func RecordCollectionWith(recordValues RecordValues, columns ...*builder.Column) *RecordCollection

func (*RecordCollection) AsAssignments

func (vc *RecordCollection) AsAssignments() builder.Assignments

func (*RecordCollection) IsNil

func (vc *RecordCollection) IsNil() bool

func (*RecordCollection) SetRecordValues

func (vc *RecordCollection) SetRecordValues(values ...interface{})

func (*RecordCollection) Values

func (vc *RecordCollection) Values() []interface{}

func (RecordCollection) WithExtendCol

func (vc RecordCollection) WithExtendCol(col *builder.Column, val interface{}) *RecordCollection

type RecordValues

type RecordValues []interface{}

type Stmt

type Stmt struct {
	// contains filtered or unexported fields
}

func Use

func Use(db sqlx.DBExecutor) *Stmt

func (*Stmt) Delete

func (s *Stmt) Delete(model builder.Model) *StmtDelete

func (*Stmt) ExprBy added in v1.1.0

func (s *Stmt) ExprBy(do func(ctx context.Context) *builder.Ex) builder.SqlExpr

func (*Stmt) Insert

func (s *Stmt) Insert() *StmtInsert

func (*Stmt) ReturningOf

func (s *Stmt) ReturningOf(expr builder.SqlExpr, target builder.SqlExpr) CouldScan

func (*Stmt) Select

func (s *Stmt) Select(target builder.SqlExpr) *StmtSelect

func (*Stmt) T

func (s *Stmt) T(model builder.Model) *builder.Table

func (*Stmt) Update

func (s *Stmt) Update(model builder.Model, modifiers ...string) *StmtUpdate

func (Stmt) With

func (s Stmt) With(model ModalAndWithQuery, others ...ModalAndWithQuery) *Stmt

type StmtDelete

type StmtDelete struct {
	// contains filtered or unexported fields
}

* [ WITH [ RECURSIVE ] with_query [, ...] ] DELETE FROM [ ONLY ] table_name [ * ] [ [ AS ] alias ]

[ USING using_list ]
[ WHERE condition | WHERE CURRENT OF cursor_name ]
[ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

func (*StmtDelete) Do

func (s *StmtDelete) Do() error

func (*StmtDelete) Ex

func (s *StmtDelete) Ex(ctx context.Context) *builder.Ex

func (StmtDelete) From

func (s StmtDelete) From(model builder.Model) *StmtDelete

func (*StmtDelete) IsNil

func (s *StmtDelete) IsNil() bool

func (*StmtDelete) Returning

func (s *StmtDelete) Returning(target builder.SqlExpr) CouldScan

func (StmtDelete) Where

func (s StmtDelete) Where(where builder.SqlCondition) *StmtDelete

type StmtInsert

type StmtInsert struct {
	// contains filtered or unexported fields
}

* [ WITH [ RECURSIVE ] with_query [, ...] ] INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ]

[ OVERRIDING { SYSTEM | USER} VALUE ]
{ DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
[ ON CONFLICT [ conflict_target ] conflict_action ]
[ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

where conflict_target can be one of:

( { index_column_name | ( index_expression ) } [ COLLATE collation ] [ opclass ] [, ...] ) [ WHERE index_predicate ]
ON CONSTRAINT constraint_name

and conflict_action is one of:

DO NOTHING
DO UPDATE SET { column_name = { expression | DEFAULT } |
                ( column_name [, ...] ) = [ ROW ] ( { expression | DEFAULT } [, ...] ) |
                ( column_name [, ...] ) = ( sub-SELECT )
              } [, ...]
          [ WHERE condition ]

func (*StmtInsert) Do

func (s *StmtInsert) Do() error

func (*StmtInsert) Ex

func (s *StmtInsert) Ex(ctx context.Context) *builder.Ex

func (StmtInsert) Into

func (s StmtInsert) Into(model builder.Model, additions ...builder.Addition) *StmtInsert

func (*StmtInsert) IsNil

func (s *StmtInsert) IsNil() bool

func (StmtInsert) OnConflictDoNothing

func (s StmtInsert) OnConflictDoNothing(indexKey string) *StmtInsert

func (StmtInsert) OnConflictDoUpdateSet

func (s StmtInsert) OnConflictDoUpdateSet(indexKey string, excludedColumns ...*builder.Column) *StmtInsert

func (*StmtInsert) Returning

func (s *StmtInsert) Returning(target builder.SqlExpr) CouldScan

func (StmtInsert) ValuesBy

func (s StmtInsert) ValuesBy(collect func(vc *RecordCollection), columns ...*builder.Column) *StmtInsert

func (StmtInsert) ValuesFrom

func (s StmtInsert) ValuesFrom(model builder.Model, columnsCouldBeZeroValue ...*builder.Column) *StmtInsert

func (StmtInsert) ValuesWith

func (s StmtInsert) ValuesWith(recordValues RecordValues, columns ...*builder.Column) *StmtInsert

type StmtSelect

type StmtSelect struct {
	builder.SelectStatement
	// contains filtered or unexported fields
}

* [ WITH [ RECURSIVE ] with_query [, ...] ] SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]

[ * | expression [ [ AS ] output_name ] [, ...] ]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY grouping_element [, ...] ]
[ HAVING condition [, ...] ]
[ WINDOW window_name AS ( window_definition ) [, ...] ]
[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]
[ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]
[ LIMIT { count | ALL } ]
[ OFFSET start [ ROW | ROWS ] ]
[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]
[ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT | SKIP LOCKED ] [...] ]

where from_item can be one of:

[ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
            [ TABLESAMPLE sampling_method ( argument [, ...] ) [ REPEATABLE ( seed ) ] ]
[ LATERAL ] ( select ) [ AS ] alias [ ( column_alias [, ...] ) ]
with_query_name [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
[ LATERAL ] function_name ( [ argument [, ...] ] )
            [ WITH ORDINALITY ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
[ LATERAL ] function_name ( [ argument [, ...] ] ) [ AS ] alias ( column_definition [, ...] )
[ LATERAL ] function_name ( [ argument [, ...] ] ) AS ( column_definition [, ...] )
[ LATERAL ] ROWS FROM( function_name ( [ argument [, ...] ] ) [ AS ( column_definition [, ...] ) ] [, ...] )
            [ WITH ORDINALITY ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join_column [, ...] ) ]

and grouping_element can be one of:

( )
expression
( expression [, ...] )
ROLLUP ( { expression | ( expression [, ...] ) } [, ...] )
CUBE ( { expression | ( expression [, ...] ) } [, ...] )
GROUPING SETS ( grouping_element [, ...] )

and with_query is:

with_query_name [ ( column_name [, ...] ) ] AS ( select | values | insert | update | delete )

TABLE [ ONLY ] table_name [ * ]

func (StmtSelect) CrossJoin

func (s StmtSelect) CrossJoin(target builder.Model) *StmtSelect

func (*StmtSelect) Ex

func (s *StmtSelect) Ex(ctx context.Context) *builder.Ex

func (StmtSelect) From

func (s StmtSelect) From(model builder.Model) *StmtSelect

func (StmtSelect) FullJoin

func (s StmtSelect) FullJoin(target builder.Model, joinCondition builder.SqlCondition) *StmtSelect

func (*StmtSelect) IsNil

func (s *StmtSelect) IsNil() bool

func (StmtSelect) Join

func (s StmtSelect) Join(target builder.Model, joinCondition builder.SqlCondition) *StmtSelect

func (StmtSelect) LeftJoin

func (s StmtSelect) LeftJoin(target builder.Model, joinCondition builder.SqlCondition) *StmtSelect

func (*StmtSelect) List

func (s *StmtSelect) List(list sqlx.ScanIterator, pager *Pager) error

func (StmtSelect) RightJoin

func (s StmtSelect) RightJoin(target builder.Model, joinCondition builder.SqlCondition) *StmtSelect

func (*StmtSelect) Scan

func (s *StmtSelect) Scan(v interface{}) error

func (StmtSelect) Where

func (s StmtSelect) Where(where builder.SqlCondition, additions ...builder.Addition) *StmtSelect

type StmtUpdate

type StmtUpdate struct {
	// contains filtered or unexported fields
}

* [ WITH [ RECURSIVE ] with_query [, ...] ] UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]

SET { column_name = { expression | DEFAULT } |
      ( column_name [, ...] ) = [ ROW ] ( { expression | DEFAULT } [, ...] ) |
      ( column_name [, ...] ) = ( sub-SELECT )
    } [, ...]
[ FROM from_list ]
[ WHERE condition | WHERE CURRENT OF cursor_name ]
[ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

func (*StmtUpdate) Do

func (s *StmtUpdate) Do() error

func (*StmtUpdate) Ex

func (s *StmtUpdate) Ex(ctx context.Context) *builder.Ex

func (StmtUpdate) From added in v1.3.0

func (s StmtUpdate) From(from builder.Model) *StmtUpdate

func (*StmtUpdate) IsNil

func (s *StmtUpdate) IsNil() bool

func (*StmtUpdate) Returning

func (s *StmtUpdate) Returning(target builder.SqlExpr) CouldScan

func (StmtUpdate) SetBy

func (s StmtUpdate) SetBy(collect func(vc *RecordCollection), columns ...*builder.Column) *StmtUpdate

func (StmtUpdate) SetFrom

func (s StmtUpdate) SetFrom(model builder.Model, columnsCouldBeZeroValue ...*builder.Column) *StmtUpdate

func (StmtUpdate) SetWith

func (s StmtUpdate) SetWith(recordValues RecordValues, columns ...*builder.Column) *StmtUpdate

func (StmtUpdate) Where

func (s StmtUpdate) Where(where builder.SqlCondition) *StmtUpdate

type StmtWith

type StmtWith struct {
	// contains filtered or unexported fields
}

func (*StmtWith) Ex

func (s *StmtWith) Ex(ctx context.Context) *builder.Ex

func (*StmtWith) IsNil

func (s *StmtWith) IsNil() bool

type SubConditionBuilder added in v1.5.0

type SubConditionBuilder interface {
	ConditionBuilder
	SelectFrom(db sqlx.DBExecutor) *StmtSelect
}

type WithCountExpr

type WithCountExpr interface {
	CountExpr(db sqlx.DBExecutor) builder.SqlExpr
}

type WithRecursive added in v1.1.0

type WithRecursive interface {
	// contains filtered or unexported methods
}

type WithTotal

type WithTotal struct {
	Total int `json:"total"`
}

func (*WithTotal) SetCount

func (c *WithTotal) SetCount(i int)

Jump to

Keyboard shortcuts

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