Documentation
¶
Index ¶
- type BaseModel
- type Gorm
- func (g *Gorm) Create(model interface{}) error
- func (g *Gorm) CreateTable(model interface{}) error
- func (g *Gorm) CreateTableList(models ...interface{}) error
- func (g *Gorm) Delete(model interface{}, id uint64) error
- func (g *Gorm) DeleteByIdLIst(model interface{}, ids ...uint64) error
- func (g *Gorm) Exists(model interface{}, key string, value interface{}) bool
- func (g *Gorm) Find(model interface{}, id uint64) error
- func (g *Gorm) FindByIdList(model interface{}, ids ...uint64) error
- func (g *Gorm) FindByMap(model interface{}, condition map[string]interface{}) error
- func (g *Gorm) InitMysql(config *MysqlConfig)
- func (g *Gorm) Page(page, size int, model interface{})
- func (g *Gorm) Update(model interface{}) error
- type GormConfig
- type JsonList
- type MysqlConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseModel ¶
type BaseModel struct {
ID uint64 `gorm:"primarykey"`
CreatedAt time.Time `gorm:"column:add_time"` // 添加时间
UpdatedAt time.Time `gorm:"column:update_time"` // 修改时间
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at"` // 删除时间
}
BaseModel 基础模型
type Gorm ¶
type Gorm struct {
DB *gorm.DB // gorm操作数据库的核心对象
SqlDb *sql.DB // 执行SQL语句的连接对象
// contains filtered or unexported fields
}
Gorm 核心对象
func (*Gorm) CreateTableList ¶
CreateTableList 创建多个表格
func (*Gorm) DeleteByIdLIst ¶
DeleteByIdLIst 根据id列表删除数据
func (*Gorm) FindByIdList ¶
FindByIdList 根据id列表查询
func (*Gorm) InitMysql ¶
func (g *Gorm) InitMysql(config *MysqlConfig)
InitMysql 初始化Mysql数据库连接 @param config MySQL配置对象
type GormConfig ¶
type GormConfig struct {
Debug bool // 是否为调试模式
LogFilePath string // 日志存放路径
Mysql MysqlConfig // mysql的配置信息
}
GormConfig 配置对象
type MysqlConfig ¶
type MysqlConfig struct {
Host string `mapstructure:"host" json:"host"` // 主机地址
Port int `mapstructure:"port" json:"port"` // 端口号
Database string `mapstructure:"db" json:"database"` // 数据库名称
User string `mapstructure:"user" json:"username"` // 用户名
Password string `mapstructure:"password" json:"password"` // 密码
MaxIdleConn uint `mapstructure:"max_idle_conn" json:"max_idle_conn"` // 设置空闲连接池中连接的最大数量
MaxOpenConn uint `mapstructure:"max_open_conn" json:"max_open_conn"` // 设置打开数据库连接的最大数量
ConnMaxLifetime uint `mapstructure:"conn_max_lifetime" json:"conn_max_lifetime"` // 设置了连接可复用的最大时间
}
MysqlConfig MySQL配置信息
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
gorm/z01_hello
command
|
|
|
gorm/z02_migrate
command
|
|
|
gorm/z03_create
command
|
|
|
zdpgo_gorm/z01_hello
command
|
|
|
zdpgo_gorm/z02_create_table
command
|
|
|
zdpgo_gorm/z03_insert_many
command
|
|
|
zdpgo_gorm/z05_lock_insert_many
command
|
|
|
zdpgo_gorm/z06_query_data
command
|
Click to show internal directories.
Click to hide internal directories.