db

package
v1.10.8 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: GPL-3.0 Imports: 17 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB
View Source
var DefaultAesKey = "AY3b5Z78806GorMa"

Functions

func Create

func Create(tx *gorm.DB, Model interface{}, autoCommit bool) error

func DBInt

func DBInt(model interface{}, o Option, dbObj *gorm.DB) *gorm.DB

func Delete

func Delete(tx *gorm.DB, Model interface{}, o Option, Associations []string, autoCommit bool) error

func DeleteByID

func DeleteByID(model interface{}, id uint64) (count int64, err error)

func DeleteById

func DeleteById(tx *gorm.DB, Model interface{}, sqlId interface{}, Associations []string, autoCommit bool) error

func DeleteByModel

func DeleteByModel(model interface{}) (count int64, err error)

func DeleteByWhere

func DeleteByWhere(model, where interface{}) (count int64, err error)

func Error

func Error(err error, nullError bool) bool

func Exist

func Exist(model interface{}, o Option) (bool, error)

func Get

func Get(db *gorm.DB, Model interface{}, o Option, out interface{}) error

func GetById

func GetById(DB *gorm.DB, Model interface{}, sqlId interface{}, out interface{}, notFoundError bool) error

func GetResult

func GetResult(dbObj *gorm.DB, o Option, out interface{}) error

func GetTablePrefix

func GetTablePrefix() string

func InitDB

func InitDB(DBType, DSN string, gdb *gorm.DB)

func PluckList

func PluckList(model, where interface{}, out interface{}, fieldName string) error

func Query

func Query(db *gorm.DB, Model interface{}, o Option, pageData *response.PageDataList) error

func Raw

func Raw(Model interface{}, sql string, o Option, out *[]string) error

func Save

func Save(value interface{}) error

func Update

func Update(tx *gorm.DB, Model interface{}, o Option, data map[string]interface{}, ass []Association, autoCommit bool,
) error

func UpdateById

func UpdateById(tx *gorm.DB, Model interface{}, sqlId interface{},
	data map[string]interface{}, ass []Association, autoCommit bool) error

func UpdateByIdStruct

func UpdateByIdStruct(tx *gorm.DB, Model interface{}, sqlId interface{},
	data interface{}, ass []Association, autoCommit bool) error

func Updates

func Updates(where interface{}, value interface{}) error

Types

type AesStr added in v1.10.2

type AesStr string

func (*AesStr) Scan added in v1.10.2

func (j *AesStr) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (AesStr) Value added in v1.10.2

func (j AesStr) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type Association

type Association struct {
	Column string
	Values interface{}
}

type Base

type Base struct {
	ID    int       `gorm:"column:id;primary_key;auto_increment;" json:"id" form:"id"` // 主键
	Ctime time.Time `gorm:"not null;type:datetime;default:current_timestamp" json:"ctime" form:"ctime"`
	Mtime time.Time `gorm:"not null;type:datetime;default:current_timestamp on update CURRENT_TIMESTAMP;" json:"mtime"  form:"mtime"`
}

type BaseByUpdate

type BaseByUpdate struct {
	ByUpdate string `gorm:"type:varchar(64);comment:更新人" json:"by_update" form:"by_update"`
}

type BaseDeleted

type BaseDeleted struct {
	Deleted bool `gorm:"default:false;comment:标记是否删除;" json:"deleted" form:"deleted"`
}

type BaseDescription

type BaseDescription struct {
	ByUpdate string `gorm:"type:varchar(64);comment:更新人" json:"by_update" form:"by_update"`
}

type BaseID

type BaseID struct {
	ID int `gorm:"column:id;primary_key;comment:主键id" json:"id" form:"id"` // 主键
}

type BaseName

type BaseName struct {
	Name string `gorm:"type:varchar(64);comment:更新人" json:"name" form:"name"`
}

type BaseSql

type BaseSql struct {
	Model interface{}
}

type BaseTime

type BaseTime struct {
	Ctime JSONTime `gorm:"not null;type:datetime;default:current_timestamp;comment:创建时间" json:"ctime" form:"ctime"`
	Mtime JSONTime `` /* 141-byte string literal not displayed */
}

type Bool added in v1.10.2

type Bool bool

func (*Bool) Scan added in v1.10.2

func (j *Bool) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (Bool) Value added in v1.10.2

func (j Bool) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type ByUpdateDeleted

