dbs

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMaxConn  uint64 = 2000
	DefaultIdleConn uint64 = 20
)
View Source
var (
	DefaultLimit    = 10
	DefaultMaxLimit = 1000
)

Functions

func HandleFunc

func HandleFunc(handler func(tx *TX) error) func(db *gorm.DB) error

func Rows2Bytes

func Rows2Bytes(rows *sql.Rows) []byte

func Rows2Map

func Rows2Map(rows *sql.Rows) []map[string]interface{}

Types

type BaseModel

type BaseModel struct {
	Id        uint64     `json:"id" gorm:"primary_key;AUTO_INCREMENT;column:id;comment:'主键ID'"`
	IsDel     uint64     `json:"-" gorm:"column:is_del;default:0;comment:'删除标志'"`
	CreatedAt time.Time  `json:"created_at" gorm:"column:created_at;comment:'创建时间'"`
	UpdatedAt time.Time  `json:"updated_at" gorm:"column:updated_at;comment:'更新时间'"`
	DeletedAt *time.Time `json:"-" gorm:"column:deleted_at;comment:'删除时间'" sql:"index"`
	Remark    string     `json:"remark" gorm:"column:remark;null;type:text;comment:'备注信息'"`
}

func (*BaseModel) AfterCreate

func (m *BaseModel) AfterCreate(fc func(tx *TX) error, db *DB) error

func (*BaseModel) AfterDelete

func (m *BaseModel) AfterDelete(fc func(tx *TX) error, db *DB) error

func (*BaseModel) AfterSave

func (m *BaseModel) AfterSave(fc func(tx *TX) error, db *DB) error

func (*BaseModel) AfterUpdate

func (m *BaseModel) AfterUpdate(fc func(tx *TX) error, db *DB) error

func (*BaseModel) BeforeCreate

func (m *BaseModel) BeforeCreate(fc func(tx *TX) error, db *DB) error

func (*BaseModel) BeforeDelete

func (m *BaseModel) BeforeDelete(fc func(tx *TX) error, db *DB) error

func (*BaseModel) BeforeSave

func (m *BaseModel) BeforeSave(fc func(tx *TX) error, db *DB) error

func (*BaseModel) BeforeUpdate

func (m *BaseModel) BeforeUpdate(fc func(tx *TX) error, db *DB) error

func (*BaseModel) TableName

func (m *BaseModel) TableName() string

type DB

type DB struct {
	*gorm.DB
}

func OpenDBClickhouse

func OpenDBClickhouse(username, password, ip string, port uint64, dbName string, dryRun bool, maxConn, idleConn uint64, customConn string) *DB

func OpenDBClickhouseCluster added in v0.1.6

func OpenDBClickhouseCluster(dsns []string, dryRun bool, maxConn, idleConn uint64) *DB

func OpenDBMySQL

func OpenDBMySQL(username, password, ip string, port uint64, dbName string, dryRun bool, maxConn, idleConn uint64, customConn string) *DB

func OpenDBMySQLCluster added in v0.1.6

func OpenDBMySQLCluster(dsns []string, dryRun bool, maxConn, idleConn uint64) *DB

func OpenDBPostgreSQL

func OpenDBPostgreSQL(username, password, ip string, port uint64, dbName string, dryRun bool, maxConn, idleConn uint64, customConn string) *DB

func OpenDBPostgreSQLCluster added in v0.1.6

func OpenDBPostgreSQLCluster(dsns []string, dryRun bool, maxConn, idleConn uint64) *DB

func OpenDBSQLServer

func OpenDBSQLServer(username, password, ip string, port uint64, dbName string, dryRun bool, maxConn, idleConn uint64, customConn string) *DB

func OpenDBSQLServerCluster added in v0.1.6

func OpenDBSQLServerCluster(dsns []string, dryRun bool, maxConn, idleConn uint64) *DB

func OpenDBSQLite

func OpenDBSQLite(filePath string, dryRun bool, maxConn, idleConn uint64, customConn string) *DB

func OpenDBSQLiteCluster added in v0.1.6

func OpenDBSQLiteCluster(fileNames []string, dryRun bool, maxConn, idleConn uint64, customConn string) *DB

func OpenDBTiDB

func OpenDBTiDB(username, password, ip string, port uint64, dbName string, dryRun bool, maxConn, idleConn uint64, customConn string) *DB

func OpenDBTiDBCluster added in v0.1.6

