Documentation ¶
Index ¶
- Constants
- func AS(v, alias string) string
- func AfterLike(column, pattern string) func(*gorm.DB) *gorm.DB
- func Alias(v, alias string) string
- func Asc(order string) string
- func BeforeLike(column, pattern string) func(*gorm.DB) *gorm.DB
- func Desc(order string) string
- func InMemorySqlite() (*gorm.DB, error)
- func InMemorySqliteWithInitSQL(sql string, values ...interface{}) (*gorm.DB, error)
- func Like(column, pattern string) func(*gorm.DB) *gorm.DB
- func Max0[T constraints.Integer](value T) T
- func Max1[T constraints.Integer](value T) T
- func MaxInteger[T constraints.Integer](lhs, rhs T) T
- func Orders(orders ...string) string
- func PageParamConvert[T constraints.Integer](pageNum, pageSize T) (offset, limit T)
- func PageParamConvertWith[T constraints.Integer](pageNum, pageSize T, pageSizeFn func(T) T) (offset, limit T)
- func Paginate[T constraints.Integer](pageNum, pageSize T) func(*gorm.DB) *gorm.DB
- func PaginateWith[T constraints.Integer](pageNum, pageSize T, pageSizeFn func(T) T) func(*gorm.DB) *gorm.DB
- func PercentageAround(v string) string
- func PercentagePrefix(v string) string
- func PercentageSuffix(v string) string
- func SignedIntegerToString[T constraints.Signed](i T) string
Constants ¶
const ( WildCardPercentage = "%" WildCardUnderLine = "_" )
const ( OrderDesc = "DESC" OrderAsc = "ASC" )
const (
AliasAs = "AS"
)
Variables ¶
This section is empty.
Functions ¶
func AS ¶
AS set alias with "AS"
If reserved word "AS" is not need, use Alias
AS("user", "u") -> "user AS u"
func BeforeLike ¶
BeforeLike generate `column LIKE %pattern`
func InMemorySqlite ¶
InMemorySqlite create in memory sqlite database
InMemorySqlite can be used for mocking database while unit testing
func InMemorySqliteWithInitSQL ¶
InMemorySqliteWithInitSQL create in memory sqlite database with init SQL
func Like ¶
Like generate `column LIKE %pattern%`
Like(column, pattern) -> db.Where("? LIKE ?", column, %+pattern+%)
The order of the parameters (column & pattern) is consistent with the order of LIKE clause
func Max0 ¶
func Max0[T constraints.Integer](value T) T
func Max1 ¶
func Max1[T constraints.Integer](value T) T
func MaxInteger ¶
func MaxInteger[T constraints.Integer](lhs, rhs T) T
func Orders ¶
Orders make a concatenation
Orders("id DESC", "create_time ASC") -> "id DESC, create_time ASC"
func PageParamConvert ¶
func PageParamConvert[T constraints.Integer](pageNum, pageSize T) (offset, limit T)
PageParamConvert convert the num and size of a page to the param offset and limit
PageParamConvert will fix the value of the pageNum and pageSize if the value is less than 1
func PageParamConvertWith ¶
func PageParamConvertWith[T constraints.Integer](pageNum, pageSize T, pageSizeFn func(T) T) (offset, limit T)
PageParamConvertWith convert the num and size of a page to the param offset and limit with the adjust function for page size
func Paginate ¶
Paginate convert pageNum and pageSize to offset and limit
Paginate(3, 10) -> db.Offset(20).Limit(10)
If offset or limit is less than 1, then Paginate will fix it ¶
If some constraints are required for pageSize, please use PaginateWith
func PaginateWith ¶
func PaginateWith[T constraints.Integer](pageNum, pageSize T, pageSizeFn func(T) T) func(*gorm.DB) *gorm.DB
PaginateWith convert pageNum and pageSize to offset and limit with the constraint of pageSize
func PercentageAround ¶
PercentageAround add % before and after the string
PercentageAround("Tim") -> "%Tim%"
PercentageAround use string concatenation rather than fmt.Sprintf("%%%s%%", v), which is confusing and slow (no need to use format)
func SignedIntegerToString ¶
func SignedIntegerToString[T constraints.Signed](i T) string
SignedIntegerToString convert signed integer (int, int8, int16, int32, int64) to string
Refer to https://stackoverflow.com/questions/39442167/convert-int32-to-string-in-golang
Types ¶
This section is empty.