type ByUpdateDeleted struct {
	BaseByUpdate
	BaseDeleted
}

type ByUpdateDeletedTime

type ByUpdateDeletedTime struct {
	BaseByUpdate
	BaseDeleted
	BaseTime
}

type ByUpdateTime

type ByUpdateTime struct {
	BaseByUpdate
	BaseTime
}

type BytesUnit added in v1.0.8

type BytesUnit string

func (*BytesUnit) Scan added in v1.0.8

func (j *BytesUnit) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (BytesUnit) Value added in v1.0.8

func (j BytesUnit) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type DataBases

type DataBases struct {
	Engine     string            `json:"engine" default:"mysql"`
	Name       string            `json:"name" default:"ops"`
	User       string            `json:"user" default:"root"`
	Password   string            `json:"password" default:"123456"`
	Host       string            `json:"host" default:"127.0.0.1"`
	Port       string            `json:"port" default:"3306"`
	Charset    string            `json:"charset" default:"utf8mb4"`
	Parameters string            `json:"parameters"`
	Options    map[string]string `json:"options"`
}

func (DataBases) DSN

func (a DataBases) DSN() string

type DateTime

type DateTime struct {
	time.Time
}

DateTime format json time field by myself

func (DateTime) MarshalJSON

func (t DateTime) MarshalJSON() ([]byte, error)

MarshalJSON on JSONTime format Time field with %Y-%m-%d %H:%M:%S

func (*DateTime) Scan

func (t *DateTime) Scan(v interface{}) error

Scan valueof time.Time

func (*DateTime) UnmarshalJSON added in v1.0.8

func (t *DateTime) UnmarshalJSON(data []byte) error

UnmarshalJSON 反序列化

func (DateTime) Value

func (t DateTime) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

type IdList added in v1.0.8

type IdList []int

type Int added in v1.10.2

type Int int

func (*Int) Scan added in v1.10.2

func (j *Int) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (Int) Value added in v1.10.2

func (j Int) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type IntArray added in v1.0.8

type IntArray []int

func (*IntArray) Scan added in v1.0.8

func (j *IntArray) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (IntArray) Value added in v1.0.8

func (j IntArray) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type IntNestArray added in v1.0.8

type IntNestArray [][]int

func (*IntNestArray) Scan added in v1.0.8

func (j *IntNestArray) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (IntNestArray) Value added in v1.0.8

func (j IntNestArray) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime format json time field by myself

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON on JSONTime format Time field with %Y-%m-%d %H:%M:%S

func (*JSONTime) Scan

func (t *JSONTime) Scan(v interface{}) error

Scan valueof time.Time

func (*JSONTime) UnmarshalJSON added in v1.0.8

func (t *JSONTime) UnmarshalJSON(data []byte) error

UnmarshalJSON 反序列化

func (JSONTime) Value

func (t JSONTime) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

type MillisTime added in v1.10.2

type MillisTime string

func (*MillisTime) Scan added in v1.10.2

func (j *MillisTime) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (*MillisTime) UnmarshalJSON added in v1.10.2

func (j *MillisTime) UnmarshalJSON(data []byte) error

UnmarshalJSON 反序列化

func (MillisTime) Value added in v1.10.2

func (j MillisTime) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type Option

type Option struct {
	DB        *gorm.DB
	Order     string
	Where     string
	Value     []interface{}
	Preloads  []string
	Select    string
	Joins     string
	Group     string
	Having    string
	Distinct  []string
	Scan      bool
	First     bool
	All       bool
	Pluck     string
	Omits     []string
	NullError bool
	Debug     bool
	Table     string
}

Option 条件

type SecTime added in v1.10.2

type SecTime string

func (*SecTime) Scan added in v1.10.2

func (j *SecTime) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (*SecTime) UnmarshalJSON added in v1.10.2

func (j *SecTime) UnmarshalJSON(data []byte) error

UnmarshalJSON 反序列化

func (SecTime) Value added in v1.10.2

func (j SecTime) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type StringArray added in v1.0.8

type StringArray []string

func (*StringArray) Scan added in v1.0.8

func (j *StringArray) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (StringArray) Value added in v1.0.8

func (j StringArray) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type ZhToCode added in v1.0.8

type ZhToCode struct {
	Zh   string `json:"zh"`
	Code string `json:"code"`
}

Jump to

Keyboard shortcuts

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