assist

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 7 Imported by: 0

README

gorm-assist

gorm assist is an assist for gorm.

GoDoc Go.Dev reference codecov Tests Go Report Card Licence Tag

Usage

Installation

Use go get.

    go get github.com/things-go/gorm-assist

Then import the package into your own code.

    import "github.com/things-go/gorm-assist"
Example

Reference

License

This project is under MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPerPage 默认页大小
	DefaultPerPage = int64(50)
	// DefaultPageSize 默认最大页大小
	DefaultMaxPerPage = int64(500)
)
View Source
var All = Star
View Source
var One = NewRaw("1")

One a symbol of "1"

View Source
var Star = NewAsterisk("")

Star/All a symbol of "*"

Functions

func Indirect

func Indirect(value interface{}) reflect.Type

Indirect returns the value that v reflect.Type.

func IntoExpression

func IntoExpression(conds ...Expr) []clause.Expression

IntoExpression convert Expr to clause.Expression

func IntoIntegerSlice added in v0.0.6

func IntoIntegerSlice[T constraints.Integer, R constraints.Integer](values []T) []R

func IntoSlice added in v0.0.3

func IntoSlice[T any, R any](values []T, f func(T) R) []R

func Paginate

func Paginate(page, perPage int64, maxPerPages ...int64) clause.Expression

Paginate 分页器 分页索引: page >= 1 分页大小: perPage >= 1 && <= DefaultMaxPerPage

Types

type Asterisk

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

Asterisk a type of xxx.*

func NewAsterisk

func NewAsterisk(table string, opts ...Option) Asterisk

NewAsterisk new * field

func (Asterisk) AddCol

func (e Asterisk) AddCol(col Expr) Expr

AddCol use expr1 + expr2

func (Asterisk) As

func (e Asterisk) As(alias string) Expr

As use expr AS ?

func (Asterisk) Avg

func (e Asterisk) Avg() Float64

Avg use AVG(expr)

func (Asterisk) Build

func (e Asterisk) Build(builder clause.Builder)

func (Asterisk) BuildColumn

func (e Asterisk) BuildColumn(stmt *gorm.Statement, opts ...BuildOption) string

func (Asterisk) BuildWithArgs

func (e Asterisk) BuildWithArgs(stmt *gorm.Statement) (string, []any)

func (Asterisk) ColumnName

func (e Asterisk) ColumnName() string

func (Asterisk) ConcatCol

func (e Asterisk) ConcatCol(cols ...Expr) Expr

ConcatCol use CONCAT(expr1,exp2...exprN)

func (Asterisk) Count

func (a Asterisk) Count() Asterisk

Count use COUNT(expr)

func (Asterisk) Desc

func (e Asterisk) Desc() Expr

Desc use expr DESC

func (Asterisk) Distinct

func (a Asterisk) Distinct() Asterisk

Distinct use DISTINCT expr

func (Asterisk) DivCol

func (e Asterisk) DivCol(col Expr) Expr

DivCol use (expr1) / (expr2)

func (Asterisk) EqCol

func (e Asterisk) EqCol(col Expr) Expr

EqCol use expr1 = expr2

func (Asterisk) Expression

func (e Asterisk) Expression() clause.Expression

func (Asterisk) GroupConcat

func (e Asterisk) GroupConcat() Expr

GroupConcat use GROUP_CONCAT(expr)

func (Asterisk) GtCol

func (e Asterisk) GtCol(col Expr) Expr

GtCol use expr1 > expr2

func (Asterisk) GteCol

func (e Asterisk) GteCol(col Expr) Expr

GteCol use expr1 >= expr2

func (Asterisk) IsNotNull

func (e Asterisk) IsNotNull() Expr

IsNotNull use expr IS NOT NULL

func (Asterisk) IsNull

func (e Asterisk) IsNull() Expr

IsNull use expr IS NULL

func (Asterisk) Length

func (e Asterisk) Length() Int

Length use LENGTH(expr)

func (Asterisk) LtCol

func (e Asterisk) LtCol(col Expr) Expr

LtCol use expr1 < expr2

func (Asterisk) LteCol

func (e Asterisk) LteCol(col Expr) Expr

LteCol use expr1 <= expr2

func (Asterisk) Max

func (e Asterisk) Max() Float64

Max use MAX(expr)

func (Asterisk) Min

func (e Asterisk) Min() Float64

Min use MIN(expr)

func (Asterisk) MulCol

func (e Asterisk) MulCol(col Expr) Expr

MulCol use (expr1) * (expr2)

func (Asterisk) NeqCol

func (e Asterisk) NeqCol(col Expr) Expr

NeqCol use expr1 <> expr2

func (Asterisk) RawExpr

func (e Asterisk) RawExpr() expression

func (Asterisk) SubCol

func (e Asterisk) SubCol(col Expr) Expr

SubCol use expr1 - expr2

func (Asterisk) WithTable

func (e Asterisk) WithTable(table string) Expr

type Bool

type Bool Field

Bool boolean type field

func NewBool

func NewBool(table, column string, opts ...Option) Bool

NewBool new bool field.

func (Bool) And

func (field Bool) And(value bool) Expr

And use expr AND ?

func (Bool) BitAnd

func (field Bool) BitAnd(value bool) Expr

BitAnd use expr expr&?

func (Bool) BitOr

func (field Bool) BitOr(value bool) Expr

BitOr use expr expr|?

func (Bool) BitXor

func (field Bool) BitXor(value bool) Expr

BitXor use expr expr^?

func (Bool) Eq

func (field Bool) Eq(value bool) Expr

