Documentation
¶
Index ¶
- Variables
- func Escaper(driverName string) names.Escaper
- func ModelToInsertData[T Model](model T, ignoreFields ...string) (columns []string, values []any)
- func ModelsToInsertData[T Model](models []T, ignoreFields ...string) (columns []string, values [][]any)
- func Placeholder(driverName string) builder.PlaceholderFormat
- func ScanCol[T any](row *sql.Rows, t T) error
- func ScanCols[T any](rows *sql.Rows, v *[]T) error
- func ScanModel[T Model](row *sql.Rows, m T) error
- func ScanModels[T Model](rows *sql.Rows, models *[]T) error
- type Config
- type DBProxy
- type DeleteStmt
- func (s *DeleteStmt) Exec(ctx context.Context) (rowsAffected int64, err error)
- func (s *DeleteStmt) From(from string) *DeleteStmt
- func (s *DeleteStmt) ID(id any) *DeleteStmt
- func (s *DeleteStmt) Limit(limit uint64) *DeleteStmt
- func (s *DeleteStmt) Offset(offset uint64) *DeleteStmt
- func (s *DeleteStmt) OrderBy(orderBys ...string) *DeleteStmt
- func (s *DeleteStmt) Prefix(sql string, args ...any) *DeleteStmt
- func (s *DeleteStmt) PrefixExpr(expr builder.Sqlizer) *DeleteStmt
- func (s *DeleteStmt) Suffix(sql string, args ...any) *DeleteStmt
- func (s *DeleteStmt) SuffixExpr(expr builder.Sqlizer) *DeleteStmt
- func (s *DeleteStmt) Where(pred any, args ...any) *DeleteStmt
- type Engine
- func (e *Engine) Close() error
- func (e *Engine) DriverName() string
- func (e *Engine) Escaper() names.Escaper
- func (e *Engine) Exec(ctx context.Context, query string, args ...any) (result sql.Result, err error)
- func (e *Engine) Exist(ctx context.Context, query string, args ...any) (exist bool, err error)
- func (e *Engine) Placeholder() builder.PlaceholderFormat
- func (e *Engine) Query(ctx context.Context, query string, args ...any) (rows *sql.Rows, err error)
- func (e *Engine) SupportsLastInsertId() bool
- func (e *Engine) SupportsReturning() bool
- func (e *Engine) TX(ctx context.Context, fn func(context.Context) error) error
- type Execer
- type FieldDescriptor
- type FieldFlag
- type FileDescriptor
- type Import
- type InsertStmt
- func (s *InsertStmt[T]) AddModel(model T) *InsertStmt[T]
- func (s *InsertStmt[T]) AddModels(models ...T) *InsertStmt[T]
- func (s *InsertStmt[T]) Columns(columns ...string) *InsertStmt[T]
- func (s *InsertStmt[T]) Exec(ctx context.Context) (rowsAffected int64, err error)
- func (s *InsertStmt[T]) Ignore() *InsertStmt[T]
- func (s *InsertStmt[T]) Prefix(sql string, args ...any) *InsertStmt[T]
- func (s *InsertStmt[T]) PrefixExpr(expr builder.Sqlizer) *InsertStmt[T]
- func (s *InsertStmt[T]) Suffix(sql string, args ...any) *InsertStmt[T]
- func (s *InsertStmt[T]) SuffixExpr(expr builder.Sqlizer) *InsertStmt[T]
- func (s *InsertStmt[T]) Values(values ...any) *InsertStmt[T]
- type JSONFieldWrapper
- type Logger
- type Model
- type ModelDescriptor
- type Option
- func WithConnMaxIdleTime(connMaxIdleTime time.Duration) Option
- func WithConnMaxLifetime(connMaxLifetime time.Duration) Option
- func WithEscaper(escaper names.Escaper) Option
- func WithLogger(logger Logger) Option
- func WithMaxIdleConns(maxIdleConns int) Option
- func WithMaxOpenConns(maxOpenConns int) Option
- func WithPlaceholderFormat(format builder.PlaceholderFormat) Option
- type Querier
- type QueryColStmt
- func (s *QueryColStmt[T]) AddColumn(column any, args ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Column(column any, args ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) CrossJoin(join string, rest ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Distinct() *QueryColStmt[T]
- func (s *QueryColStmt[T]) Find(ctx context.Context) ([]T, error)
- func (s *QueryColStmt[T]) From(from string) *QueryColStmt[T]
- func (s *QueryColStmt[T]) FromSelect(from *builder.SelectBuilder, alias string) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Get(ctx context.Context) (T, bool, error)
- func (s *QueryColStmt[T]) GroupBy(groupBys ...string) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Having(pred any, rest ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) InnerJoin(join string, rest ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Join(join string, rest ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) JoinClause(pred any, args ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) LeftJoin(join string, rest ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Limit(limit uint64) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Offset(offset uint64) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Options(options ...string) *QueryColStmt[T]
- func (s *QueryColStmt[T]) OrderBy(orderBys ...string) *QueryColStmt[T]
- func (s *QueryColStmt[T]) OrderByClause(pred any, args ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Prefix(sql string, args ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) PrefixExpr(expr builder.Sqlizer) *QueryColStmt[T]
- func (s *QueryColStmt[T]) RemoveColumns() *QueryColStmt[T]
- func (s *QueryColStmt[T]) RemoveLimit() *QueryColStmt[T]
- func (s *QueryColStmt[T]) RemoveOffset() *QueryColStmt[T]
- func (s *QueryColStmt[T]) RightJoin(join string, rest ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Select(columns ...string) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Suffix(sql string, args ...any) *QueryColStmt[T]
- func (s *QueryColStmt[T]) SuffixExpr(expr builder.Sqlizer) *QueryColStmt[T]
- func (s *QueryColStmt[T]) Where(pred any, args ...any) *QueryColStmt[T]
- type QueryModelStmt
- func (s *QueryModelStmt[T]) AddColumn(column any, args ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Column(column any, args ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) CrossJoin(join string, rest ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Distinct() *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Exist(ctx context.Context) (bool, error)
- func (s *QueryModelStmt[T]) Find(ctx context.Context) ([]T, error)
- func (s *QueryModelStmt[T]) From(from string) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) FromSelect(from *builder.SelectBuilder, alias string) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Get(ctx context.Context) (T, error)
- func (s *QueryModelStmt[T]) GroupBy(groupBys ...string) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Having(pred any, rest ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) ID(id any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) InnerJoin(join string, rest ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Join(join string, rest ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) JoinClause(pred any, args ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) LeftJoin(join string, rest ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Limit(limit uint64) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Offset(offset uint64) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Options(options ...string) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) OrderBy(orderBys ...string) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) OrderByClause(pred any, args ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Page(ctx context.Context, page, size uint64) ([]T, uint64, error)
- func (s *QueryModelStmt[T]) Prefix(sql string, args ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) PrefixExpr(expr builder.Sqlizer) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) RemoveColumns() *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) RemoveLimit() *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) RemoveOffset() *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) RightJoin(join string, rest ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Select(columns ...string) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Suffix(sql string, args ...any) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) SuffixExpr(expr builder.Sqlizer) *QueryModelStmt[T]
- func (s *QueryModelStmt[T]) Where(pred any, args ...any) *QueryModelStmt[T]
- type Repository
- func (r *Repository[T]) Delete(ctx context.Context, id int64) (rowsAffected int64, err error)
- func (r *Repository[T]) DeleteByField(ctx context.Context, field string, value any) (rowsAffected int64, err error)
- func (r *Repository[T]) Exist(ctx context.Context, id int64) (bool, error)
- func (r *Repository[T]) ExistByField(ctx context.Context, field string, value any) (bool, error)
- func (r *Repository[T]) Get(ctx context.Context, id int64) (T, error)
- func (r *Repository[T]) GetByField(ctx context.Context, field string, value any) (T, error)
- func (r *Repository[T]) Insert(ctx context.Context, model T) (rowsAffected int64, err error)
- func (r *Repository[T]) InsertAll(ctx context.Context, models []T) (rowsAffected int64, err error)
- func (r *Repository[T]) InsertIgnore(ctx context.Context, model T) (rowsAffected int64, err error)
- func (r *Repository[T]) InsertIgnoreAll(ctx context.Context, models []T) (rowsAffected int64, err error)
- func (r *Repository[T]) Lock(ctx context.Context, id int64) (T, error)
- func (r *Repository[T]) LockByField(ctx context.Context, field string, value any) (T, error)
- func (r *Repository[T]) Update(ctx context.Context, model T) (rowsAffected int64, err error)
- func (r *Repository[T]) UpdateMap(ctx context.Context, id int64, data map[string]any) (rowsAffected int64, err error)
- type Table
- type TableName
- type UnimplementedModel
- type UnimplementedTable
- type UpdateStmt
- func (s *UpdateStmt[T]) Exec(ctx context.Context) (rowsAffected int64, err error)
- func (s *UpdateStmt[T]) ID(id any) *UpdateStmt[T]
- func (s *UpdateStmt[T]) Limit(limit uint64) *UpdateStmt[T]
- func (s *UpdateStmt[T]) Offset(offset uint64) *UpdateStmt[T]
- func (s *UpdateStmt[T]) OrderBy(orderBys ...string) *UpdateStmt[T]
- func (s *UpdateStmt[T]) Prefix(sql string, args ...any) *UpdateStmt[T]
- func (s *UpdateStmt[T]) PrefixExpr(expr builder.Sqlizer) *UpdateStmt[T]
- func (s *UpdateStmt[T]) Set(column string, value any) *UpdateStmt[T]
- func (s *UpdateStmt[T]) SetMap(clauses map[string]any) *UpdateStmt[T]
- func (s *UpdateStmt[T]) SetModel(t T) *UpdateStmt[T]
- func (s *UpdateStmt[T]) Suffix(sql string, args ...any) *UpdateStmt[T]
- func (s *UpdateStmt[T]) SuffixExpr(expr builder.Sqlizer) *UpdateStmt[T]
- func (s *UpdateStmt[T]) Table(table string) *UpdateStmt[T]
- func (s *UpdateStmt[T]) Where(pred any, args ...any) *UpdateStmt[T]
Constants ¶
This section is empty.
Variables ¶
var FlagTagMap = map[FieldFlag]string{ FlagPrimaryKey: "primary_key", FlagAutoIncrement: "auto_increment", FlagJson: "json", FlagCreated: "created", FlagUpdated: "updated", FlagVersion: "version", }
Functions ¶
func ModelToInsertData ¶
func ModelsToInsertData ¶
func Placeholder ¶
func Placeholder(driverName string) builder.PlaceholderFormat
Types ¶
type DeleteStmt ¶
type DeleteStmt struct {
// contains filtered or unexported fields
}
func Delete ¶
func Delete(engine *Engine) *DeleteStmt
func (*DeleteStmt) Exec ¶
func (s *DeleteStmt) Exec(ctx context.Context) (rowsAffected int64, err error)
func (*DeleteStmt) From ¶
func (s *DeleteStmt) From(from string) *DeleteStmt
func (*DeleteStmt) ID ¶
func (s *DeleteStmt) ID(id any) *DeleteStmt
func (*DeleteStmt) Limit ¶
func (s *DeleteStmt) Limit(limit uint64) *DeleteStmt
Limit sets a LIMIT clause on the query.
func (*DeleteStmt) Offset ¶
func (s *DeleteStmt) Offset(offset uint64) *DeleteStmt
Offset sets a OFFSET clause on the query.
func (*DeleteStmt) OrderBy ¶
func (s *DeleteStmt) OrderBy(orderBys ...string) *DeleteStmt
OrderBy adds ORDER BY expressions to the query.
func (*DeleteStmt) Prefix ¶
func (s *DeleteStmt) Prefix(sql string, args ...any) *DeleteStmt
Prefix adds an expression to the beginning of the query
func (*DeleteStmt) PrefixExpr ¶
func (s *DeleteStmt) PrefixExpr(expr builder.Sqlizer) *DeleteStmt
PrefixExpr adds an expression to the very beginning of the query
func (*DeleteStmt) Suffix ¶
func (s *DeleteStmt) Suffix(sql string, args ...any) *DeleteStmt
Suffix adds an expression to the end of the query
func (*DeleteStmt) SuffixExpr ¶
func (s *DeleteStmt) SuffixExpr(expr builder.Sqlizer) *DeleteStmt
SuffixExpr adds an expression to the end of the query
func (*DeleteStmt) Where ¶
func (s *DeleteStmt) Where(pred any, args ...any) *DeleteStmt
Where adds WHERE expressions to the query.
See SelectBuilder.Where for more information.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) DriverName ¶
func (*Engine) Placeholder ¶
func (e *Engine) Placeholder() builder.PlaceholderFormat
func (*Engine) SupportsLastInsertId ¶
SupportsLastInsertId returns true if the database driver supports LastInsertId
func (*Engine) SupportsReturning ¶
SupportsReturning returns true if the database driver supports RETURNING clause
type FieldDescriptor ¶
type FieldDescriptor struct {
Name string
FullName string
DBField string
Type string
Flag FieldFlag
}
FieldDescriptor stores field information
type FileDescriptor ¶
type FileDescriptor struct {
Path string
LormImportAlias string
Package string
Imports []*Import
Structs []*ModelDescriptor
}
func (*FileDescriptor) JsonMarshal ¶
func (d *FileDescriptor) JsonMarshal() string
func (*FileDescriptor) RawVarPrefix ¶
func (d *FileDescriptor) RawVarPrefix() string
type InsertStmt ¶
type InsertStmt[T Table] struct { // contains filtered or unexported fields }
func Insert ¶
func Insert[T Table](engine *Engine) *InsertStmt[T]
func (*InsertStmt[T]) AddModel ¶
func (s *InsertStmt[T]) AddModel(model T) *InsertStmt[T]
func (*InsertStmt[T]) AddModels ¶
func (s *InsertStmt[T]) AddModels(models ...T) *InsertStmt[T]
func (*InsertStmt[T]) Columns ¶
func (s *InsertStmt[T]) Columns(columns ...string) *InsertStmt[T]
func (*InsertStmt[T]) Exec ¶
func (s *InsertStmt[T]) Exec(ctx context.Context) (rowsAffected int64, err error)
func (*InsertStmt[T]) Ignore ¶
func (s *InsertStmt[T]) Ignore() *InsertStmt[T]
func (*InsertStmt[T]) Prefix ¶
func (s *InsertStmt[T]) Prefix(sql string, args ...any) *InsertStmt[T]
func (*InsertStmt[T]) PrefixExpr ¶
func (s *InsertStmt[T]) PrefixExpr(expr builder.Sqlizer) *InsertStmt[T]
func (*InsertStmt[T]) Suffix ¶
func (s *InsertStmt[T]) Suffix(sql string, args ...any) *InsertStmt[T]
func (*InsertStmt[T]) SuffixExpr ¶
func (s *InsertStmt[T]) SuffixExpr(expr builder.Sqlizer) *InsertStmt[T]
func (*InsertStmt[T]) Values ¶
func (s *InsertStmt[T]) Values(values ...any) *InsertStmt[T]
type JSONFieldWrapper ¶
type JSONFieldWrapper struct {
// contains filtered or unexported fields
}
func NewJSONFieldWrapper ¶
func NewJSONFieldWrapper(v any) *JSONFieldWrapper
func (*JSONFieldWrapper) MarshalJSON ¶
func (s *JSONFieldWrapper) MarshalJSON() ([]byte, error)
func (*JSONFieldWrapper) Scan ¶
func (s *JSONFieldWrapper) Scan(src any) error
func (*JSONFieldWrapper) String ¶
func (s *JSONFieldWrapper) String() string
func (*JSONFieldWrapper) UnmarshalJSON ¶
func (s *JSONFieldWrapper) UnmarshalJSON(data []byte) error
type Model ¶
type Model interface {
// New create a new model instance
New() Model
// LormFieldMap return field map, key is db field name, value is field value pointer
LormFieldMap() map[string]any
// LormModelDescriptor return db fields of this Model
LormModelDescriptor() *ModelDescriptor
// contains filtered or unexported methods
}
type ModelDescriptor ¶
type ModelDescriptor struct {
Name string
TableName string
Fields []*FieldDescriptor
}
ModelDescriptor stores struct information
func (*ModelDescriptor) AllFields ¶
func (m *ModelDescriptor) AllFields() []string
func (*ModelDescriptor) FlagFields ¶
func (m *ModelDescriptor) FlagFields(flag FieldFlag) []string
type Option ¶
type Option func(*Config)
func WithConnMaxIdleTime ¶
WithConnMaxIdleTime sets the maximum idle time of a connection
func WithConnMaxLifetime ¶
WithConnMaxLifetime sets the maximum lifetime of a connection
func WithMaxIdleConns ¶
WithMaxIdleConns sets the maximum number of idle connections
func WithMaxOpenConns ¶
WithMaxOpenConns sets the maximum number of open connections
func WithPlaceholderFormat ¶
func WithPlaceholderFormat(format builder.PlaceholderFormat) Option
WithPlaceholderFormat sets the placeholder format
type QueryColStmt ¶
type QueryColStmt[T any] struct { // contains filtered or unexported fields }
func QueryCol ¶
func QueryCol[T any](engine *Engine) *QueryColStmt[T]
func (*QueryColStmt[T]) AddColumn ¶
func (s *QueryColStmt[T]) AddColumn(column any, args ...any) *QueryColStmt[T]
AddColumn adds a result column to the query. Unlike Select, AddColumn accepts args which will be bound to placeholders in the columns string, for example:
AddColumn("IF(col IN ("+squirrel.Placeholders(3)+"), 1, 0) as col", 1, 2, 3)
func (*QueryColStmt[T]) Column ¶
func (s *QueryColStmt[T]) Column(column any, args ...any) *QueryColStmt[T]
Column adds a result column to the query. Unlike Select, Column accepts args which will be bound to placeholders in the columns string, for example:
AddColumn("IF(col IN ("+squirrel.Placeholders(3)+"), 1, 0) as col", 1, 2, 3)
func (*QueryColStmt[T]) CrossJoin ¶
func (s *QueryColStmt[T]) CrossJoin(join string, rest ...any) *QueryColStmt[T]
CrossJoin adds a CROSS JOIN clause to the query.
func (*QueryColStmt[T]) Distinct ¶
func (s *QueryColStmt[T]) Distinct() *QueryColStmt[T]
Distinct adds a DISTINCT clause to the query.
func (*QueryColStmt[T]) From ¶
func (s *QueryColStmt[T]) From(from string) *QueryColStmt[T]
From sets the FROM clause of the query.
func (*QueryColStmt[T]) FromSelect ¶
func (s *QueryColStmt[T]) FromSelect(from *builder.SelectBuilder, alias string) *QueryColStmt[T]
FromSelect sets a subquery into the FROM clause of the query.
func (*QueryColStmt[T]) GroupBy ¶
func (s *QueryColStmt[T]) GroupBy(groupBys ...string) *QueryColStmt[T]
GroupBy adds GROUP BY expressions to the query.
func (*QueryColStmt[T]) Having ¶
func (s *QueryColStmt[T]) Having(pred any, rest ...any) *QueryColStmt[T]
Having adds an expression to the HAVING clause of the query.
See Where.
func (*QueryColStmt[T]) InnerJoin ¶
func (s *QueryColStmt[T]) InnerJoin(join string, rest ...any) *QueryColStmt[T]
InnerJoin adds a INNER JOIN clause to the query.
func (*QueryColStmt[T]) Join ¶
func (s *QueryColStmt[T]) Join(join string, rest ...any) *QueryColStmt[T]
Join adds a JOIN clause to the query.
func (*QueryColStmt[T]) JoinClause ¶
func (s *QueryColStmt[T]) JoinClause(pred any, args ...any) *QueryColStmt[T]
JoinClause adds a join clause to the query.
func (*QueryColStmt[T]) LeftJoin ¶
func (s *QueryColStmt[T]) LeftJoin(join string, rest ...any) *QueryColStmt[T]
LeftJoin adds a LEFT JOIN clause to the query.
func (*QueryColStmt[T]) Limit ¶
func (s *QueryColStmt[T]) Limit(limit uint64) *QueryColStmt[T]
Limit sets a LIMIT clause on the query.
func (*QueryColStmt[T]) Offset ¶
func (s *QueryColStmt[T]) Offset(offset uint64) *QueryColStmt[T]
Offset sets a OFFSET clause on the query.
func (*QueryColStmt[T]) Options ¶
func (s *QueryColStmt[T]) Options(options ...string) *QueryColStmt[T]
Options adds select option to the query
func (*QueryColStmt[T]) OrderBy ¶
func (s *QueryColStmt[T]) OrderBy(orderBys ...string) *QueryColStmt[T]
OrderBy adds ORDER BY expressions to the query.
func (*QueryColStmt[T]) OrderByClause ¶
func (s *QueryColStmt[T]) OrderByClause(pred any, args ...any) *QueryColStmt[T]
OrderByClause adds ORDER BY clause to the query.
func (*QueryColStmt[T]) Prefix ¶
func (s *QueryColStmt[T]) Prefix(sql string, args ...any) *QueryColStmt[T]
Prefix adds an expression to the beginning of the query
func (*QueryColStmt[T]) PrefixExpr ¶
func (s *QueryColStmt[T]) PrefixExpr(expr builder.Sqlizer) *QueryColStmt[T]
PrefixExpr adds an expression to the very beginning of the query
func (*QueryColStmt[T]) RemoveColumns ¶
func (s *QueryColStmt[T]) RemoveColumns() *QueryColStmt[T]
RemoveColumns remove all columns from query. Must add a new column with Column or Select methods, otherwise return a error.
func (*QueryColStmt[T]) RemoveLimit ¶
func (s *QueryColStmt[T]) RemoveLimit() *QueryColStmt[T]
func (*QueryColStmt[T]) RemoveOffset ¶
func (s *QueryColStmt[T]) RemoveOffset() *QueryColStmt[T]
RemoveOffset removes OFFSET clause.
func (*QueryColStmt[T]) RightJoin ¶
func (s *QueryColStmt[T]) RightJoin(join string, rest ...any) *QueryColStmt[T]
RightJoin adds a RIGHT JOIN clause to the query.
func (*QueryColStmt[T]) Select ¶
func (s *QueryColStmt[T]) Select(columns ...string) *QueryColStmt[T]
Select set result columns to the query.
func (*QueryColStmt[T]) Suffix ¶
func (s *QueryColStmt[T]) Suffix(sql string, args ...any) *QueryColStmt[T]
Suffix adds an expression to the end of the query
func (*QueryColStmt[T]) SuffixExpr ¶
func (s *QueryColStmt[T]) SuffixExpr(expr builder.Sqlizer) *QueryColStmt[T]
SuffixExpr adds an expression to the end of the query
func (*QueryColStmt[T]) Where ¶
func (s *QueryColStmt[T]) Where(pred any, args ...any) *QueryColStmt[T]
Where adds an expression to the WHERE clause of the query.
Expressions are ANDed together in the generated SQL.
Where accepts several types for its pred argument:
nil OR "" - ignored.
string - SQL expression. If the expression has SQL placeholders then a set of arguments must be passed as well, one for each placeholder.
map[string]any OR Eq - map of SQL expressions to values. Each key is transformed into an expression like "<key> = ?", with the corresponding value bound to the placeholder. If the value is nil, the expression will be "<key> IS NULL". If the value is an array or slice, the expression will be "<key> IN (?,?,...)", with one placeholder for each item in the value. These expressions are ANDed together.
Where will panic if pred isn't any of the above types.
type QueryModelStmt ¶
type QueryModelStmt[T Model] struct { // contains filtered or unexported fields }
func Query ¶
func Query[T Model](engine *Engine) *QueryModelStmt[T]
func (*QueryModelStmt[T]) AddColumn ¶
func (s *QueryModelStmt[T]) AddColumn(column any, args ...any) *QueryModelStmt[T]
AddColumn adds a result column to the query. Unlike Select, AddColumn accepts args which will be bound to placeholders in the columns string, for example:
AddColumn("IF(col IN ("+squirrel.Placeholders(3)+"), 1, 0) as col", 1, 2, 3)
func (*QueryModelStmt[T]) Column ¶
func (s *QueryModelStmt[T]) Column(column any, args ...any) *QueryModelStmt[T]
Column adds a result column to the query. Unlike Select, Column accepts args which will be bound to placeholders in the columns string, for example:
AddColumn("IF(col IN ("+squirrel.Placeholders(3)+"), 1, 0) as col", 1, 2, 3)
func (*QueryModelStmt[T]) CrossJoin ¶
func (s *QueryModelStmt[T]) CrossJoin(join string, rest ...any) *QueryModelStmt[T]
CrossJoin adds a CROSS JOIN clause to the query.
func (*QueryModelStmt[T]) Distinct ¶
func (s *QueryModelStmt[T]) Distinct() *QueryModelStmt[T]
Distinct adds a DISTINCT clause to the query.
func (*QueryModelStmt[T]) Exist ¶
func (s *QueryModelStmt[T]) Exist(ctx context.Context) (bool, error)
func (*QueryModelStmt[T]) From ¶
func (s *QueryModelStmt[T]) From(from string) *QueryModelStmt[T]
From sets the FROM clause of the query.
func (*QueryModelStmt[T]) FromSelect ¶
func (s *QueryModelStmt[T]) FromSelect(from *builder.SelectBuilder, alias string) *QueryModelStmt[T]
FromSelect sets a subquery into the FROM clause of the query.
func (*QueryModelStmt[T]) GroupBy ¶
func (s *QueryModelStmt[T]) GroupBy(groupBys ...string) *QueryModelStmt[T]
GroupBy adds GROUP BY expressions to the query.
func (*QueryModelStmt[T]) Having ¶
func (s *QueryModelStmt[T]) Having(pred any, rest ...any) *QueryModelStmt[T]
Having adds an expression to the HAVING clause of the query.
See Where.
func (*QueryModelStmt[T]) ID ¶
func (s *QueryModelStmt[T]) ID(id any) *QueryModelStmt[T]
func (*QueryModelStmt[T]) InnerJoin ¶
func (s *QueryModelStmt[T]) InnerJoin(join string, rest ...any) *QueryModelStmt[T]
InnerJoin adds a INNER JOIN clause to the query.
func (*QueryModelStmt[T]) Join ¶
func (s *QueryModelStmt[T]) Join(join string, rest ...any) *QueryModelStmt[T]
Join adds a JOIN clause to the query.
func (*QueryModelStmt[T]) JoinClause ¶
func (s *QueryModelStmt[T]) JoinClause(pred any, args ...any) *QueryModelStmt[T]
JoinClause adds a join clause to the query.
func (*QueryModelStmt[T]) LeftJoin ¶
func (s *QueryModelStmt[T]) LeftJoin(join string, rest ...any) *QueryModelStmt[T]
LeftJoin adds a LEFT JOIN clause to the query.
func (*QueryModelStmt[T]) Limit ¶
func (s *QueryModelStmt[T]) Limit(limit uint64) *QueryModelStmt[T]
Limit sets a LIMIT clause on the query.
func (*QueryModelStmt[T]) Offset ¶
func (s *QueryModelStmt[T]) Offset(offset uint64) *QueryModelStmt[T]
Offset sets a OFFSET clause on the query.
func (*QueryModelStmt[T]) Options ¶
func (s *QueryModelStmt[T]) Options(options ...string) *QueryModelStmt[T]
Options adds select option to the query
func (*QueryModelStmt[T]) OrderBy ¶
func (s *QueryModelStmt[T]) OrderBy(orderBys ...string) *QueryModelStmt[T]
OrderBy adds ORDER BY expressions to the query.
func (*QueryModelStmt[T]) OrderByClause ¶
func (s *QueryModelStmt[T]) OrderByClause(pred any, args ...any) *QueryModelStmt[T]
OrderByClause adds ORDER BY clause to the query.
func (*QueryModelStmt[T]) Prefix ¶
func (s *QueryModelStmt[T]) Prefix(sql string, args ...any) *QueryModelStmt[T]
Prefix adds an expression to the beginning of the query
func (*QueryModelStmt[T]) PrefixExpr ¶
func (s *QueryModelStmt[T]) PrefixExpr(expr builder.Sqlizer) *QueryModelStmt[T]
PrefixExpr adds an expression to the very beginning of the query
func (*QueryModelStmt[T]) RemoveColumns ¶
func (s *QueryModelStmt[T]) RemoveColumns() *QueryModelStmt[T]
RemoveColumns remove all columns from query. Must add a new column with Column or Select methods, otherwise return a error.
func (*QueryModelStmt[T]) RemoveLimit ¶
func (s *QueryModelStmt[T]) RemoveLimit() *QueryModelStmt[T]
func (*QueryModelStmt[T]) RemoveOffset ¶
func (s *QueryModelStmt[T]) RemoveOffset() *QueryModelStmt[T]
RemoveOffset removes OFFSET clause.
func (*QueryModelStmt[T]) RightJoin ¶
func (s *QueryModelStmt[T]) RightJoin(join string, rest ...any) *QueryModelStmt[T]
RightJoin adds a RIGHT JOIN clause to the query.
func (*QueryModelStmt[T]) Select ¶
func (s *QueryModelStmt[T]) Select(columns ...string) *QueryModelStmt[T]
Select set result columns to the query.
func (*QueryModelStmt[T]) Suffix ¶
func (s *QueryModelStmt[T]) Suffix(sql string, args ...any) *QueryModelStmt[T]
Suffix adds an expression to the end of the query
func (*QueryModelStmt[T]) SuffixExpr ¶
func (s *QueryModelStmt[T]) SuffixExpr(expr builder.Sqlizer) *QueryModelStmt[T]
SuffixExpr adds an expression to the end of the query
func (*QueryModelStmt[T]) Where ¶
func (s *QueryModelStmt[T]) Where(pred any, args ...any) *QueryModelStmt[T]
Where adds an expression to the WHERE clause of the query.
Expressions are ANDed together in the generated SQL.
Where accepts several types for its pred argument:
nil OR "" - ignored.
string - SQL expression. If the expression has SQL placeholders then a set of arguments must be passed as well, one for each placeholder.
map[string]any OR Eq - map of SQL expressions to values. Each key is transformed into an expression like "<key> = ?", with the corresponding value bound to the placeholder. If the value is nil, the expression will be "<key> IS NULL". If the value is an array or slice, the expression will be "<key> IN (?,?,...)", with one placeholder for each item in the value. These expressions are ANDed together.
Where will panic if pred isn't any of the above types.
type Repository ¶
func NewRepository ¶
func NewRepository[T Table](engine *Engine) *Repository[T]
func (*Repository[T]) DeleteByField ¶
func (*Repository[T]) ExistByField ¶
func (*Repository[T]) GetByField ¶
func (*Repository[T]) Insert ¶
func (r *Repository[T]) Insert(ctx context.Context, model T) (rowsAffected int64, err error)
func (*Repository[T]) InsertAll ¶
func (r *Repository[T]) InsertAll(ctx context.Context, models []T) (rowsAffected int64, err error)
func (*Repository[T]) InsertIgnore ¶
func (r *Repository[T]) InsertIgnore(ctx context.Context, model T) (rowsAffected int64, err error)
func (*Repository[T]) InsertIgnoreAll ¶
func (r *Repository[T]) InsertIgnoreAll(ctx context.Context, models []T) (rowsAffected int64, err error)
func (*Repository[T]) LockByField ¶
type TableName ¶
type TableName interface {
TableName() string
}
TableName table name interface to define customerize table name
type UnimplementedModel ¶
type UnimplementedModel struct{}
type UnimplementedTable ¶
type UnimplementedTable struct{}
type UpdateStmt ¶
type UpdateStmt[T Table] struct { // contains filtered or unexported fields }
func Update ¶
func Update[T Table](engine *Engine) *UpdateStmt[T]
func (*UpdateStmt[T]) Exec ¶
func (s *UpdateStmt[T]) Exec(ctx context.Context) (rowsAffected int64, err error)
func (*UpdateStmt[T]) ID ¶
func (s *UpdateStmt[T]) ID(id any) *UpdateStmt[T]
func (*UpdateStmt[T]) Limit ¶
func (s *UpdateStmt[T]) Limit(limit uint64) *UpdateStmt[T]
Limit sets a LIMIT clause on the query.
func (*UpdateStmt[T]) Offset ¶
func (s *UpdateStmt[T]) Offset(offset uint64) *UpdateStmt[T]
Offset sets a OFFSET clause on the query.
func (*UpdateStmt[T]) OrderBy ¶
func (s *UpdateStmt[T]) OrderBy(orderBys ...string) *UpdateStmt[T]
OrderBy adds ORDER BY expressions to the query.
func (*UpdateStmt[T]) Prefix ¶
func (s *UpdateStmt[T]) Prefix(sql string, args ...any) *UpdateStmt[T]
Prefix adds an expression to the beginning of the query
func (*UpdateStmt[T]) PrefixExpr ¶
func (s *UpdateStmt[T]) PrefixExpr(expr builder.Sqlizer) *UpdateStmt[T]
PrefixExpr adds an expression to the very beginning of the query
func (*UpdateStmt[T]) Set ¶
func (s *UpdateStmt[T]) Set(column string, value any) *UpdateStmt[T]
Set adds SET clauses to the query.
func (*UpdateStmt[T]) SetMap ¶
func (s *UpdateStmt[T]) SetMap(clauses map[string]any) *UpdateStmt[T]
SetMap is a convenience method which calls .Set for each key/value pair in clauses.
func (*UpdateStmt[T]) SetModel ¶
func (s *UpdateStmt[T]) SetModel(t T) *UpdateStmt[T]
func (*UpdateStmt[T]) Suffix ¶
func (s *UpdateStmt[T]) Suffix(sql string, args ...any) *UpdateStmt[T]
Suffix adds an expression to the end of the query
func (*UpdateStmt[T]) SuffixExpr ¶
func (s *UpdateStmt[T]) SuffixExpr(expr builder.Sqlizer) *UpdateStmt[T]
SuffixExpr adds an expression to the end of the query
func (*UpdateStmt[T]) Table ¶
func (s *UpdateStmt[T]) Table(table string) *UpdateStmt[T]
func (*UpdateStmt[T]) Where ¶
func (s *UpdateStmt[T]) Where(pred any, args ...any) *UpdateStmt[T]
Where adds WHERE expressions to the query.
See SelectBuilder.Where for more information.