mysqlx

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountSQL

func CountSQL(sql string) string

CountSQL count the target sql

func CountTable

func CountTable(c sqlx.SqlConn, table string) (int64, error)

func CreateDbIne

func CreateDbIne(dsn string) error

func CreateMysqlIndexes

func CreateMysqlIndexes(conn sqlx.SqlConn, db, table string, indexes []string) error

func GenerateSQLInsert

func GenerateSQLInsert(table string, data interface{}) string

func GetLengthTag

func GetLengthTag(field reflect.StructField) (int, error)

func GetMysqlTableComment

func GetMysqlTableComment(source, table string) (string, error)

func MysqlListTable

func MysqlListTable(db *sql.DB) ([]string, error)

func MysqlPing

func MysqlPing(dsn string) error

func PageSQL

func PageSQL(sql string, page, pageSize int) (string, int, int)

PageSQL add page limit to sql, return pagedSQL, offset, limit

func ParseMySQLDatabase

func ParseMySQLDatabase(dsn string) (string, string, error)

ParseMySQLDatabase 会在连接串中加上时间类型和时区设置,返回修改后的dsn、数据库名称和error

func TakeMySQLConn

func TakeMySQLConn(dsn string) (*sql.DB, error)

func TakeMySQLConnx

func TakeMySQLConnx(dsn string) sqlx.SqlConn

func ToClickhouseTable

func ToClickhouseTable(dsn, db, table, indexes string, withTime bool) ([]string, string, error)

Types

type Column

type Column struct {
	Field      string      `db:"Field"`
	Type       string      `db:"Type"`
	Collation  interface{} `db:"Collation"`
	Null       string      `db:"Null"`
	Key        string      `db:"Key"`
	Default    interface{} `db:"Default"`
	Extra      string      `db:"Extra"`
	Privileges string      `db:"Privileges"`
	Comment    string      `db:"Comment"`
}

func DescribeMysqlTable

func DescribeMysqlTable(conn sqlx.SqlConn, table string) ([]*Column, error)

type Count

type Count struct {
	Count int64 `db:"count"`
}

type MySQLModel

type MySQLModel struct {
	Conn      sqlx.SqlConn
	AppName   string
	Dsn       string
	Database  string
	TableName string
	Type      reflect.Type
	Indexes   []string

	DBs               []string
	MutableFieldDBs   []string // 字段的tag里面的db:""
	MutableFieldNames []string // 字段的名字
	// contains filtered or unexported fields
}

func MustNewMySQLModel

func MustNewMySQLModel(appName, dsn string, data interface{}) (*MySQLModel, bool, error)

MustNewMySQLModel 按照data结构体来建表,如果已存在则删掉他重新建

func NewMySQLModel

func NewMySQLModel(appName, dsn string, data interface{}) (*MySQLModel, bool, error)

NewMySQLModel 新建基础Model,按照data结构体来建表,如果已存在则不建表,但是会检测每一列是否和结构体字段对得上

func (*MySQLModel) All

func (m *MySQLModel) All() (interface{}, error)

func (*MySQLModel) BatchInsert

func (b *MySQLModel) BatchInsert(vs interface{}) error

BatchInsert 批量插入

func (*MySQLModel) Count

func (b *MySQLModel) Count(where string, args ...interface{}) (int64, error)

func (*MySQLModel) Delete

func (b *MySQLModel) Delete(id interface{}) (int64, error)

func (*MySQLModel) DeleteWhere

func (b *MySQLModel) DeleteWhere(where string, args ...interface{}) (int64, error)

func (*MySQLModel) Drop

func (b *MySQLModel) Drop() error

Drop drop table

func (*MySQLModel) DropIfExists

func (b *MySQLModel) DropIfExists() error

func (*MySQLModel) FindBy

func (b *MySQLModel) FindBy(field string, fieldValue interface{}) (interface{}, error)

func (*MySQLModel) FindWhere

func (b *MySQLModel) FindWhere(where string, args ...interface{}) (interface{}, error)

func (*MySQLModel) Insert

func (b *MySQLModel) Insert(data interface{}) (int64, error)

func (*MySQLModel) MustAll

func (m *MySQLModel) MustAll() interface{}

func (*MySQLModel) QueryWhere

func (b *MySQLModel) QueryWhere(where string, args ...interface{}) (interface{}, error)
QueryWhere 按条件查询

where : 查询条件,如果为空则没有查询条件。如:where="id=1" -> `select .. from table where id=1` . where="" -> `select .. from table`

返回:结构体的指针切片类型的interface{},如:[]*User类型

func (*MySQLModel) Update

func (b *MySQLModel) Update(id interface{}, sets string, args ...interface{}) (int64, error)

func (*MySQLModel) UpdateWhere

func (m *MySQLModel) UpdateWhere(sets, where string, args ...interface{}) (int64, error)

type MysqlTableComment

type MysqlTableComment struct {
	TableComment string `db:"TABLE_COMMENT"`
}

Jump to

Keyboard shortcuts

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