Eq equal to, use expr = ?

func (Bool) IfNull

func (field Bool) IfNull(value bool) Expr

IfNull use IFNULL(expr,?)

func (Bool) IntoColumns

func (field Bool) IntoColumns() Columns

IntoColumns columns array with sub method

func (Bool) Is

func (field Bool) Is(value bool) Expr

Is use expr = ?

func (Bool) Neq

func (field Bool) Neq(value bool) Expr

Neq not equal to, use expr <> ?

func (Bool) Not

func (field Bool) Not() Expr

Not use NOT expr

func (Bool) Or

func (field Bool) Or(value bool) Expr

Or use expr OR ?

func (Bool) Xor

func (field Bool) Xor(value bool) Expr

Xor use expr XOR ?

type BuildOption

type BuildOption uint

BuildOption build option

const (
	// WithTable build column with table
	WithTable BuildOption = iota

	// WithAll build column with table and alias(if have)
	WithAll

	// WithoutQuote build column without quote
	WithoutQuote
)

type Bytes

type Bytes Field

Bytes []byte type field

func NewBytes

func NewBytes(table, column string, opts ...Option) Bytes

NewBytes new bytes field.

func (Bytes) Between

func (field Bytes) Between(left []byte, right []byte) Expr

Between use expr BETWEEN ? AND ?

func (Bytes) Eq

func (field Bytes) Eq(value []byte) Expr

Eq equal to, use expr = ?

func (Bytes) FindInSet

func (field Bytes) FindInSet(targetList string) Expr

FindInSet FIND_IN_SET(field_name, input_string_list)

func (Bytes) FindInSetWith

func (field Bytes) FindInSetWith(target string) Expr

FindInSetWith FIND_IN_SET(input_string, field_name)

func (Bytes) FuzzyLike

func (field Bytes) FuzzyLike(value string) Expr

FuzzyLike use expr LIKE ?, ? contain prefix % and suffix % e.g. expr LIKE %value%

func (Bytes) Gt

func (field Bytes) Gt(value []byte) Expr

Gt greater than, use expr > ?

func (Bytes) Gte

func (field Bytes) Gte(value []byte) Expr

Gte greater or equal to, use expr >= ?

func (Bytes) IfNull

func (field Bytes) IfNull(value []byte) Expr

IfNull use IFNULL(expr,?)

func (Bytes) In

func (field Bytes) In(values ...[]byte) Expr

In use expr IN (?)

func (Bytes) IntoColumns

func (field Bytes) IntoColumns() Columns

IntoColumns columns array with sub method

func (Bytes) LeftLike

func (field Bytes) LeftLike(value string) Expr

LeftLike use expr LIKE ?, ? contain suffix %. e.g. expr LIKE value%

func (Bytes) Like

func (field Bytes) Like(value string) Expr

Like use expr LIKE ?

func (Bytes) Lt

func (field Bytes) Lt(value []byte) Expr

Lt less than, use expr < ?

func (Bytes) Lte

func (field Bytes) Lte(value []byte) Expr

Lte less or equal to, use expr <= ?

func (Bytes) Neq

func (field Bytes) Neq(value []byte) Expr

Neq not equal to, use expr <> ?

func (Bytes) NotBetween

func (field Bytes) NotBetween(left []byte, right []byte) Expr

NotBetween use NOT (expr BETWEEN ? AND ?)

func (Bytes) NotIn

func (field Bytes) NotIn(values ...[]byte) Expr

NotIn use expr NOT IN (?)

func (Bytes) NotLike

func (field Bytes) NotLike(value string) Expr

NotLike use expr NOT LIKE ?

func (Bytes) NotRegxp

func (field Bytes) NotRegxp(value string) Expr

NotRegxp use NOT expr REGEXP ?

func (Bytes) Regexp

func (field Bytes) Regexp(value string) Expr

Regexp use expr REGEXP ?

func (Bytes) SubstringIndex

func (field Bytes) SubstringIndex(delim string, count int) Bytes

SubstringIndex use SUBSTRING_INDEX(expr,?,?) https://dev.mysql.com/doc/refman/8.0/en/functions.html#function_substring-index

type Columns

type Columns []Expr

Columns columns array

func NewColumns

func NewColumns(cols ...Expr) Columns

NewColumns new columns instance.

func (Columns) Eq

func (cs Columns) Eq(subQuery *gorm.DB) Expr

Eq equivalent column = (subQuery)

func (Columns) Gt

func (cs Columns) Gt(subQuery *gorm.DB) Expr

Gt equivalent column > (subQuery)

func (Columns) Gte

func (cs Columns) Gte(subQuery *gorm.DB) Expr

Gte equivalent column >= (subQuery)

func (Columns) In

func (cs Columns) In(subQueryOrValue any) Expr

IN return contains subQuery or value when len(columns) == 1, equal to columns[0] IN (subQuery/value) when len(columns) > 1, equal to (columns[0], columns[1], ...) IN (subQuery/value)

func (Columns) Lt

func (cs Columns) Lt(subQuery *gorm.DB) Expr

Lt equivalent column < (subQuery)

func (Columns) Lte

func (cs Columns) Lte(subQuery *gorm.DB) Expr

Lte equivalent column <= (subQuery)

func (Columns) Neq

func (cs Columns) Neq(subQuery *gorm.DB) Expr

Neq equivalent column <> (subQuery)

func (Columns) NotIn

func (cs Columns) NotIn(subQueryOrValue any) Expr

IN return contains subQuery or value when len(columns) == 1, equal to NOT columns[0] IN (subQuery/value) when len(columns) > 1, equal to NOT (columns[0], columns[1], ...) IN (subQuery/value)

