mysql

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2017 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnMetadata

type ColumnMetadata struct {
	ColumnName string // column name or code ?
	ColumnType string // column type
	NullAble   string // column null able

	// If Key is MUL, multiple occurrences of a given value are
	// permitted within the column. The column is the first column
	// of a nonunique index or a unique-valued index that can contain
	// NULL values.
	Key          string // column key type
	DefaultValue string // default value if have
	Extra        string // extra info, for example, auto_increment
}

ColumnMetadata metadata of a column

type DataBaseMetadata

type DataBaseMetadata struct {
	DatabaseName string           // database name
	Tables       []*TableMetadata // collection of tables
}

DataBaseMetadata metadata of a database

func (*DataBaseMetadata) GetSimpleMetadata added in v1.1.0

func (d *DataBaseMetadata) GetSimpleMetadata() (rt map[string]map[string]string)

GetSimpleMetadata

func (*DataBaseMetadata) GetTableMeta

func (d *DataBaseMetadata) GetTableMeta(tableName string) *TableMetadata

GetTableMeta

func (*DataBaseMetadata) HaveTable

func (d *DataBaseMetadata) HaveTable(sTableName string) bool

HaveTable

func (*DataBaseMetadata) TableHaveField

func (d *DataBaseMetadata) TableHaveField(sTableName string, sFieldName string) bool

TableHaveField

type MysqlAPI

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

MysqlAPI

func NewMysqlAPI

func NewMysqlAPI(dbURI string) *MysqlAPI

NewMysqlAPI create new MysqlAPI instance

func (*MysqlAPI) Connection

func (api *MysqlAPI) Connection() *sql.DB

Connection return

func (*MysqlAPI) Create

func (api *MysqlAPI) Create(table string, obj map[string]interface{}) (rs sql.Result, err error)

Create by table name and obj map

func (*MysqlAPI) CurrentDatabaseName

func (api *MysqlAPI) CurrentDatabaseName() string

CurrentDatabaseName return current database

func (*MysqlAPI) Delete

func (api *MysqlAPI) Delete(table string, id interface{}, obj map[string]interface{}) (rs sql.Result, err error)

Delete by table name and where obj

func (*MysqlAPI) GetConnectionPool

func (api *MysqlAPI) GetConnectionPool(dbURI string) *sql.DB

GetConnectionPool which Pool is Singleton Connection Pool

func (*MysqlAPI) GetDatabaseMetadata

func (api *MysqlAPI) GetDatabaseMetadata() *DataBaseMetadata

GetDatabaseMetadata return database meta

func (*MysqlAPI) SQL

func (api *MysqlAPI) SQL() *SQL

SQL instance

func (*MysqlAPI) Select

func (api *MysqlAPI) Select(table string, id interface{}, limit int, offset int, fields []interface{}, wheres map[string]goqu.Op, links []interface{}) (rs []map[string]interface{}, err error)

Select by table name , where or id

func (*MysqlAPI) Stop

func (api *MysqlAPI) Stop() *MysqlAPI

Stop MysqlAPI, clean connections

func (*MysqlAPI) Update

func (api *MysqlAPI) Update(table string, id interface{}, obj map[string]interface{}) (rs sql.Result, err error)

Update by table name and obj map

func (*MysqlAPI) UpdateAPIMetadata added in v1.1.0

func (api *MysqlAPI) UpdateAPIMetadata() *MysqlAPI

UpdateAPIMetadata use to update the metadata of the MySQLAPI instance

If database tables structure changed, it will be useful

type QueryOption

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

QueryConfig for Select method

type SQL

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

SQL return sqls by sql builder

func (*SQL) DeleteByTable

func (s *SQL) DeleteByTable(tableName string, mWhere map[string]interface{}) (sql string, err error)

DeleteByTable by where

func (*SQL) DeleteByTableAndId

func (s *SQL) DeleteByTableAndId(tableName string, id interface{}) (sql string, err error)

DeleteByTableAndId

func (*SQL) GetByTable

func (s *SQL) GetByTable(tableName string, opt QueryOption) (sql string, err error)

GetByTable with filter

func (*SQL) GetByTableAndID

func (s *SQL) GetByTableAndID(tableName string, id interface{}, opt QueryOption) (sql string, err error)

GetByTableAndID for specific record in table

func (*SQL) InsertByTable

func (s *SQL) InsertByTable(tableName string, record map[string]interface{}) (sql string, err error)

InsertByTable and record map

func (*SQL) UpdateByTableAndId

func (s *SQL) UpdateByTableAndId(tableName string, id interface{}, record map[string]interface{}) (sql string, err error)

UpdateByTable for update specific record by id

type TableMetadata

type TableMetadata struct {
	TableName string            //table name
	Columns   []*ColumnMetadata //collections of column
}

TableMetadata metadata of a table

func (*TableMetadata) GetPrimaryColumn

func (t *TableMetadata) GetPrimaryColumn() *ColumnMetadata

GetPrimaryColumn

func (*TableMetadata) HaveField

func (t *TableMetadata) HaveField(sFieldName string) bool

HaveField

Jump to

Keyboard shortcuts

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