func OpenDBTiDBCluster(dsns []string, dryRun bool, maxConn, idleConn uint64) *DB

func (*DB) Create

func (db *DB) Create(dataModel interface{}) error

func (*DB) CreateBatch

func (db *DB) CreateBatch(dataModels interface{}, batchSize uint) error

func (*DB) DeleteHardById

func (db *DB) DeleteHardById(dataModels interface{}) error

func (*DB) DeleteHardByWhere

func (db *DB) DeleteHardByWhere(dataModel interface{}, where string, args []interface{}) error

func (*DB) DeleteSoftById

func (db *DB) DeleteSoftById(dataModels interface{}) error

func (*DB) DeleteSoftByWhere

func (db *DB) DeleteSoftByWhere(dataModel interface{}, where string, args []interface{}) error

func (*DB) Exec

func (db *DB) Exec(sql string, values ...interface{}) error

func (*DB) InitDefaultData

func (db *DB) InitDefaultData(basePath string)

func (*DB) Migration

func (db *DB) Migration(models []interface{})

func (*DB) RawSqlForByte

func (db *DB) RawSqlForByte(sql string, values ...interface{}) ([]byte, error)

func (*DB) RawSqlForMap

func (db *DB) RawSqlForMap(sql string, values ...interface{}) ([]map[string]interface{}, error)

func (*DB) RetrieveByArgs

func (db *DB) RetrieveByArgs(dataModel interface{}, where string, args []interface{}) error

func (*DB) RetrieveByFind

func (db *DB) RetrieveByFind(whereModel interface{}) error

func (*DB) RetrieveById

func (db *DB) RetrieveById(whereModel interface{}) error

func (*DB) RetrieveByMap

func (db *DB) RetrieveByMap(dataModel interface{}, whereMap map[string]interface{}) error

func (*DB) RetrieveByModel

func (db *DB) RetrieveByModel(pageSize, pageNo int, whereModel interface{}, order string) (interface{}, int64, error)

func (*DB) RetrieveByModelBytes

func (db *DB) RetrieveByModelBytes(pageSize, pageNo int, whereModel interface{}, order string) ([]byte, int64, error)

func (*DB) RetrieveByModelSelect

func (db *DB) RetrieveByModelSelect(pageSize, pageNo int, whereModel interface{}, fields []string, order string) (interface{}, int64, error)

func (*DB) RetrieveByModelSelectBytes

func (db *DB) RetrieveByModelSelectBytes(pageSize, pageNo int, whereModel interface{}, fields []string, order string) ([]byte, int64, error)

func (*DB) RetrieveByModelSelectString

func (db *DB) RetrieveByModelSelectString(pageSize, pageNo int, whereModel interface{}, fields []string, order string) (string, int64, error)

func (*DB) RetrieveByModelString

func (db *DB) RetrieveByModelString(pageSize, pageNo int, whereModel interface{}, order string) (string, int64, error)

func (*DB) RetrieveByWhere

func (db *DB) RetrieveByWhere(pageSize, pageNo int, dataModel interface{}, order, where string, args []interface{}) (interface{}, int64, error)

func (*DB) RetrieveByWhereBytes

func (db *DB) RetrieveByWhereBytes(pageSize, pageNo int, dataModel interface{}, order, where string, args []interface{}) ([]byte, int64, error)

func (*DB) RetrieveByWhereSelect

func (db *DB) RetrieveByWhereSelect(pageSize, pageNo int, dataModel interface{}, fields []string, order, where string, args []interface{}) (interface{}, int64, error)

func (*DB) RetrieveByWhereSelectBytes

func (db *DB) RetrieveByWhereSelectBytes(pageSize, pageNo int, dataModel interface{}, fields []string, order, where string, args []interface{}) ([]byte, int64, error)

func (*DB) RetrieveByWhereSelectString

func (db *DB) RetrieveByWhereSelectString(pageSize, pageNo int, dataModel interface{}, fields []string, order, where string, args []interface{}) (string, int64, error)

func (*DB) RetrieveByWhereString

func (db *DB) RetrieveByWhereString(pageSize, pageNo int, dataModel interface{}, order, where string, args []interface{}) (string, int64, error)

func (*DB) RetrieveCountByArgs

func (db *DB) RetrieveCountByArgs(dataModel interface{}, where string, args []interface{}) (int64, error)

func (*DB) RetrieveCountByModel

func (db *DB) RetrieveCountByModel(whereModel interface{}) (int64, error)