type Condition

type Condition = func(*gorm.DB) *gorm.DB

Condition alias func(*gorm.DB) *gorm.DB

func CrossJoins added in v0.0.8

func CrossJoins(tableName string, conds ...Expr) Condition

CrossJoins cross joins condition

func CrossJoinsX added in v0.0.8

func CrossJoinsX(tableName, alias string, conds ...Expr) Condition

CrossJoinsX cross joins condition

func Group

func Group(columns ...Expr) Condition

Group with field

func Having

func Having(columns ...Expr) Condition

Having with field

func InnerJoins added in v0.0.8

func InnerJoins(tableName string, conds ...Expr) Condition

InnerJoins inner joins condition

func InnerJoinsX added in v0.0.8

func InnerJoinsX(tableName, alias string, conds ...Expr) Condition

InnerJoinsX inner joins condition

func LeftJoins added in v0.0.8

func LeftJoins(tableName string, conds ...Expr) Condition

LeftJoins left join condition

func LeftJoinsX added in v0.0.8

func LeftJoinsX(tableName, alias string, conds ...Expr) Condition

LeftJoinsX left join condition

func LockingShare

func LockingShare() Condition

LockingShare specify the lock strength to SHARE

func LockingUpdate

func LockingUpdate() Condition

LockingUpdate specify the lock strength to UPDATE

func Order

func Order(columns ...Expr) Condition

Order with field

func Pagination

func Pagination(page, perPage int64, maxPerPages ...int64) Condition

Pagination 分页器 分页索引: page >= 1 分页大小: perPage >= 1 && <= DefaultMaxPerPage

func RightJoins added in v0.0.8

func RightJoins(tableName string, conds ...Expr) Condition

RightJoins right join condition

func RightJoinsX added in v0.0.8

func RightJoinsX(tableName, alias string, conds ...Expr) Condition

RightJoinsX right join condition

func Select

func Select(columns ...Expr) Condition

Select with field

func Table

func Table(fromSubs ...From) Condition

Table return a table produced by SubQuery.

func Where

func Where(columns ...Expr) Condition

Where with field

type Conditions

type Conditions []Condition

Conditions Condition slice

func NewConditions

func NewConditions(cs ...Condition) Conditions

NewConditions new condition instance.

func (Conditions) Append added in v0.0.2

func (c Conditions) Append(cs ...Condition) Conditions

Append more condition

func (Conditions) Build

func (c Conditions) Build() []Condition

Build into []Condition

func (Conditions) CrossJoins added in v0.0.8

func (c Conditions) CrossJoins(tableName string, conds ...Expr) Conditions

CrossJoins cross joins condition

func (Conditions) CrossJoinsX added in v0.0.8

func (c Conditions) CrossJoinsX(tableName, alias string, conds ...Expr) Conditions

CrossJoinsX cross joins condition

func (Conditions) Group

func (c Conditions) Group(columns ...Expr) Conditions

Group with field

func (Conditions) Having

func (c Conditions) Having(columns ...Expr) Conditions

Having with field

func (Conditions) InnerJoins added in v0.0.8

func (c Conditions) InnerJoins(tableName string, conds ...Expr) Conditions

InnerJoins inner joins condition

func (Conditions) InnerJoinsX added in v0.0.8

func (c Conditions) InnerJoinsX(tableName, alias string, conds ...Expr) Conditions

InnerJoinsX inner joins condition

func (Conditions) LeftJoins added in v0.0.8

func (c Conditions) LeftJoins(tableName string, conds ...Expr) Conditions

LeftJoins left join condition

func (Conditions) LeftJoinsX added in v0.0.8

func (c Conditions) LeftJoinsX(tableName, alias string, conds ...Expr) Conditions

LeftJoinsX left join condition

func (Conditions) LockingShare

func (c Conditions) LockingShare() Conditions

LockingShare specify the lock strength to SHARE

func (Conditions) LockingUpdate

func (c Conditions) LockingUpdate() Conditions

LockingUpdate specify the lock strength to UPDATE

func (Conditions) Order

func (c Conditions) Order(columns ...Expr) Conditions

Order with field

func (Conditions) Pagination

func (c Conditions) Pagination(page, perPage int64, maxPages ...int64) Conditions

Pagination 分页器 分页索引: page >= 1 分页大小: perPage >= 1 && <= DefaultMaxPerPage

func (Conditions) RightJoins added in v0.0.8

func (c Conditions) RightJoins(tableName string, conds ...Expr) Conditions

RightJoins right join condition

func (Conditions) RightJoinsX added in v0.0.8

func (c Conditions) RightJoinsX(tableName, alias string, conds ...Expr) Conditions

RightJoinsX right join condition

func (Conditions) Select

func (c Conditions) Select(columns ...Expr) Conditions

Select with field

func (Conditions) Table

func (c Conditions) Table(fromSubs ...From) Conditions

Table with field

func (Conditions) Where

func (c Conditions) Where(columns ...Expr) Conditions

Group with field

type Decimal

type Decimal = Float[string]

func NewDecimal

func NewDecimal(table, column string, opts ...Option) Decimal

NewDecimal new decimal field

type Expr

type Expr interface {
	clause.Expression

	As(alias string) Expr
	ColumnName() string
	Expression() clause.Expression
	RawExpr() expression
	BuildColumn(*gorm.Statement, ...BuildOption) string
	BuildWithArgs(*gorm.Statement) (query string, args []any)

	// col operate expression
	AddCol(col Expr) Expr
	SubCol(col Expr) Expr
	MulCol(col Expr) Expr
	DivCol(col Expr) Expr
	ConcatCol(cols ...Expr) Expr
}

