kmgSql

package
v0.0.0-...-05317bf Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearReisterTable

func ClearReisterTable()

不支持并发调用

func DeleteById

func DeleteById(tableName string, fieldName string, value string) error

func Exec

func Exec(query string, args ...string) (sql.Result, error)

func GetAllInTable

func GetAllInTable(tableName string) (output []map[string]string, err error)

func GetFirstIntFromRowList

func GetFirstIntFromRowList(rowList []map[string]string) int

func GetOneWhere

func GetOneWhere(tableName string, fieldName string, value string) (output map[string]string, err error)

如果没有数据不会报错,output和err都会返回nil

func HasProdConfig

func HasProdConfig() bool

func HasTestConfig

func HasTestConfig() bool

func Insert

func Insert(tableName string, row map[string]string) (lastInsertId int, err error)

func LoadConfigWithDbName

func LoadConfigWithDbName(dbname string)

func MustAddNewField

func MustAddNewField(tableConf Table, newFieldName string)

func MustCreateDb

func MustCreateDb()

创建数据库 不支持并发调用

func MustCreateTable

func MustCreateTable(tableConf Table)

func MustDeleteById

func MustDeleteById(tableName string, fieldName string, value string)

func MustExec

func MustExec(query string, args ...string)

func MustForceModifyTable

func MustForceModifyTable(tableConf Table)

func MustForceSyncDefaultDbConfig

func MustForceSyncDefaultDbConfig()

func MustForceSyncRegisterTable

func MustForceSyncRegisterTable()

强制同步注册进去的表,可能会掉数据,保证字段达到配置的样子 不支持并发调用

func MustForceSyncTable

func MustForceSyncTable(tableConf Table)

func MustGetAllInTable

func MustGetAllInTable(tableName string) (output []map[string]string)

func MustGetOneWhere

func MustGetOneWhere(tableName string, fieldName string, value string) (output map[string]string)

func MustInsert

func MustInsert(tableName string, row map[string]string) (lastInsertId int)

func MustIsTableExist

func MustIsTableExist(tableName string) bool

func MustLoadProdConfig

func MustLoadProdConfig()

func MustLoadTestConfig

func MustLoadTestConfig()

func MustModifyTable

func MustModifyTable(tableConf Table)

func MustOrmFromId

func MustOrmFromId(obj OrmObject, id string)

func MustOrmFromRow

func MustOrmFromRow(obj OrmObject, row map[string]string)

func MustOrmInsert

func MustOrmInsert(obj OrmObject)

func MustOrmPersist

func MustOrmPersist(obj OrmObject)

func MustOrmToRow

func MustOrmToRow(obj OrmObject) (row map[string]string)

func MustOrmUpdate

func MustOrmUpdate(obj OrmObject)

func MustPing

func MustPing()

事务不可以ping,ping需要数据库存在

func MustQuery

func MustQuery(query string, args ...string) []map[string]string

func MustQueryOne

func MustQueryOne(query string, args ...string) map[string]string

如果没有数据不会报错

func MustRegisterTable

func MustRegisterTable(table Table)

向系统中注册表,不允许重复注册 不支持并发调用

func MustReplaceById

func MustReplaceById(tableName string, primaryKeyName string, row map[string]string) (lastInsertId int)

func MustRunSelectCommand

func MustRunSelectCommand(selectCommand *MysqlAst.SelectCommand) (mapValue []map[string]string)

func MustSetTableDataYaml

func MustSetTableDataYaml(yaml string)

设置表数据 注意会删除数据

func MustSyncDefaultDbConfig

func MustSyncDefaultDbConfig()

同步默认数据库配置

func MustSyncRegisterTable

func MustSyncRegisterTable()

