pgstmt

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 9 Imported by: 2

README

pgstmt

DSL SQL Builder

Experiment DO NOT use in production

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default any = defaultValue{}

Default use for insert default value

Functions

func All added in v0.8.7

func All(v any) any

All marks value as all($?)

func Any

func Any(v any) any

Any marks value as any($?)

func Arg

func Arg(v any) any

Arg marks value as argument to replace with $? when build query

func NotArg

func NotArg(v any) any

NotArg marks value as non-argument

func Raw added in v0.11.0

func Raw(v any) any

Raw marks value as raw sql without escape

Types

type Cond

type Cond interface {
	Op(field any, op string, value any)
	OpRaw(field any, op string, rawValue any)
	Eq(field, value any)
	EqRaw(field, rawValue any)
	Ne(field, value any)
	NeRaw(field, rawValue any)
	Lt(field, value any)
	LtRaw(field, rawValue any)
	Le(field, value any)
	LeRaw(field, rawValue any)
	Gt(field, value any)
	GtRaw(field, rawValue any)
	Ge(field, value any)
	GeRaw(field, rawValue any)
	Like(field, value any)
	LikeRaw(field, rawValue any)
	ILike(field, value any)
	ILikeRaw(field, rawValue any)
	In(field any, value ...any)
	InRaw(field any, value ...any)
	InSelect(field any, f func(b SelectStatement))
	NotIn(field any, value ...any)
	NotInRaw(field any, value ...any)
	IsNull(field any)
	IsNotNull(field any)

	Field(field any) CondOp
	Value(value any) CondOp

	Raw(sql string)
	Not(f func(b Cond))
	And(f func(b Cond))
	Or(f func(b Cond))
	Mode() CondMode
}

Cond is the condition builder

type CondMode

type CondMode interface {
	And()
	Or()
}

type CondOp added in v0.13.0

type CondOp interface {
	Op(op string) CondValue
	OpValues(op string) CondValues
	Eq() CondValue
	Ne() CondValue
	Lt() CondValue
	Le() CondValue
	Gt() CondValue
	Ge() CondValue
	Like() CondValue
	ILike() CondValue
	In() CondValues
	NotIn() CondValues
	IsNull()
	IsNotNull()
}

type CondValue added in v0.13.0

type CondValue interface {
	Value(value any)
	Raw(rawValue any)
	Field(field any)
}

type CondValues added in v0.13.0

type CondValues interface {
	Value(values ...any)
	Raw(rawValues ...any)
	Field(field any)
	Select(f func(b SelectStatement))
}

type ConflictAction added in v0.13.0

type ConflictAction interface {
	DoNothing()
	DoUpdate(f func(b UpdateStatement))
}

type ConflictTarget added in v0.13.0

type ConflictTarget interface {
	Index(target ...string)
	Where(f func(b Cond))
	OnConstraint(constraintName string)
}

type DeleteStatement

type DeleteStatement interface {
	From(table string)
	Where(f func(b Cond))
	Returning(col ...string)
}

type Distinct added in v0.8.2

type Distinct interface {
	On(col ...string)
}

type InsertStatement

type InsertStatement interface {
	Into(table string)
	Columns(col ...string)
	OverridingSystemValue()
	OverridingUserValue()
	DefaultValues()
	Value(value ...any)
	Values(values ...[]any)
	Select(f func(b SelectStatement))

	OnConflict(f func(b ConflictTarget)) ConflictAction

	// OnConflictDoNothing is the shortcut for
	// OnConflict(func(b ConflictTarget) {}).DoNothing()
	OnConflictDoNothing()

	// OnConflictIndex is the shortcut for
	// OnConflict(func(b ConflictTarget) {
	//		b.Index(target...)
	// })
	OnConflictIndex(target ...string) ConflictAction

	// OnConflictOnConstraint is the shortcut for
	// OnConflict(func(b ConflictTarget) {
	//		b.OnConstraint(constraintName)
	// })
	OnConflictOnConstraint(constraintName string) ConflictAction

	Returning(col ...string)
}

InsertStatement is the insert statement builder

type Join

type Join interface {
	On(f func(b Cond))
	Using(col ...string)
}

type OrderBy

type OrderBy interface {
	Asc() OrderBy
	Desc() OrderBy
	NullsFirst() OrderBy
	NullsLast() OrderBy
}

type Result

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

func Delete

func Delete(f func(b DeleteStatement)) *Result

Delete builds delete statement

func Insert

func Insert(f func(b InsertStatement)) *Result

Insert builds insert statement