Expr a query expression about field

func And

func And(exprs ...Expr) Expr

And return and condition form example: (`id1` AND `id2`)

func EmptyExpr

func EmptyExpr() Expr

EmptyExpr return a empty expression. it is nil

func Exist

func Exist(subQuery *gorm.DB) Expr

Exist equivalent EXISTS(subQuery)

func Not

func Not(exprs ...Expr) Expr

Not return not condition form example: (NOT `id1` AND NOT `id2`)

func NotExist

func NotExist(subQuery *gorm.DB) Expr

NotExist equivalent NOT EXISTS(subQuery)

func Or

func Or(exprs ...Expr) Expr

Or return or condition form example: (`id1` OR `id2`)

type Field

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

Field a standard field struct

func NewField

func NewField(table, column string, opts ...Option) Field

NewField new field

func (Field) Add

func (field Field) Add(value any) Field

Add use value type:

time.Duration: use DATE_ADD(expr, INTERVAL ? MICROSECOND)
other: use expr+?

func (Field) AddCol

func (e Field) AddCol(col Expr) Expr

AddCol use expr1 + expr2

func (Field) As

func (e Field) As(alias string) Expr

As use expr AS ?

func (Field) Avg

func (e Field) Avg() Float64

Avg use AVG(expr)

func (Field) Between

func (field Field) Between(left any, right any) Expr

Between use expr BETWEEN ? AND ?

func (Field) BitAnd

func (field Field) BitAnd(value any) Field

BitAnd use expr expr&?

func (Field) BitFlip

func (field Field) BitFlip() Field

BitFlip use expr ~expr

func (Field) BitOr

func (field Field) BitOr(value any) Field

BitOr use expr expr|?

func (Field) BitXor

func (field Field) BitXor(value any) Field

BitXor use expr expr^?

func (Field) Build

func (e Field) Build(builder clause.Builder)

func (Field) BuildColumn

func (e Field) BuildColumn(stmt *gorm.Statement, opts ...BuildOption) string

func (Field) BuildWithArgs

func (e Field) BuildWithArgs(stmt *gorm.Statement) (string, []any)

func (Field) ColumnName

func (e Field) ColumnName() string

func (Field) Concat

func (field Field) Concat(before, after string) String

Concat use CONCAT(?,?,?)

func (Field) ConcatCol

func (e Field) ConcatCol(cols ...Expr) Expr

ConcatCol use CONCAT(expr1,exp2...exprN)

func (Field) Count

func (e Field) Count() Int

Count use COUNT(expr)

func (Field) Date

func (field Field) Date() Time

Date use DATE(expr) return the date.

func (Field) DateDiff

func (field Field) DateDiff(expr2 time.Time) Int

DateDiff use DATEDIFF(expr1, expr2)

func (Field) DateFormat

func (field Field) DateFormat(format string) String

DateFormat use DATE_FORMAT(date,format)

func (Field) Day

func (field Field) Day() Int

Day use DAY(date) return the day.

func (Field) DayName

func (field Field) DayName() String

DayName use DAYNAME(date) return the name of the day of the week.

func (Field) DayOfMonth

func (field Field) DayOfMonth() Int

DayOfMonth use DAYOFMONTH(date)

func (Field) DayOfWeek

func (field Field) DayOfWeek() Int

DayOfWeek use DAYOFWEEK(date)

func (Field) DayOfYear

func (field Field) DayOfYear() Int

DayOfYear use DAYOFYEAR(date)

func (Field) Desc

func (e Field) Desc() Expr

Desc use expr DESC

func (Field) Distinct

func (e Field) Distinct() Int

Distinct use DISTINCT(expr)

func (Field) Div

func (field Field) Div(value any) Field

Div use expr/?

func (Field) DivCol

func (e Field) DivCol(col Expr) Expr

DivCol use (expr1) / (expr2)

func (Field) Eq

func (field Field) Eq(value any) Expr

Eq equal to, use expr = ?

func (Field) EqCol

func (e Field) EqCol(col Expr) Expr

EqCol use expr1 = expr2

func (Field) Expression

func (e Field) Expression() clause.Expression

func (Field) FindInSet

func (field Field) FindInSet(targetList string) Expr

FindInSet use FIND_IN_SET(field_name, input_string_list)

func (Field) FindInSetWith

func (field Field) FindInSetWith(target string) Expr

FindInSetWith use FIND_IN_SET(?, expr)

func (Field) Floor

func (field Field) Floor() Field

Floor se FLOOR(expr)

func (Field) FloorDiv

func (field Field) FloorDiv(value any) Field

FloorDiv use expr DIV ?

func (Field) FromDays

func (field Field) FromDays() Time

FromDays use FROM_DAYS(value)

func (Field) FromUnixTime

func (field Field) FromUnixTime(format ...string) String

FromUnixTime use FromUnixTime(unix_timestamp[, format])

func (Field) GroupConcat

func (e Field) GroupConcat() Expr

GroupConcat use GROUP_CONCAT(expr)

func (Field) Gt

func (field Field) Gt(value any) Expr

Gt greater than, use expr > ?

func (Field) GtCol

func (e Field) GtCol(col Expr) Expr

GtCol use expr1 > expr2

func (Field) Gte

func (field Field) Gte(value any) Expr

Gte greater or equal to, use expr >= ?

func (Field) GteCol

func (e Field) GteCol(col Expr) Expr

