sqlbuilder

package
v0.0.0-...-fbdf664 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 18 Imported by: 1

Documentation

Overview

+gengo:runtimedoc=false

Index

Constants

View Source
const (
	ToggleMultiTable    = "MultiTable"
	ToggleNeedAutoAlias = "NeedAlias"
	ToggleUseValues     = "UseValues"
	ToggleInProject     = "InProject"
)

Variables

View Source
var UpdateNeedLimitByWhere = errors.New("no where limit for update")

Functions

func Alias

func Alias(expr sqlfrag.Fragment, name string) sqlfrag.Fragment

func CompareAddition

func CompareAddition(a Addition, b Addition) int

func ContextWithToggles

func ContextWithToggles(ctx context.Context, toggles Toggles) context.Context

func GetColumnComputed

func GetColumnComputed(col Column) sqlfrag.Fragment

func GetColumnName

func GetColumnName(fieldName, tagValue string) string

func MatchColumn

func MatchColumn(col Column, name string) bool

func MultiMayAutoAlias

func MultiMayAutoAlias(columns ...sqlfrag.Fragment) sqlfrag.Fragment

func ResolveIndexNameAndMethod

func ResolveIndexNameAndMethod(n string) (name string, method string)

Types

type Addition

type Addition interface {
	sqlfrag.Fragment

	AdditionType() AdditionType
}

func Comment

func Comment(c string) Addition

func OrderBy

func OrderBy(orders ...Order) Addition

func Where

func Where(c sqlfrag.Fragment) Addition

type AdditionType

type AdditionType int
const (
	AdditionJoin AdditionType = iota
	AdditionWhere
	AdditionGroupBy
	AdditionCombination
	AdditionOrderBy
	AdditionOnConflict
	AdditionReturning
	AdditionLimit
	AdditionOther
	AdditionComment
)

type Additions

type Additions []Addition

func (Additions) Frag

func (additions Additions) Frag(ctx context.Context) iter.Seq2[string, []any]

func (Additions) IsNil

func (additions Additions) IsNil() bool

type Assignment

type Assignment interface {
	sqlfrag.Fragment

	SqlAssignment()
}

func ColumnsAndCollect

func ColumnsAndCollect(columnOrColumns sqlfrag.Fragment, seq iter.Seq[any]) Assignment

func ColumnsAndValues

func ColumnsAndValues(columnOrColumns sqlfrag.Fragment, values ...any) Assignment

type Assignments

type Assignments []Assignment

func (Assignments) Frag

func (assignments Assignments) Frag(ctx context.Context) iter.Seq2[string, []any]

func (Assignments) IsNil

func (assignments Assignments) IsNil() bool

type BuildSubQuery

type BuildSubQuery func(table Table) sqlfrag.Fragment

type ColOptionFunc

type ColOptionFunc func(c ColumnSetter)

func ColComputedBy

func ColComputedBy(aggregate sqlfrag.Fragment) ColOptionFunc

func ColDef

func ColDef(def ColumnDef) ColOptionFunc

func ColField

func ColField(fieldName string) ColOptionFunc

func ColTypeOf

func ColTypeOf(v any, tagValue string) ColOptionFunc

type Column

type Column interface {
	sqlfrag.Fragment

	Fragment(query string, args ...any) sqlfrag.Fragment
	Of(table Table) Column
	Name() string
	FieldName() string
}

func Col

func Col(name string, fns ...ColOptionFunc) Column

type ColumnCollection

type ColumnCollection interface {
	sqlfrag.Fragment

	ColumnSeq
	ColumnPicker

	Col(name string) Column
	AllCols() iter.Seq2[int, Column]

	Of(t Table) ColumnCollection
	Len() int
}

func Cols

func Cols(names ...string) ColumnCollection

func ColumnCollect

func ColumnCollect(cols iter.Seq[Column]) ColumnCollection

func PickColsByFieldNames

func PickColsByFieldNames(picker ColumnPicker, names ...string) ColumnCollection