func (*DB) Transaction

func (db *DB) Transaction(fc func(tx *TX) error) error

func (*DB) TruncateTable

func (db *DB) TruncateTable(dataModel interface{}) error

func (*DB) UpdateByArgsField

func (db *DB) UpdateByArgsField(dataModel interface{}, where string, args []interface{}, column, expr string, updates ...interface{}) error

func (*DB) UpdateByArgsWhere

func (db *DB) UpdateByArgsWhere(dataModel interface{}, where string, args []interface{}, updates map[string]interface{}) error

func (*DB) UpdateByArgsWhereModel

func (db *DB) UpdateByArgsWhereModel(where string, args []interface{}, updateModel interface{}) error

func (*DB) UpdateByField

func (db *DB) UpdateByField(dataModel interface{}, where interface{}, column, expr string, updates ...interface{}) error

func (*DB) UpdateById

func (db *DB) UpdateById(dataModel interface{}) error

func (*DB) UpdateByModelField

func (db *DB) UpdateByModelField(whereModel interface{}, column, expr string, updates ...interface{}) error

func (*DB) UpdateByModelWhere

func (db *DB) UpdateByModelWhere(whereModel interface{}, updates map[string]interface{}) error

func (*DB) UpdateByModelWhereModel

func (db *DB) UpdateByModelWhereModel(whereModel interface{}, updateModel interface{}) error

func (*DB) UpdateByWhere

func (db *DB) UpdateByWhere(dataModel interface{}, where string, updates map[string]interface{}) error

func (*DB) UpdateByWhereModel

func (db *DB) UpdateByWhereModel(where string, updateModel interface{}) error

type LogInfoModel

type LogInfoModel struct {
	BaseModel
	Method        string    `json:"method" gorm:"column:method;null;comment:'请求方法'"`
	ContentLength uint64    `json:"content_length" gorm:"column:content_length;null;comment:'内容长度'"`
	ExecuteTime   time.Time `json:"execute_time" gorm:"column:execute_time;null;comment:'执行时间'"`
	ContentType   string    `json:"content_type" gorm:"column:content_type;null;comment:'内容类型'"`
	CostTime      uint64    `json:"cost_time" gorm:"column:cost_time;null;comment:'花费时间'"`
	RequestUrl    string    `json:"request_url" gorm:"column:request_url;null;comment:'请求URL'"`
	RequestHost   string    `json:"request_host" gorm:"column:request_host;null;comment:'请求主机'"`
	UserAgent     string    `json:"user_agent" gorm:"column:user_agent;null;comment:'请求头'"`
	RemoteIp      string    `json:"remote_ip" gorm:"column:remote_ip;null;comment:'远程IP'"`
	RemoteAddr    string    `json:"remote_addr" gorm:"column:remote_addr;null;comment:'远程地址'"`
	ApiPath       string    `json:"api_path" gorm:"column:api_path;null;comment:'API路径'"`
	Referer       string    `json:"referer" gorm:"column:referer;null;comment:'网页关联'"`
	ApiDesc       string    `json:"api_desc" gorm:"column:api_desc;null;comment:'API功能'"`
	StatusCode    int       `json:"status_code" gorm:"column:status_code;null;comment:'状态码'"`
	ResponseData  string    `json:"response_data" gorm:"column:response_data;null;type:text;comment:'响应数据'"`
	AccountInfo   string    `json:"account_info" gorm:"column:account_info;null;type:text;comment:'用户信息'"`
	AccountName   string    `json:"account_name" gorm:"column:account_name;null;comment:'用户名称'"`
	AccountId     uint64    `json:"account_id" gorm:"column:account_id;null;comment:'用户ID'"`
	RequestParams string    `json:"request_params" gorm:"column:request_params;null;type:text;comment:'请求参数'"`
	RequestToken  string    `json:"request_token" gorm:"column:request_token;null;type:text;comment:'请求Token'"`
}

func (*LogInfoModel) TableName

func (m *LogInfoModel) TableName() string

type TX

type TX struct {
	*gorm.DB
}

type UpdateModel

type UpdateModel struct {
	BaseModel
	FileName    string    `json:"file_name" gorm:"column:file_name;not null;comment:'文件名称'"`
	ExecuteTime time.Time `json:"execute_time" gorm:"column:execute_time;null;comment:'执行时间'"`
}

func (*UpdateModel) TableName

func (m *UpdateModel) TableName() string

Jump to

Keyboard shortcuts

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