GteCol use expr1 >= expr2

func (Field) Hour

func (field Field) Hour() Int

Hour use HOUR(date) return the hour.

func (Field) IfNull

func (field Field) IfNull(value any) Expr

IfNull use IFNULL(expr,?)

func (Field) In

func (field Field) In(values ...any) Expr

In use expr IN (?)

func (Field) IntoColumns

func (field Field) IntoColumns() Columns

IntoColumns columns array with sub method

func (Field) IsNotNull

func (e Field) IsNotNull() Expr

IsNotNull use expr IS NOT NULL

func (Field) IsNull

func (e Field) IsNull() Expr

IsNull use expr IS NULL

func (Field) LTrim added in v0.0.7

func (field Field) LTrim(remStr string) String

LTrim use TRIM(LEADING ? FROM ?)

func (Field) LTrimSpace added in v0.0.7

func (field Field) LTrimSpace() String

LTrimSpace use LTRIM(?)

func (Field) LeftShift

func (field Field) LeftShift(value any) Field

LeftShift use expr<<?

func (Field) Length

func (e Field) Length() Int

Length use LENGTH(expr)

func (Field) Like

func (field Field) Like(value any) Expr

Like use expr LIKE ?

func (Field) Lt

func (field Field) Lt(value any) Expr

Lt less than, use expr < ?

func (Field) LtCol

func (e Field) LtCol(col Expr) Expr

LtCol use expr1 < expr2

func (Field) Lte

func (field Field) Lte(value any) Expr

Lte less or equal to, use expr <= ?

func (Field) LteCol

func (e Field) LteCol(col Expr) Expr

LteCol use expr1 <= expr2

func (Field) Max

func (e Field) Max() Float64

Max use MAX(expr)

func (Field) MicroSecond

func (field Field) MicroSecond() Int

MicroSecond use MICROSECOND(date) return the microsecond.

func (Field) Min

func (e Field) Min() Float64

Min use MIN(expr)

func (Field) Minute

func (field Field) Minute() Int

Minute use MINUTE(date) return the minute.

func (Field) Mod

func (field Field) Mod(value any) Field

Mod use expr%?

func (Field) Month

func (field Field) Month() Int

Month use MONTH(date) return the month.

func (Field) MonthName

func (field Field) MonthName() String

MonthName use MONTHNAME(date) return the name of the month of the year.

func (Field) Mul

func (field Field) Mul(value any) Field

Mul use expr*?

func (Field) MulCol

func (e Field) MulCol(col Expr) Expr

MulCol use (expr1) * (expr2)

func (Field) Neq

func (field Field) Neq(value any) Expr

Neq not equal to, use expr <> ?

func (Field) NeqCol

func (e Field) NeqCol(col Expr) Expr

NeqCol use expr1 <> expr2

func (Field) NotBetween

func (field Field) NotBetween(left any, right any) Expr

NotBetween use NOT (expr BETWEEN ? AND ?)

func (Field) NotIn

func (field Field) NotIn(values ...any) Expr

NotIn use expr NOT IN (?)

func (Field) NotLike

func (field Field) NotLike(value any) Expr

NotLike use expr NOT LIKE ?

func (Field) NotRegxp

func (field Field) NotRegxp(value string) Expr

NotRegxp use NOT expr REGEXP ?

func (Field) RTrim added in v0.0.7

func (field Field) RTrim(remStr string) String

RTrim use TRIM(TRAILING ? FROM ?)

func (Field) RTrimSpace added in v0.0.7

func (field Field) RTrimSpace() String

RTrimSpace use RTRIM(?)

func (Field) RawExpr

func (e Field) RawExpr() expression

func (Field) Regexp

func (field Field) Regexp(value any) Expr

Regexp use expr REGEXP ?

func (Field) Replace

func (field Field) Replace(from, to string) String

Replace use REPLACE(expr,?,?)

func (Field) RightShift

func (field Field) RightShift(value any) Field

RightShift use expr>>?

func (Field) Round

func (field Field) Round(decimals int) Field

Round use ROUND(expr, ?)

func (Field) Second

func (field Field) Second() Int

Second use SECOND(date) return the second.

func (Field) Sub

func (field Field) Sub(value any) Field

Sub use below value type:

time.Duration: use DATE_SUB(expr, INTERVAL ? MICROSECOND)
other: use expr-?

func (Field) SubCol

func (e Field) SubCol(col Expr) Expr

SubCol use expr1 - expr2

func (Field) SubstringIndex

func (field Field) SubstringIndex(delim string, count int) String

SubstringIndex use SUBSTRING_INDEX(expr,?,?) https://dev.mysql.com/doc/refman/8.0/en/functions.html#function_substring-index

func (Field) Sum

func (field Field) Sum() Field

Sum use SUM(expr)

func (Field) Trim added in v0.0.7

func (field Field) Trim(remStr string) String

Trim use TRIM(BOTH ? FROM ?)

func (Field) TrimSpace added in v0.0.7

func (field Field) TrimSpace() String

TrimSpace use TRIM(?)

func (Field) UnixTimestamp

func (field Field) UnixTimestamp() Int64

UnixTimestamp use UnixTimestamp(date)

func (Field) WithTable

func (e Field) WithTable(table string) Expr

func (Field) Year

func (field Field) Year() Int

Year use YEAR(date) return the year.

type Float

type Float[T constraints.Float | ~string] Field

Float type field

func NewFloat

func NewFloat[T constraints.Float | ~string](table, column string, opts ...Option) Float[T]

NewFloat new float field.

func (Float[T]) Add