type ColumnCollectionManger

type ColumnCollectionManger interface {
	AddCol(cols ...Column)
}

type ColumnDef

type ColumnDef = columndef.ColumnDef

func GetColumnDef

func GetColumnDef(col Column) ColumnDef

type ColumnPicker

type ColumnPicker interface {
	F(name string) Column
}

type ColumnSeq

type ColumnSeq interface {
	Cols() iter.Seq[Column]
}

type ColumnSetter

type ColumnSetter interface {
	SetFieldName(name string)
	SetColumnDef(def ColumnDef)
	SetComputed(computed sqlfrag.Fragment)
}

type ColumnValuer

type ColumnValuer[T any] func(v Column) sqlfrag.Fragment

+gengo:runtimedoc=false

func AsValue

func AsValue[T any](v TypedColumn[T]) ColumnValuer[T]

func Between

func Between[T comparable](leftValue T, rightValue T) ColumnValuer[T]

func Des

func Des[T any](v T) ColumnValuer[T]

func Eq

func Eq[T comparable](expect T) ColumnValuer[T]

func EqCol

func EqCol[T comparable](expect TypedColumn[T]) ColumnValuer[T]

func Gt

func Gt[T comparable](min T) ColumnValuer[T]

func Gte

func Gte[T comparable](min T) ColumnValuer[T]

func In

func In[T any](values ...T) ColumnValuer[T]

func Incr

func Incr[T any](v T) ColumnValuer[T]

func IsNotNull

func IsNotNull[T any]() ColumnValuer[T]

func IsNull

func IsNull[T any]() ColumnValuer[T]

func LeftLike

func LeftLike[T ~string](s T) ColumnValuer[T]

func Like

func Like[T ~string](s T) ColumnValuer[T]

func Lt

func Lt[T comparable](max T) ColumnValuer[T]

func Lte

func Lte[T comparable](max T) ColumnValuer[T]

func Neq

func Neq[T any](expect T) ColumnValuer[T]

func NeqCol

func NeqCol[T comparable](expect TypedColumn[T]) ColumnValuer[T]

func NotBetween

func NotBetween[T comparable](leftValue T, rightValue T) ColumnValuer[T]

func NotIn

func NotIn[T any](values ...T) ColumnValuer[T]

func NotLike

func NotLike[T ~string](s T) ColumnValuer[T]

func RightLike

func RightLike[T ~string](s T) ColumnValuer[T]

func Value

func Value[T any](v T) ColumnValuer[T]

type ColumnWithComputed

type ColumnWithComputed interface {
	Computed() sqlfrag.Fragment
}

type ColumnWithDef

type ColumnWithDef interface {
	Def() ColumnDef
}

type ColumnWrapper

type ColumnWrapper interface {
	Unwrap() Column
}

type CombinationAddition

type CombinationAddition interface {
	Addition

	All(stmtSelect SelectStatement) CombinationAddition
	Distinct(stmtSelect SelectStatement) CombinationAddition
}

func Expect

func Expect() CombinationAddition

func Intersect

func Intersect() CombinationAddition

func Union

func Union() CombinationAddition

type ComposedCondition

type ComposedCondition struct {
	SqlConditionMarker
	// contains filtered or unexported fields
}

func (*ComposedCondition) And

func (*ComposedCondition) Frag

func (c *ComposedCondition) Frag(ctx context.Context) iter.Seq2[string, []any]

func (*ComposedCondition) IsNil

func (c *ComposedCondition) IsNil() bool

func (*ComposedCondition) Or

func (*ComposedCondition) Xor

type Condition

type Condition struct {
	SqlConditionMarker
	// contains filtered or unexported fields
}

func AsCond

func AsCond(ex sqlfrag.Fragment) *Condition

func (*Condition) Frag

func (c *Condition) Frag(ctx context.Context) iter.Seq2[string, []any]

func (*Condition) IsNil

func (c *Condition) IsNil() bool

type DataTypeDescriber