func Select

func Select(f func(b SelectStatement)) *Result

Select builds select statement

func Union added in v0.11.0

func Union(f func(b UnionStatement)) *Result

func Update

func Update(f func(b UpdateStatement)) *Result

Update builds update statement

func (*Result) Exec

func (r *Result) Exec(f func(string, ...any) (sql.Result, error)) (sql.Result, error)

func (*Result) ExecContext

func (r *Result) ExecContext(ctx context.Context, f func(context.Context, string, ...any) (sql.Result, error)) (sql.Result, error)

func (*Result) ExecWith

func (r *Result) ExecWith(ctx context.Context) (sql.Result, error)

func (*Result) IterWith

func (r *Result) IterWith(ctx context.Context, iter pgsql.Iterator) error

func (*Result) Query

func (r *Result) Query(f func(string, ...any) (*sql.Rows, error)) (*pgsql.Rows, error)

func (*Result) QueryContext

func (r *Result) QueryContext(ctx context.Context, f func(context.Context, string, ...any) (*sql.Rows, error)) (*pgsql.Rows, error)

func (*Result) QueryRow

func (r *Result) QueryRow(f func(string, ...any) *sql.Row) *pgsql.Row

func (*Result) QueryRowContext

func (r *Result) QueryRowContext(ctx context.Context, f func(context.Context, string, ...any) *sql.Row) *pgsql.Row

func (*Result) QueryRowWith

func (r *Result) QueryRowWith(ctx context.Context) *pgsql.Row

func (*Result) QueryWith

func (r *Result) QueryWith(ctx context.Context) (*pgsql.Rows, error)

func (*Result) SQL

func (r *Result) SQL() (query string, args []any)

type SelectStatement

type SelectStatement interface {
	Distinct() Distinct
	Columns(col ...any)
	ColumnSelect(f func(b SelectStatement), as string)
	ColumnExists(f func(b SelectStatement))
	From(table ...string)
	FromSelect(f func(b SelectStatement), as string)
	FromValues(f func(b Values), as string)

	Join(table string) Join
	InnerJoin(table string) Join
	FullOuterJoin(table string) Join
	LeftJoin(table string) Join
	RightJoin(table string) Join

	JoinSelect(f func(b SelectStatement), as string) Join
	InnerJoinSelect(f func(b SelectStatement), as string) Join
	FullOuterJoinSelect(f func(b SelectStatement), as string) Join
	LeftJoinSelect(f func(b SelectStatement), as string) Join
	RightJoinSelect(f func(b SelectStatement), as string) Join

	JoinLateralSelect(f func(b SelectStatement), as string) Join
	InnerJoinLateralSelect(f func(b SelectStatement), as string) Join
	FullOuterJoinLateralSelect(f func(b SelectStatement), as string) Join
	LeftJoinLateralSelect(f func(b SelectStatement), as string) Join
	RightJoinLateralSelect(f func(b SelectStatement), as string) Join

	JoinUnion(f func(b UnionStatement), as string) Join
	InnerJoinUnion(f func(b UnionStatement), as string) Join
	FullOuterJoinUnion(f func(b UnionStatement), as string) Join
	LeftJoinUnion(f func(b UnionStatement), as string) Join
	RightJoinUnion(f func(b UnionStatement), as string) Join

	Where(f func(b Cond))
	GroupBy(col ...string)
	Having(f func(b Cond))
	OrderBy(col string) OrderBy
	Limit(n int64)
	Offset(n int64)
}

SelectStatement is the select statement builder

type Set

type Set interface {
	To(value ...any)
	ToRaw(rawValue ...any)
	Select(f func(b SelectStatement))
}

type UnionStatement added in v0.11.0

type UnionStatement interface {
	Select(f func(b SelectStatement))
	AllSelect(f func(b SelectStatement))
	Union(f func(b UnionStatement))
	AllUnion(f func(b UnionStatement))
	OrderBy(col string) OrderBy
	Limit(n int64)
	Offset(n int64)
}

type UpdateStatement

type UpdateStatement interface {
	Table(table string)
	Set(col ...string) Set
	From(table ...string)
	Join(table string) Join
	InnerJoin(table string) Join
	FullOuterJoin(table string) Join
	LeftJoin(table string) Join
	RightJoin(table string) Join
	Where(f func(b Cond))
	WhereCurrentOf(cursor string)
	Returning(col ...string)
}

type Values

type Values interface {
	Value(value ...any)
	Values(values ...[]any)
}

Jump to

Keyboard shortcuts

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