func (field Float[T]) Add(value T) Float[T]

Add use expr+?

func (Float[T]) Between

func (field Float[T]) Between(left T, right T) Expr

Between use expr BETWEEN ? AND ?

func (Float[T]) Div

func (field Float[T]) Div(value T) Float[T]

Div use expr/?

func (Float[T]) Eq

func (field Float[T]) Eq(value T) Expr

Eq equal to, use expr = ?

func (Float[T]) Floor

func (field Float[T]) Floor() Int

Floor se FLOOR(expr)

func (Float[T]) FloorDiv

func (field Float[T]) FloorDiv(value T) Int

FloorDiv use expr DIV ?

func (Float[T]) Gt

func (field Float[T]) Gt(value T) Expr

Gt greater than, use expr > ?

func (Float[T]) Gte

func (field Float[T]) Gte(value T) Expr

Gte greater or equal to, use expr >= ?

func (Float[T]) IfNull

func (field Float[T]) IfNull(value T) Expr

IfNull use IFNULL(expr,?)

func (Float[T]) In

func (field Float[T]) In(values ...T) Expr

In use expr IN (?)

func (Float[T]) IntoColumns

func (field Float[T]) IntoColumns() Columns

IntoColumns columns array with sub method

func (Float[T]) Like

func (field Float[T]) Like(value T) Expr

Like use expr LIKE ?

func (Float[T]) Lt

func (field Float[T]) Lt(value T) Expr

Lt less than, use expr < ?

func (Float[T]) Lte

func (field Float[T]) Lte(value T) Expr

Lte less or equal to, use expr <= ?

func (Float[T]) Mul

func (field Float[T]) Mul(value T) Float[T]

Mul use expr*?

func (Float[T]) Neq

func (field Float[T]) Neq(value T) Expr

Neq not equal to, use expr <> ?

func (Float[T]) NotBetween

func (field Float[T]) NotBetween(left T, right T) Expr

NotBetween use NOT (expr BETWEEN ? AND ?).

func (Float[T]) NotIn

func (field Float[T]) NotIn(values ...T) Expr

NotIn use expr NOT IN (?)

func (Float[T]) NotLike

func (field Float[T]) NotLike(value T) Expr

NotLike use expr NOT LIKE ?

func (Float[T]) Round

func (field Float[T]) Round(decimals int) Float[T]

Round use ROUND(expr, ?)

func (Float[T]) Sub

func (field Float[T]) Sub(value T) Float[T]

Sub use expr-?

func (Float[T]) Sum

func (field Float[T]) Sum() Float[T]

Sum use SUM(expr)

type Float32

type Float32 = Float[float32]

func NewFloat32

func NewFloat32(table, column string, opts ...Option) Float32

NewFloat32 new float32 field

type Float64

type Float64 = Float[float64]

func NewFloat64

func NewFloat64(table, column string, opts ...Option) Float64

NewFloat64 new float64 field

type From

type From struct {
	Alias    string
	SubQuery *gorm.DB
}

From hold subQuery

type Int

type Int = Integer[int]

func NewInt

func NewInt(table, column string, opts ...Option) Int

NewField new int field

type Int16

type Int16 = Integer[int16]

func NewInt16

func NewInt16(table, column string, opts ...Option) Int16

NewField new int16 field

type Int32

type Int32 = Integer[int32]

func NewInt32

func NewInt32(table, column string, opts ...Option) Int32

NewField new int32 field

type Int64

type Int64 = Integer[int64]

func NewInt64

func NewInt64(table, column string, opts ...Option) Int64

NewField new int64 field

func UnixTimestamp

func UnixTimestamp(date ...string) Int64

UnixTimestamp use UNIX_TIMESTAMP([date])

type Int8

type Int8 = Integer[int8]

func NewInt8

func NewInt8(table, column string, opts ...Option) Int8

NewField new int8 field

type Integer

type Integer[T constraints.Integer] Field

Integer type field

func NewInteger

func NewInteger[T constraints.Integer](table, column string, opts ...Option) Integer[T]

NewInt new Integer

func (Integer[T]) Add

func (field Integer[T]) Add(value T) Integer[T]

Add use expr+?

func (Integer[T]) Between

func (field Integer[T]) Between(left T, right T) Expr

Between use expr BETWEEN ? AND ?

func (Integer[T]) BitAnd

func (field Integer[T]) BitAnd(value T) Integer[T]

BitAnd use expr expr&?

func (Integer[T]) BitFlip

func (field Integer[T]) BitFlip() Integer[T]

BitFlip use expr ~expr

func (Integer[T]) BitOr

func (field Integer[T]) BitOr(value T) Integer[T]

BitOr use expr expr|?

func (Integer[T]) BitXor

func (field Integer[T]) BitXor(value T) Integer[T]

BitXor use expr expr^?

func (Integer[T]) Div

func (field Integer[T]) Div(value T) Integer[T]

Div use expr/?

func (Integer[T]) Eq

func (field Integer[T]) Eq(value T) Expr

Eq equal to, use expr = ?

func (Integer[T]) FloorDiv

func (field Integer[T]) FloorDiv(value T) Integer[T]

FloorDiv use expr DIV ?

func (Integer[T]) FromDays

func (field Integer[T]) FromDays() Time

FromDays use FROM_DAYS(value)

func (Integer[T]) FromUnixTime

func (field Integer[T]) FromUnixTime(format ...string) String

FromUnixTime use FromUnixTime(unix_timestamp[, format])

func (Integer[T]) Gt

func (field Integer[T]) Gt(value T) Expr

Gt greater than, use expr > ?