type DataTypeDescriber interface {
	DataType(driverName string) string
}

type DeprecatedActions

type DeprecatedActions = columndef.DeprecatedActions

type Function

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

func AnyValue

func AnyValue(fragments ...sqlfrag.Fragment) *Function

func Avg

func Avg(fragments ...sqlfrag.Fragment) *Function

func Count

func Count(fragments ...sqlfrag.Fragment) *Function

func Distinct

func Distinct(fragments ...sqlfrag.Fragment) *Function

func First

func First(fragments ...sqlfrag.Fragment) *Function

func Func

func Func(name string, args ...sqlfrag.Fragment) *Function

func Last

func Last(fragments ...sqlfrag.Fragment) *Function

func Max

func Max(fragments ...sqlfrag.Fragment) *Function

func Min

func Min(fragments ...sqlfrag.Fragment) *Function

func Sum

func Sum(fragments ...sqlfrag.Fragment) *Function

func (*Function) Frag

func (f *Function) Frag(ctx context.Context) iter.Seq2[string, []any]

func (*Function) IsNil

func (f *Function) IsNil() bool

type GroupByAddition

type GroupByAddition interface {
	Addition

	Having(cond sqlfrag.Fragment) GroupByAddition
}

func GroupBy

func GroupBy(groups ...sqlfrag.Fragment) GroupByAddition

type IndexDefine

type IndexDefine struct {
	Kind              string
	Name              string
	Method            string
	ColNameAndOptions []string
}

func ParseIndexDefine

func ParseIndexDefine(def string) *IndexDefine

ParseIndexDefine @def index i_xxx/BTREE Name @def index i_xxx/GIST TEST/gist_trgm_ops

func (IndexDefine) ID

func (i IndexDefine) ID() string

type IndexOptionFunc

type IndexOptionFunc func(k *key)

func IndexColNameAndOptions

func IndexColNameAndOptions(colNameAndOptions ...string) IndexOptionFunc

func IndexUnique

func IndexUnique(unique bool) IndexOptionFunc

func IndexUsing

func IndexUsing(method string) IndexOptionFunc

type Indexes

type Indexes map[string][]string

type JoinAddition

type JoinAddition interface {
	Addition
	On(joinCondition sqlfrag.Fragment) JoinAddition
	Using(joinColumnList ...Column) JoinAddition
}

func CrossJoin

func CrossJoin(table sqlfrag.Fragment) JoinAddition

func FullJoin

func FullJoin(table sqlfrag.Fragment) JoinAddition

func InnerJoin

func InnerJoin(table sqlfrag.Fragment) JoinAddition

func Join

func Join(table sqlfrag.Fragment, prefixes ...string) JoinAddition

func LeftJoin

func LeftJoin(table sqlfrag.Fragment) JoinAddition

func RightJoin

func RightJoin(table sqlfrag.Fragment) JoinAddition

type Key

type Key interface {
	sqlfrag.Fragment

	Of(table Table) Key

	Name() string

	IsPrimary() bool
	IsUnique() bool

	ColumnSeq
}

func Index

func Index(name string, columns ColumnCollection, optFns ...IndexOptionFunc) Key

func PrimaryKey

func PrimaryKey(columns ColumnCollection, optFns ...IndexOptionFunc) Key

func UniqueIndex

func UniqueIndex(name string, columns ColumnCollection, optFns ...IndexOptionFunc) Key

type KeyCollection

type KeyCollection interface {
	KeyPicker
	KeySeq

	Of(t Table) KeyCollection
	Len() int
}

type KeyCollectionManager

type KeyCollectionManager interface {
	AddKey(keys ...Key)
}

type KeyDef

type KeyDef interface {
	Method() string
	ColNameAndOptions() []string
}

type KeyPicker

type KeyPicker interface {
	K(name string) Key
}

type KeySeq

type KeySeq interface {
	Keys() iter.Seq[Key]
}

type LimitAddition

type LimitAddition interface {
	Addition

	Offset(offset int64) LimitAddition
}

