db

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDestroy added in v1.0.4

func DefaultDestroy(ctx *plugin.Context) error

func DefaultGetDBName added in v1.0.4

func DefaultGetDBName(ctx *plugin.Context) string

func DefaultMake added in v1.0.4

func DefaultMake(ctx *plugin.Context, groups []ERGroup) ([]string, error)

func DefaultMakeDao added in v1.0.4

func DefaultMakeDao(ctx *plugin.Context, outputPath *string, conf *DaoConfig) error

func DefaultMakeER added in v1.0.4

func DefaultMakeER(ctx *plugin.Context, groups []ERGroup, outputFile *string, tplFile *string) error

func DefaultMakeId added in v1.0.4

func DefaultMakeId(ctx *plugin.Context, table string, idField string, idSize uint) (string, error)

func DefaultQuery1 added in v1.0.4

func DefaultQuery1(ctx *plugin.Context, requestSql string, args ...interface{}) (map[string]interface{}, error)

func DefaultQuery11 added in v1.0.4

func DefaultQuery11(ctx *plugin.Context, requestSql string, args ...interface{}) (interface{}, error)

func DefaultQuery1a added in v1.0.4

func DefaultQuery1a(ctx *plugin.Context, requestSql string, args ...interface{}) ([]interface{}, error)

func InKeys added in v1.0.3

func InKeys(numArgs int) string

InKeys 根据长度生成SQL中 IN "(?,?,...)" 引号中的部分 InKeys return IN后面的Key变量的SQL

func MakeDao added in v1.0.3

func MakeDao(outputPath string, conn *db.DB, conf *DaoConfig, ctx *plugin.Context) error

func MakeER added in v1.0.3

func MakeER(groups []ERGroup, outputFile *string, tplFile *string, ctx *plugin.Context) error

MakeER 创建ER图文件

func MakeTable added in v1.0.3

func MakeTable(conn *db.DB, table *TableStruct, ctx *plugin.Context) ([]string, error)

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func GetDB

func GetDB(ctx *plugin.Context, name *string) *DB

GetDB 获得数据库连接 GetDB name 连接配置名称,如果不提供名称则使用默认连接 GetDB return 数据库连接,对象内置连接池操作,完成后无需手动关闭连接

func (*DB) Begin

func (db *DB) Begin() *Tx

Begin 开始事务 Begin return 事务对象,事务中的操作都在事务对象上操作,请务必在返回的事务对象上执行commit或rollback

func (*DB) Delete

func (db *DB) Delete(table string, wheres string, args ...interface{}) (ExecResult, error)

Delete 删除数据 Delete return 返回影响的行数

func (*DB) Destroy added in v1.0.3

func (db *DB) Destroy() error

Destroy 关闭连接池

func (*DB) Exec

func (db *DB) Exec(requestSql string, args ...interface{}) (ExecResult, error)

Exec 执行SQL * requestSql SQL语句 * args SQL语句中问号变量的值,按顺序放在请求参数中 Exec return 如果是INSERT到含有自增字段的表中返回插入的自增ID,否则返回影响的行数

func (*DB) GetDBName added in v1.0.4

func (db *DB) GetDBName() string

GetDBName 获取当前数据库名称 GetDBName return 当前数据库名称

func (*DB) Insert

func (db *DB) Insert(table string, data map[string]interface{}) (ExecResult, error)

Insert 插入数据 * table 表名 * data 数据对象(Key-Value格式) Insert return 如果是INSERT到含有自增字段的表中返回插入的自增ID,否则返回影响的行数

func (*DB) Make added in v1.0.3

func (db *DB) Make(groups []ERGroup, ctx *plugin.Context) ([]string, error)

Make 创建表格,如果表格已经存在则更新表结构 Make return 已执行的SQL列表

func (*DB) MakeDao added in v1.0.3

func (db *DB) MakeDao(outputPath *string, conf *DaoConfig, ctx *plugin.Context) error