func (Integer[T]) Gte

func (field Integer[T]) Gte(value T) Expr

Gte greater or equal to, use expr >= ?

func (Integer[T]) IfNull

func (field Integer[T]) IfNull(value T) Expr

IfNull use IFNULL(expr,?)

func (Integer[T]) In

func (field Integer[T]) In(values ...T) Expr

In use expr IN (?)

func (Integer[T]) IntoColumns

func (field Integer[T]) IntoColumns() Columns

IntoColumns columns array with sub method

func (Integer[T]) LeftShift

func (field Integer[T]) LeftShift(value T) Integer[T]

LeftShift use expr<<?

func (Integer[T]) Like

func (field Integer[T]) Like(value T) Expr

Like use expr LIKE ?

func (Integer[T]) Lt

func (field Integer[T]) Lt(value T) Expr

Lt less than, use expr < ?

func (Integer[T]) Lte

func (field Integer[T]) Lte(value T) Expr

Lte less or equal to, use expr <= ?

func (Integer[T]) Mod

func (field Integer[T]) Mod(value T) Integer[T]

Mod use expr%?

func (Integer[T]) Mul

func (field Integer[T]) Mul(value T) Integer[T]

Mul use expr*?

func (Integer[T]) Neq

func (field Integer[T]) Neq(value T) Expr

Neq not equal to, use expr <> ?

func (Integer[T]) NotBetween

func (field Integer[T]) NotBetween(left T, right T) Expr

NotBetween use NOT (expr BETWEEN ? AND ?)

func (Integer[T]) NotIn

func (field Integer[T]) NotIn(values ...T) Expr

NotIn use expr NOT IN (?)

func (Integer[T]) NotLike

func (field Integer[T]) NotLike(value T) Expr

NotLike use expr NOT LIKE ?

func (Integer[T]) RightShift

func (field Integer[T]) RightShift(value T) Integer[T]

RightShift use expr>>?

func (Integer[T]) Round

func (field Integer[T]) Round(value int) Integer[T]

Round use ROUND(expr, ?)

func (Integer[T]) Sub

func (field Integer[T]) Sub(value T) Integer[T]

Add use expr-?

func (Integer[T]) Sum

func (field Integer[T]) Sum() Integer[T]

Sum use SUM(expr)

type Option

type Option func(clause.Column) clause.Column

Option field option

type Raw

type Raw = Field

func NewRaw

func NewRaw(sql string, vars ...any) Raw

NewRaw new raw

type String

type String Field

String string type field

func FromUnixTime

func FromUnixTime(date int64, format ...string) String

FromUnixTime use FROM_UNIXTIME(unix_timestamp[,format])

func NewString

func NewString(table, column string, opts ...Option) String

NewString new string field.

func (String) Between

func (field String) Between(left, right string) Expr

Between use expr BETWEEN ? AND ?

func (String) Concat

func (field String) Concat(before, after string) String

Concat use CONCAT(?,?,?)

func (String) Eq

func (field String) Eq(value string) Expr

Eq equal to, use expr = ?

func (String) FindInSet

func (field String) FindInSet(targetList string) Expr

FindInSet equal to FIND_IN_SET(field_name, input_string_list)

func (String) FindInSetWith

func (field String) FindInSetWith(target string) Expr

FindInSetWith equal to FIND_IN_SET(input_string, field_name)

func (String) FuzzyLike

func (field String) FuzzyLike(value string) Expr

FuzzyLike use expr LIKE ?, ? contain prefix % and suffix % e.g. expr LIKE %value%

func (String) Gt

func (field String) Gt(value string) Expr

Gt greater than, use expr > ?

func (String) Gte

func (field String) Gte(value string) Expr

Gte greater or equal to, use expr >= ?

func (String) IfNull

func (field String) IfNull(value string) Expr

IfNull use IFNULL(expr,?)

func (String) In

func (field String) In(values ...string) Expr

In use expr IN (?)

func (String) IntoColumns

func (field String) IntoColumns() Columns

IntoColumns columns array with sub method

func (String) LTrim added in v0.0.7

func (field String) LTrim(remStr string) String

LTrim use TRIM(LEADING ? FROM ?)

func (String) LTrimSpace added in v0.0.7

func (field String) LTrimSpace() String

LTrimSpace use LTRIM(?)

func (String) LeftLike

func (field String) LeftLike(value string) Expr

LeftLike use expr LIKE ?, ? contain suffix %. e.g. expr LIKE value%

func (String) Like

func (field String) Like(value string) Expr

Like use expr LIKE ?

func (String) Lt

func (field String) Lt(value string) Expr

Lt less than, use expr < ?

func (String) Lte

func (field String) Lte(value string) Expr

Lte less or equal to, use expr <= ?

func (String) Neq

func (field String) Neq(value string) Expr

Neq not equal to, use expr <> ?

func (String) NotBetween

func (field String) NotBetween(left, right string) Expr

NotBetween use NOT (expr BETWEEN ? AND ?)

func (String) NotIn

func (field String) NotIn(values ...string) Expr

NotIn use expr NOT IN (?)

func (String) NotLike

func (field String) NotLike(value string) Expr

NotLike use expr NOT LIKE ?

func (String) NotRegxp

func (field String) NotRegxp(value string) Expr

NotRegxp use NOT expr REGEXP ?

func (String) RTrim added in v0.0.7

func (field String) RTrim(remStr string) String

RTrim use TRIM(TRAILING ? FROM ?)

func (String) RTrimSpace added in v0.0.7

func (field String) RTrimSpace() String