func Limit

func Limit(rowCount int64) LimitAddition

type Model

type Model = internal.Model

type ModelNewer

type ModelNewer[M Model] internal.ModelNewer[M]

type OnConflictAddition

type OnConflictAddition interface {
	Addition

	DoNothing() OnConflictAddition
	DoUpdateSet(assignments ...Assignment) OnConflictAddition
}

func OnConflict

func OnConflict(columns ColumnSeq) OnConflictAddition

type Order

type Order interface {
	sqlfrag.Fragment
	// contains filtered or unexported methods
}

func AscOrder

func AscOrder(target sqlfrag.Fragment) Order

func DescOrder

func DescOrder(target sqlfrag.Fragment) Order

type OtherAddition

type OtherAddition struct {
	sqlfrag.Fragment
}

func AsAddition

func AsAddition(fragment sqlfrag.Fragment) *OtherAddition

func ForUpdate

func ForUpdate() *OtherAddition

func (OtherAddition) AdditionType

func (OtherAddition) AdditionType() AdditionType

func (*OtherAddition) IsNil

func (a *OtherAddition) IsNil() bool

type ReturningAddition

type ReturningAddition interface {
	Addition
}

func Returning

func Returning(project sqlfrag.Fragment) ReturningAddition

type SelectStatement

type SelectStatement interface {
	sqlfrag.Fragment
	// contains filtered or unexported methods
}

type SqlCondition

type SqlCondition interface {
	sqlfrag.Fragment

	SqlConditionMarker
}

func And

func And(conditions ...sqlfrag.Fragment) SqlCondition

func EmptyCond

func EmptyCond() SqlCondition

func Or

func Or(conditions ...sqlfrag.Fragment) SqlCondition

func Xor

func Xor(conditions ...sqlfrag.Fragment) SqlCondition

type SqlConditionMarker

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

type StmtDelete

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

func Delete

func Delete() *StmtDelete

func (*StmtDelete) Frag

func (s *StmtDelete) Frag(ctx context.Context) iter.Seq2[string, []any]

func (StmtDelete) From

func (s StmtDelete) From(table Table, additions ...Addition) *StmtDelete

func (*StmtDelete) IsNil

func (s *StmtDelete) IsNil() bool

type StmtInsert

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

func Insert

func Insert(modifiers ...string) *StmtInsert

func (*StmtInsert) Frag

func (s *StmtInsert) Frag(ctx context.Context) iter.Seq2[string, []any]

func (StmtInsert) Into

func (s StmtInsert) Into(table Table, additions ...Addition) *StmtInsert

func (*StmtInsert) IsNil

func (s *StmtInsert) IsNil() bool

func (StmtInsert) Values

func (s StmtInsert) Values(cols ColumnCollection, values ...any) *StmtInsert

func (StmtInsert) ValuesCollect

func (s StmtInsert) ValuesCollect(cols ColumnCollection, seq iter.Seq[any]) *StmtInsert

type StmtSelect

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

func Select

func Select(sqlExpr sqlfrag.Fragment, modifiers ...sqlfrag.Fragment) *StmtSelect

func (*StmtSelect) Frag

func (s *StmtSelect) Frag(ctx context.Context) iter.Seq2[string, []any]

func (StmtSelect) From

func (s StmtSelect) From(table sqlfrag.Fragment, additions ...Addition) *StmtSelect

func (*StmtSelect) IsNil

func (s *StmtSelect) IsNil() bool

type StmtUpdate

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

func Update

func Update(table Table, modifiers ...string) *StmtUpdate

func (*StmtUpdate) Frag

func (s *StmtUpdate) Frag(ctx context.Context) iter.Seq2[string, []any]

func (StmtUpdate) From

func (s StmtUpdate) From(table Table, additions ...Addition) *StmtUpdate

func (*StmtUpdate) IsNil

func (s *StmtUpdate) IsNil() bool

func (StmtUpdate) Set

func (s StmtUpdate) Set(assignments ...Assignment) *StmtUpdate