同步注册进去的表(只会增加字段,保证不掉数据,会使用fmt显示有哪些字段存在问题. 不支持并发调用

func MustSyncTable

func MustSyncTable(tableConf Table)

func MustTransactionCallback

func MustTransactionCallback(f func(tx Tx))

使用默认数据库开启事务回调

func MustUpdateById

func MustUpdateById(tableName string, primaryKeyName string, row map[string]string)

func MustVerifyTableConfig

func MustVerifyTableConfig(tableConf Table)

func OrmPersist

func OrmPersist(obj OrmObject) (lastInsertId int, err error)

func OrmToRow

func OrmToRow(obj OrmObject) (row map[string]string, err error)

func Ping

func Ping() (err error)

事务不可以ping,ping需要数据库存在

func Query

func Query(query string, args ...string) (output []map[string]string, err error)

func QueryOne

func QueryOne(query string, args ...string) (output map[string]string, err error)

func ReplaceById

func ReplaceById(tableName string, primaryKeyName string, row map[string]string) (lastInsertId int, err error)

func SetDefaultDbConfig

func SetDefaultDbConfig(conf *DbConfig)

func SyncDbCommand

func SyncDbCommand()

func TransactionCallback

func TransactionCallback(db TransactionableDb, f func() error) (err error)

@deprecated transaction callback on beego.orm,but not depend on it 有可能会多次运行

func UpdateById

func UpdateById(tableName string, primaryKeyName string, row map[string]string) error

Types

type DB

type DB struct {
	DbQueryer
	*sql.DB
}

a wrap of database/sql.Db 表示一个数据库 这个可以建立很多连接

func GetDb

func GetDb() DB

func NewDb

func NewDb(db *sql.DB) DB

func (DB) Exec

func (q DB) Exec(query string, args ...string) (sql.Result, error)

func (*DB) GetTableData

func (db *DB) GetTableData(tableName string) (output []map[string]string, err error)

get all data of a table mostly for test

func (*DB) GetTableDataMap

func (db *DB) GetTableDataMap(tableName string, pkName string) (output map[string]map[string]string, err error)

func (*DB) MustGetTableData

func (db *DB) MustGetTableData(tableName string) (output []map[string]string)

func (*DB) MustGetTableDataMap

func (db *DB) MustGetTableDataMap(tableName string, pkName string) (output map[string]map[string]string)

func (DB) MustSetTablesDataYaml

func (db DB) MustSetTablesDataYaml(yaml string)

@deprecated

func (DB) Query

func (q DB) Query(query string, args ...string) (output []map[string]string, err error)

func (DB) SetTablesData

func (db DB) SetTablesData(data map[string][]map[string]string) (err error)

@deprecated Set some tables data in this database. mostly for test not guarantee next increment id will be!! 设置表数据 注意:

  • 会删除数据
  • 保证 auto_increase 的值是数据里面的最大值+1

func (DB) SetTablesDataYaml

func (db DB) SetTablesDataYaml(yaml string) (err error)

@deprecated

type DbConfig

type DbConfig struct {
	Username string // example: root
	Password string // example: password
	Host     string // example: 127.0.0.1
	DbName   string // example: kmg_test
}

func GetDbConfigFromConfig

func GetDbConfigFromConfig(p *kmgConfig.Parameter) *DbConfig

@deprecated

func GetDefaultDbConfig

func GetDefaultDbConfig() *DbConfig

func (*DbConfig) GetDsn

func (config *DbConfig) GetDsn() string

func (*DbConfig) GetDsnWithoutDbName

func (config *DbConfig) GetDsnWithoutDbName() string

type DbQueryer

type DbQueryer struct {
	SqlQueryer
}

表示一个数据库Queryer 可以拿去查数据库,

func (DbQueryer) DeleteById

func (q DbQueryer) DeleteById(tableName string, fieldName string, value string) error

func (DbQueryer) Exec

func (q DbQueryer) Exec(query string, args ...string) (sql.Result, error)

func (DbQueryer) GetAllInTable

func (q DbQueryer) GetAllInTable(tableName string) (output []map[string]string, err error)

func (DbQueryer) GetOneWhere

func (q DbQueryer) GetOneWhere(tableName string, fieldName string, value string) (output map[string]string, err error)

func (DbQueryer) Insert

func (q DbQueryer) Insert(tableName string, row map[string]string) (lastInsertId int, err error)

func (DbQueryer) MustRunSelectCommand

func (q DbQueryer) MustRunSelectCommand(selectCommand *MysqlAst.SelectCommand) (mapValue []map[string]string)

func (DbQueryer) Query

func (q DbQueryer) Query(query string, args ...string) (output []map[string]string, err error)

func (DbQueryer) QueryOne

func (q DbQueryer) QueryOne(query string, args ...string) (output map[string]string, err error)

func (DbQueryer) ReplaceById

func (q DbQueryer) ReplaceById(tableName string, primaryKeyName string, row map[string]string) (lastInsertId int, err error)

func (DbQueryer) UpdateById

func (q DbQueryer) UpdateById(tableName string, primaryKeyName string, row map[string]string) error

type DbType

type DbType string
const (
	DbTypeInt              DbType = `int(11) DEFAULT 0`
	DbTypeIntAutoIncrement DbType = `int(11) unsigned AUTO_INCREMENT`
	DbTypeString           DbType = `varchar(255) COLLATE utf8_bin DEFAULT ""`
	DbTypeLongString       DbType = `longtext COLLATE utf8_bin DEFAULT ""`
	DbTypeFloat            DbType = `float default 0`
	DbTypeDatetime         DbType = `datetime DEFAULT "0000-00-00 00:00:00"`
	DbTypeBool             DbType = `tinyint(4) DEFAULT 0`
	DbTypeLongBlob         DbType = `LONGBLOB`
)

func (DbType) GetMysqlFieldType

func (t DbType) GetMysqlFieldType() MysqlFieldType

type MysqlDataType

type MysqlDataType string
const (
	MysqlDataTypeVarchar  MysqlDataType = `varchar`
	MysqlDataTypeInt32    MysqlDataType = `int`
	MysqlDataTypeLongText MysqlDataType = `longtext`
	MysqlDataTypeFloat    MysqlDataType = `float`
	MysqlDataTypeDateTime MysqlDataType = `datetime`
	MysqlDataTypeInt8     MysqlDataType = `tinyint`
	MysqlDataTypeLongBlob MysqlDataType = `longblob`
)

type MysqlField

type MysqlField struct {
	Name string
	Type MysqlFieldType
}

type MysqlFieldType

type MysqlFieldType struct {
	DataType         MysqlDataType
	IsUnsigned       bool
	IsAutoIncrement  bool
	CharacterSetName string //utf8
	CollationName    string //utf8_bin
	Default          string
	StringLength     int
}

func (MysqlFieldType) Equal

func (t1 MysqlFieldType) Equal(t2 MysqlFieldType) bool

func (MysqlFieldType) String

func (t1 MysqlFieldType) String() string

type OrmObject

type OrmObject interface {
	GetIdFieldName() string
	GetTableName() string
}

func OrmFromRow

func OrmFromRow(obj OrmObject, row map[string]string) (OrmObject, error)

type SqlQueryer

type SqlQueryer interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
}

type SqlTxer

type SqlTxer interface {
	Commit() error
	Rollback() error
}

type Table

type Table struct {
	Name       string
	FieldList  map[string]DbType
	PrimaryKey string
	UniqueKey  [][]string
	Null       []string
}

读取数据库的表字段,不区分大小写(某些系统的mysql不区分大小写) 写入数据库的表字段,区分大小写

type TestDbConf

type TestDbConf struct {
	Db *DbConfig
}

type TransactionableDb

type TransactionableDb interface {
	Begin() error
	Commit() error
	Rollback() error
}

@deprecated

type Tx

type Tx struct {
	DbQueryer
	*sql.Tx
}

表示一个数据事务 这个只有一条连接

func NewTx

func NewTx(tx *sql.Tx) Tx

func (Tx) Exec

func (q Tx) Exec(query string, args ...string) (sql.Result, error)

func (Tx) Query

func (q Tx) Query(query string, args ...string) (output []map[string]string, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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