pgbuilder

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2019 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 ToCondition

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

Types

type BuildSubExpr

type BuildSubExpr func(s *Stmt, model builder.Model) builder.SqlExpr

type ConditionBuilder

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

func ConditionBuilderFromCondition

func ConditionBuilderFromCondition(c builder.SqlCondition) 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, conditionBuilder ConditionBuilder, pager *Pager, additions ...builder.Addition) error
}

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 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) 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 builder.Model, build BuildSubExpr) *StmtWith

func (*Stmt) WithRecursive

func (s *Stmt) WithRecursive(model builder.Model, build BuildSubExpr) *StmtWith

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

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

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

func (s *StmtWith) Do() error

func (*StmtWith) Ex

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

func (StmtWith) Exec

func (s StmtWith) Exec(statement func(stmt *Stmt, model ...builder.Model) builder.SqlExpr) *StmtWith

func (*StmtWith) IsNil

func (s *StmtWith) IsNil() bool

func (*StmtWith) Scan

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

func (StmtWith) With

func (s StmtWith) With(model builder.Model, build BuildSubExpr) *StmtWith

type WithCountExpr

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

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