gormic

package
v0.3.5-0...-ad62298 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectMysql

func ConnectMysql(c *types.MysqlC) (db *gorm.DB, err error)

ConnectMysql build a connection to mysql

func ConnectSqlite3

func ConnectSqlite3(c *types.SQLite3Config) (*gorm.DB, error)

ConnectSqlite3 .

func SetLogger

func SetLogger(db *gorm.DB, logger gorm.LogWriter) *gorm.DB

SetLogger to open log mode and set logger notice that: gorm.LogWriter is an interface with Println method, and if logger is nil, default output to os.Stdout

Types

type Join

type Join struct {
	Query string
	Args  []interface{}
}

Join . db.Joins("JOIN department on department.id = employee.department_id AND employee.name = ?", "Jenkins")

type Model

type Model struct {
	ID         string    `gorm:"column:id;index;not null;type:varchar(128)"`
	CreateTime time.Time `gorm:"column:create_time"`
	UpdateTime time.Time `gorm:"column:update_time"`
}

Model ... as custom gorm model with some callbacks BeforeCreate ... create 之前调用 BeforeUpdate ... update 之前调用

func (*Model) BeforeCreate

func (m *Model) BeforeCreate() error

BeforeCreate ....

func (*Model) BeforeUpdate

func (m *Model) BeforeUpdate() error

BeforeUpdate ....

type Paginator

type Paginator struct {
	Total   uint        `json:"total"`
	Records interface{} `json:"records"`
	Error   error       `json:"error,omitempty"`
}

Paginator 分页返回

func Pagging

func Pagging(p *PagingParam, out interface{}) *Paginator

Pagging 分页

type PagingParam

type PagingParam struct {
	DB       *gorm.DB    // DB Data Source
	Limit    uint        // Limit
	Offset   uint        // Offset
	Select   string      // Select
	OrderBy  []string    // Orders
	GroupBy  string      // Group
	Joins    []Join      // Joins
	Wheres   []Where     // Wheres
	ORs      []Where     // ORs
	Not      interface{} // Not
	Preloads []string    // Preload
	ShowSQL  bool        // Debug mode

}

PagingParam 分页参数

type TableConn

type TableConn struct {
	*gorm.DB
	*sync.RWMutex
}

TableConn ... connection to table

type Where

type Where struct {
	Key   string
	Value interface{}
}

Where . db.Where(key, value)

Jump to

Keyboard shortcuts

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