MakeDao 创建实体对象 MakeDao outputPath 实体文件输出目录,为空时输出到当前目录下以数据库为目录名

func (*DB) MakeER added in v1.0.3

func (db *DB) MakeER(groups []ERGroup, outputFile *string, tplFile *string, ctx *plugin.Context) error

MakeER 创建ER图

func (*DB) MakeId

func (db *DB) MakeId(table string, idField string, idSize uint) (string, error)

MakeId 生成指定字段不唯一的ID MakeId idField ID字段 MakeId idSize ID长度 MakeId return 新的ID

func (*DB) Query

func (db *DB) Query(requestSql string, args ...interface{}) (QueryResult, error)

Query 查询 Query return 返回查询到的数据,对象数组格式

func (*DB) Query1

func (db *DB) Query1(requestSql string, args ...interface{}) (map[string]interface{}, error)

Query1 查询 Query1 return 返回查询到的第一行数据,对象格式

func (*DB) Query11

func (db *DB) Query11(requestSql string, args ...interface{}) (interface{}, error)

Query11 查询 Query11 return 返回查询到的第一行第一列数据,字段类型对应的格式

func (*DB) Query1a

func (db *DB) Query1a(requestSql string, args ...interface{}) ([]interface{}, error)

Query1a 查询 Query1a return 返回查询到的第一列数据,数组格式

func (*DB) Replace

func (db *DB) Replace(table string, data map[string]interface{}) (ExecResult, error)

Replace 替换数据 Replace return 如果是REPLACE到含有自增字段的表中返回插入的自增ID,否则返回影响的行数

func (*DB) Update

func (db *DB) Update(table string, data map[string]interface{}, wheres string, args ...interface{}) (ExecResult, error)

Update 更新数据 * wheres 条件(SQL中WHERE后面的部分) Update return 返回影响的行数

type DaoConfig added in v1.0.3

type DaoConfig struct {
	VersionField string
	ValidFields  []ValidFieldConfig
}

type DaoData added in v1.0.3

type DaoData struct {
	DBName       string
	FixedDBName  string
	RandomTag    string
	VersionField string
	//TableNames   []string
	Tables      []TableData
	FixedTables []string
	ExtDaoCode  []string
}

type ERGroup added in v1.0.3

type ERGroup struct {
	Group   string
	Comment string
	Tables  []TableStruct
}

type ExecResult added in v1.0.3

type ExecResult struct {
	Id      int64
	Changes int64
	Version uint64
	Sql     string
	SqlArgs []interface{}
}

func DefaultDelete added in v1.0.4

func DefaultDelete(ctx *plugin.Context, table string, wheres string, args ...interface{}) (ExecResult, error)

func DefaultExec added in v1.0.4

func DefaultExec(ctx *plugin.Context, requestSql string, args ...interface{}) (ExecResult, error)

func DefaultInsert added in v1.0.4

func DefaultInsert(ctx *plugin.Context, table string, data map[string]interface{}) (ExecResult, error)

func DefaultReplace added in v1.0.4

func DefaultReplace(ctx *plugin.Context, table string, data map[string]interface{}) (ExecResult, error)

func DefaultUpdate added in v1.0.4

func DefaultUpdate(ctx *plugin.Context, table string, data map[string]interface{}, wheres string, args ...interface{}) (ExecResult, error)

type FieldData added in v1.0.3

type FieldData struct {
	Name    string
	Type    string
	Default string
	Options map[string]string
}

type IndexField added in v1.0.3

type IndexField struct {
	Name       string
	Where      string
	Args       string
	Params     string
	ItemArgs   string
	StringArgs string
}

type QueryResult added in v1.0.3

type QueryResult struct {
	Result  []map[string]interface{}
	Sql     string
	SqlArgs []interface{}
}

func DefaultQuery added in v1.0.4

func DefaultQuery(ctx *plugin.Context, requestSql string, args ...interface{}) (QueryResult, error)