func (StmtUpdate) SetBy

func (s StmtUpdate) SetBy(assignments iter.Seq[Assignment]) *StmtUpdate

func (StmtUpdate) Where

func (s StmtUpdate) Where(c sqlfrag.Fragment, additions ...Addition) *StmtUpdate

type Table

type Table interface {
	TableName() string

	KeyPicker
	KeySeq

	ColumnPicker
	ColumnSeq

	sqlfrag.Fragment
}

func GetColumnTable

func GetColumnTable(col Column) Table

func GetKeyTable

func GetKeyTable(key Key) Table

func T

func T(tableName string, tableDefinitions ...sqlfrag.Fragment) Table

func TableFromModel

func TableFromModel(model any) Table

type TableCanFragment

type TableCanFragment interface {
	Fragment(query string, args ...any) sqlfrag.Fragment

	// Deprecated
	// use Fragment instead
	Expr(query string, args ...any) sqlfrag.Fragment
}

type TableWithTableName

type TableWithTableName interface {
	WithTableName(name string) Table
}

type Tables

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

func (*Tables) Add

func (tables *Tables) Add(tabs ...Table)

func (Tables) Range

func (tables Tables) Range(cb func(tab Table, idx int) bool)

func (*Tables) Remove

func (tables *Tables) Remove(name string)

func (*Tables) Table

func (tables *Tables) Table(tableName string) Table

func (*Tables) TableNames

func (tables *Tables) TableNames() (names []string)

type Toggles

type Toggles map[string]bool

func TogglesFromContext

func TogglesFromContext(ctx context.Context) Toggles

func (Toggles) InjectContext

func (toggles Toggles) InjectContext(ctx context.Context) context.Context

func (Toggles) Is

func (toggles Toggles) Is(key string) bool

func (Toggles) Merge

func (toggles Toggles) Merge(next Toggles) Toggles

type TypedColumn

type TypedColumn[T any] interface {
	Column

	V(op ColumnValuer[T]) sqlfrag.Fragment
	By(ops ...ColumnValuer[T]) Assignment
}

func CastColumn

func CastColumn[T any](col Column, fns ...ColOptionFunc) TypedColumn[T]

func TypedCol

func TypedCol[T any](name string, fns ...ColOptionFunc) TypedColumn[T]

func TypedColOf

func TypedColOf[T any](t Table, name string) TypedColumn[T]

type WithColDescriptions

type WithColDescriptions interface {
	ColDescriptions() map[string][]string
}

type WithComments

type WithComments interface {
	Comments() map[string]string
}

type WithIndexes

type WithIndexes interface {
	Indexes() Indexes
}

type WithPrimaryKey

type WithPrimaryKey interface {
	PrimaryKey() []string
}

type WithRelations

type WithRelations interface {
	ColRelations() map[string][]string
}

type WithStmt

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

func With

func With(t Table, build BuildSubQuery, modifiers ...string) *WithStmt

func WithRecursive

func WithRecursive(t Table, build BuildSubQuery) *WithStmt

func (WithStmt) Exec

func (w WithStmt) Exec(statement func(tables ...Table) sqlfrag.Fragment) *WithStmt

func (*WithStmt) Frag

func (w *WithStmt) Frag(ctx context.Context) iter.Seq2[string, []any]

func (*WithStmt) IsNil

func (w *WithStmt) IsNil() bool

func (WithStmt) With

func (w WithStmt) With(t Table, build BuildSubQuery) *WithStmt

type WithTable

type WithTable interface {
	T() Table
}

type WithTableDescription

type WithTableDescription interface {
	TableDescription() []string
}

type WithUniqueIndexes

type WithUniqueIndexes interface {
	UniqueIndexes() Indexes
}

Directories

Path Synopsis
columndef
Package columndef GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Package columndef GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
+gengo:runtimedoc=false
+gengo:runtimedoc=false
Package structs GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Package structs GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE

Jump to

Keyboard shortcuts

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