orm

package
v0.0.0-...-b015d54 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PageSizeMin = 10
	PageSizeMax = 50
)

Variables

This section is empty.

Functions

func CloseDB

func CloseDB(db *gorm.DB) (err error)

func Connect

func Connect(fp, field string, debugMode bool) (db *gorm.DB, err error)

connect to database by provide a config file path(under project directory), and then use field mysql.dsn

func ConnectDSN

func ConnectDSN(dsn string, debugMode bool) (db *gorm.DB, err error)

MySQL initialize

dsn format: {USERANME}:{PASSWORD}@tcp({IP})/{DATABASE}?charset=utf8mb4&parseTime=True&loc=Local

func InitDB

func InitDB(db *gorm.DB) (err error)

func IsDuplicateEntry

func IsDuplicateEntry(err error) bool

func IsNotFound

func IsNotFound(err error) bool

errors

func JSONContains

func JSONContains(tx *gorm.DB, field string, val any, contains bool) *gorm.DB

func JSONIsNull

func JSONIsNull(tx *gorm.DB, field string, isNull bool) *gorm.DB

to avoid use this func, you can't bind field to an pointer rather than a structure

func Like

func Like(tx *gorm.DB, field, val string) *gorm.DB

func MultiEquals

func MultiEquals[T any](tx *gorm.DB, field string, values []T) *gorm.DB

func Where

func Where(tx *gorm.DB, field, val string) *gorm.DB

Types

type Map

type Map[T any] map[string]T

map

func (*Map[T]) Scan

func (item *Map[T]) Scan(value any) (err error)

func (Map[T]) Value

func (item Map[T]) Value() (driver.Value, error)

type Query

type Query struct {
	Starting string `json:"starting,omitempty" form:"starting"` // 2022-10-28
	End      string `json:"end,omitempty" form:"end"`           // 2022-10-28
	PageNo   int    `json:"pageNo,omitempty" form:"pageNo"`
	PageSize int    `json:"pageSize,omitempty" form:"pageSize"`
	Search   string `json:"search,omitempty" form:"search"`
	Status   string `json:"status,omitempty" form:"status"`
	UserId   int64  `json:"-" form:"-"`
}

query

func (*Query) DateRange

func (query *Query) DateRange(tx *gorm.DB, field string) *gorm.DB

func (*Query) Flip

func (query *Query) Flip(tx *gorm.DB) *gorm.DB

func (*Query) Validate

func (query *Query) Validate() (err error)

type QueryDate

type QueryDate struct {
	DateStart  string `json:"dateStart,omitempty" form:"dateStart"`
	DateEnd    string `json:"dateEnd,omitempty" form:"dateEnd"`
	MonthStart string `json:"monthStart,omitempty" form:"monthStart"`
	MonthEnd   string `json:"monthEnd,omitempty" form:"monthEnd"`
}

func (*QueryDate) Do

func (query *QueryDate) Do(db *gorm.DB, field string) (*gorm.DB, *Error)

func (*QueryDate) Validate

func (query *QueryDate) Validate() (err *Error)

type Result

type Result[T any] struct {
	Total int64 `json:"total"`
	Items []T   `json:"items"`
}

result

func NewResult

func NewResult[T any]() *Result[T]

func (Result[T]) Map

func (result Result[T]) Map() map[string]any

type Vector

type Vector[T any] []T // T should marshalable

vector

func (*Vector[T]) Scan

func (items *Vector[T]) Scan(value any) (err error)

func (Vector[T]) Value

func (vec Vector[T]) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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