RTrimSpace use RTRIM(?)

func (String) Regexp

func (field String) Regexp(value string) Expr

Regexp use expr REGEXP ?

func (String) Replace

func (field String) Replace(from, to string) String

Replace use REPLACE(expr,?,?)

func (String) SubstringIndex

func (field String) SubstringIndex(delim string, count int) String

SubstringIndex use SUBSTRING_INDEX(expr,?,?) https://dev.mysql.com/doc/refman/8.0/en/functions.html#function_substring-index

func (String) Trim added in v0.0.7

func (field String) Trim(remStr string) String

Trim use TRIM(BOTH ? FROM ?)

func (String) TrimSpace added in v0.0.7

func (field String) TrimSpace() String

TrimSpace use TRIM(?)

type Time

type Time Field

Time time type field

func CurDate

func CurDate() Time

CurDate return result of CURDATE()

func CurTime

func CurTime() Time

CurTime return result of CURTIME()

func FromDays

func FromDays(value int) Time

FromDays equal to FROM_DAYS(value)

func NewTime

func NewTime(table, column string, opts ...Option) Time

NewTime bew time field

func Now

func Now() Time

Now return result of NOW()

func (Time) Add

func (field Time) Add(value time.Duration) Time

Add use DATE_ADD(date, INTERVAL ? MICROSECOND)

func (Time) Between

func (field Time) Between(left time.Time, right time.Time) Expr

Between use expr BETWEEN ? AND ?

func (Time) Date

func (field Time) Date() Time

Date use DATE(expr) return the date.

func (Time) DateDiff

func (field Time) DateDiff(expr2 time.Time) Int

DateDiff use DATEDIFF(expr1, expr2)

func (Time) DateFormat

func (field Time) DateFormat(format string) String

DateFormat use DATE_FORMAT(date,format)

func (Time) Day

func (field Time) Day() Int

Day use DAY(date) return the day.

func (Time) DayName

func (field Time) DayName() String

DayName use DAYNAME(date) return the name of the day of the week.

func (Time) DayOfMonth

func (field Time) DayOfMonth() Int

DayOfMonth use DAYOFMONTH(date)

func (Time) DayOfWeek

func (field Time) DayOfWeek() Int

DayOfWeek use DAYOFWEEK(date)

func (Time) DayOfYear

func (field Time) DayOfYear() Int

DayOfYear use DAYOFYEAR(date)

func (Time) Eq

func (field Time) Eq(value time.Time) Expr

Eq equal to, use expr = ?

func (Time) Gt

func (field Time) Gt(value time.Time) Expr

Gt greater than, use expr > ?

func (Time) Gte

func (field Time) Gte(value time.Time) Expr

Gte greater or equal to, use expr >= ?

func (Time) Hour

func (field Time) Hour() Int

Hour use HOUR(date) return the hour.

func (Time) IfNull

func (field Time) IfNull(value time.Time) Expr

IfNull use IFNULL(expr,?)

func (Time) In

func (field Time) In(values ...time.Time) Expr

In use expr IN (?)

func (Time) IntoColumns

func (field Time) IntoColumns() Columns

IntoColumns columns array with sub method

func (Time) Lt

func (field Time) Lt(value time.Time) Expr

Lt less than, use expr < ?

func (Time) Lte

func (field Time) Lte(value time.Time) Expr

Lte less or equal to, use expr <= ?

func (Time) MicroSecond

func (field Time) MicroSecond() Int

MicroSecond use MICROSECOND(date) return the microsecond.

func (Time) Minute

func (field Time) Minute() Int

Minute use MINUTE(date) return the minute.

func (Time) Month

func (field Time) Month() Int

Month use MONTH(date) return the month.

func (Time) MonthName

func (field Time) MonthName() String

MonthName use MONTHNAME(date) return the name of the month of the year.

func (Time) Neq

func (field Time) Neq(value time.Time) Expr

Neq not equal to, use expr <> ?

func (Time) NotBetween

func (field Time) NotBetween(left time.Time, right time.Time) Expr

NotBetween use NOT (expr BETWEEN ? AND ?)

func (Time) NotIn

func (field Time) NotIn(values ...time.Time) Expr

NotIn use expr NOT IN (?)

func (Time) Second

func (field Time) Second() Int

Second use SECOND(date) return the second.

func (Time) Sub

func (field Time) Sub(value time.Duration) Time

Sub use DATE_SUB(date, INTERVAL ? MICROSECOND)

func (Time) Sum

func (field Time) Sum() Time

Sum use SUM(expr)

func (Time) UnixTimestamp

func (field Time) UnixTimestamp() Int64

UnixTimestamp use UnixTimestamp(date)

func (Time) Year

func (field Time) Year() Int

Year use YEAR(date) return the year.

type Uint

type Uint = Integer[uint]

func NewUint

func NewUint(table, column string, opts ...Option) Uint

NewField new uint field

type Uint16

type Uint16 = Integer[uint16]

func NewUint16

func NewUint16(table, column string, opts ...Option) Uint16

NewField new uint16 field

type Uint32

type Uint32 = Integer[uint32]

func NewUint32

func NewUint32(table, column string, opts ...Option) Uint32

NewField new uint32 field

type Uint64

type Uint64 = Integer[uint64]

func NewUint64

func NewUint64(table, column string, opts ...Option) Uint64

NewField new uint64 field

type Uint8

type Uint8 = Integer[uint8]

func NewUint8

func NewUint8(table, column string, opts ...Option) Uint8

NewField new uint8 field

type Value

type Value clause.Expr

func Values

func Values(value any) Value

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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