type TableData added in v1.0.3

type TableData struct {
	DBName          string
	TableName       string
	FixedTableName  string
	IsAutoId        bool
	AutoIdField     string
	AutoIdFieldType string
	PrimaryKey      *IndexField
	UniqueKeys      map[string]*IndexField
	IndexKeys       map[string]*IndexField
	Fields          []FieldData
	PointFields     []FieldData
	//FieldsWithoutAutoId []FieldData
	SelectFields          string
	ValidFieldConfig      ValidFieldConfig
	ValidField            string
	ValidWhere            string
	ValidSet              string
	InvalidSet            string
	VersionField          string
	HasVersion            bool
	AutoGenerated         []string
	AutoGeneratedOnUpdate []string
	ExtTableCode          []string
	ExtItemCode           []string
	ExtQueryCode          []string
}

type TableDesc added in v1.0.3

type TableDesc struct {
	Field   string
	Type    string
	Null    string
	Key     string
	Default string
	Extra   string
	After   string
}

type TableField added in v1.0.3

type TableField struct {
	Name       string
	Type       string
	Index      string
	IndexGroup string
	Default    string
	Comment    string
	IsNull     bool
	Extra      string

	Null string
	// contains filtered or unexported fields
}

func (*TableField) Parse added in v1.0.3

func (field *TableField) Parse(tableType string)

type TableFieldDesc added in v1.0.3

type TableFieldDesc struct {
	Field   string
	Type    string
	Null    string
	Key     string
	Default string
	Extra   string
	After   string
}

type TableIndex added in v1.0.3

type TableIndex struct {
	Non_unique   int
	Key_name     string
	Seq_in_index int
	Column_name  string
}

type TableKeyDesc added in v1.0.3

type TableKeyDesc struct {
	Key_name    string
	Column_name string
}

type TableStruct added in v1.0.3

type TableStruct struct {
	Name    string
	Comment string
	Fields  []TableField
}

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

func DefaultBegin added in v1.0.4

func DefaultBegin(ctx *plugin.Context) *Tx

func (*Tx) CheckFinished

func (tx *Tx) CheckFinished() error

CheckFinished 检查事务是否已经提交或回滚,如果事务没有结束则执行回滚操作

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit 提交事务

func (*Tx) Delete

func (tx *Tx) Delete(table string, wheres string, args ...interface{}) (ExecResult, error)

func (*Tx) Exec

func (tx *Tx) Exec(requestSql string, args ...interface{}) (ExecResult, error)

func (*Tx) Finish

func (tx *Tx) Finish(ok bool) error

Finish 根据传入的成功标识提交或回滚事务 Finish ok 事务是否执行成功

func (*Tx) Insert

func (tx *Tx) Insert(table string, data map[string]interface{}) (ExecResult, error)

func (*Tx) Query

func (tx *Tx) Query(requestSql string, args ...interface{}) (QueryResult, error)

func (*Tx) Query1

func (tx *Tx) Query1(requestSql string, args ...interface{}) (map[string]interface{}, error)

func (*Tx) Query11

func (tx *Tx) Query11(requestSql string, args ...interface{}) (interface{}, error)

func (*Tx) Query1a

func (tx *Tx) Query1a(requestSql string, args ...interface{}) ([]interface{}, error)

func (*Tx) Replace

func (tx *Tx) Replace(table string, data map[string]interface{}) (ExecResult, error)

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback 回滚事务

func (*Tx) Update

func (tx *Tx) Update(table string, data map[string]interface{}, wheres string, args ...interface{}) (ExecResult, error)

type ValidFieldConfig added in v1.0.3

type ValidFieldConfig struct {
	Field              string
	Type               string
	ValidOperator      string
	ValidValue         string
	ValidSetOperator   string
	ValidSetValue      string
	InvalidSetOperator string
	InvalidSetValue    string
}

Jump to

Keyboard shortcuts

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