mdb

package module
v0.0.0-...-c805acc Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2016 License: Apache-2.0 Imports: 13 Imported by: 1

README

mdb

Mabetle Go Database

Documentation

Overview

package mdb inculde many usefull functions for processing database. package entry is mdb.NewSql(sql.DB)

link program example: s:=mdb.Sql.NewLinkSql() s.Select(columns).From(table).Where(where).Args(args ...).Order(column).Desc(column).DoQuery()

Index

Constants

This section is empty.

Variables

View Source
var (
	// text type
	COLUMN_TYPE_TEXT_ARRAY = []string{"char", "varchar", "text", "tinytext", "mediumtext", "longtext"}
	// number type
	COLUMN_TYPE_NUMBER_ARRAY = []string{"int", "integer", "tinyint", "bigint", "smallint", "mediumint",
		"float", "double", "real", "decimal", "numeric"}
)

Functions

func BuildColumnsWhere

func BuildColumnsWhere(columns []string) string

return where Column = ? and cloumnB = ?

func BuildSelectColumns

func BuildSelectColumns(columns []string) string

Join columns, return "ColumnA, ColumnB"

func BuildValueHoder

func BuildValueHoder(args ...interface{}) string

Return ?,?,?

func BuildWhere

func BuildWhere(where string) string

func BuildWhereQuery

func BuildWhereQuery(sql, where string) string

func CheckErrorWithSucceedMsg

func CheckErrorWithSucceedMsg(err error, format string, args ...interface{})

print the succeed message.

func GetClearTableSql

func GetClearTableSql(table string) string

GetClearTableSql

func GetCountColumnsSql

func GetCountColumnsSql(table string) string

GetCountColumnsSql

func GetCountRowsSql

func GetCountRowsSql(table string) string

GetCountRowsSql

func GetDropTableSql

func GetDropTableSql(table string) string

GetDropTableSql

func GetIsHasIDSql

func GetIsHasIDSql(table string) string

GetIsHasIDSql

func GetModelFields

func GetModelFields(model interface{}) string

GetModelFields

func GetModelFieldsMap

func GetModelFieldsMap(model interface{}) map[string]string

GetModelFieldsMap

func GetRemoveRowSql

func GetRemoveRowSql(table string) string

GetRemoveRowSql

func GetSelectAllSql

func GetSelectAllSql(table string) string

GetSelectAllSql

func GetSqlBeginFrom

func GetSqlBeginFrom(sql string) string

GetSqlBeginFrom

func GetString

func GetString(value interface{}) string

GetString

func GetTableName

func GetTableName(model interface{}) string

GetTableName equals to TableName

func IsBlank

func IsBlank(value interface{}, name string) bool

func IsValidColumnName

func IsValidColumnName(column string) bool

func IsValidTableName

func IsValidTableName(table string) bool

Used for check provide table name if blank.

func IsZero

func IsZero(value interface{}, name string) bool

func ParseSqlTableName

func ParseSqlTableName(sql string) string

ParseSqLTableName gets table name from sql. from table

func PrintArrayFriendly

func PrintArrayFriendly(data [][]string)

PrintArrayFriendly

func PrintArrayVerticalFriendly

func PrintArrayVerticalFriendly(data [][]string)

func PrintCloumns

func PrintCloumns(cols []string)

PrintCloumns

func PrintData

func PrintData(data [][]string)

func PrintMap

func PrintMap(m map[string]string)

PrintMap prints map map has no sequence

func PrintMapWithColumns

func PrintMapWithColumns(m []map[string]interface{}, columns []string)

PrintMapWithColumns

func PrintModel

func PrintModel(model interface{})

PrintModel

func PrintModels

func PrintModels(models ...interface{})

PrintModels

func PrintRowData

func PrintRowData(row []string)

func PrintRowsArray

func PrintRowsArray(data [][]string)

PrintRowsArray

func QueryForXml

func QueryForXml(sql string, args ...interface{}) (result string)

QueryForXml

func QulifyWhere

func QulifyWhere(where string) string

func TableName

func TableName(model interface{}) string

TableName

func ToType

func ToType(i interface{}) (reflect.Type, error)

ToType

Types

type ConnErr

type ConnErr struct {
	mcore.RuntimeException
}

func NewConnErr

func NewConnErr(host, schema string) ConnErr

type DBService

type DBService struct {
	Sql  *Sql
	Xorm *Xorm
}

DBService holds Sql and Xorm db base application extends DBService.

func NewDBService

func NewDBService(sql *Sql, xorm *Xorm) *DBService

NewDBService creates DBService instance.

func (*DBService) GetSql

func (s *DBService) GetSql() *Sql

GetSql returns Sql

func (*DBService) GetXorm

func (s *DBService) GetXorm() *Xorm

GetXorm returns Xorm

type LinkSql

type LinkSql struct {
	*Sql
	// contains filtered or unexported fields
}

Link program.

func NewLinkSql

func NewLinkSql(sql *Sql) *LinkSql

func (*LinkSql) Args

func (s *LinkSql) Args(args ...interface{}) *LinkSql

func (*LinkSql) Asc

func (s *LinkSql) Asc(asc string) *LinkSql

func (*LinkSql) BuildQuery

func (s *LinkSql) BuildQuery() string

func (*LinkSql) Columns

func (s *LinkSql) Columns(columns string) *LinkSql

func (*LinkSql) Desc

func (s *LinkSql) Desc(desc string) *LinkSql

func (*LinkSql) DoDelete

func (s *LinkSql) DoDelete() error

func (*LinkSql) DoExec

func (s *LinkSql) DoExec() (r sql.Result, err error)

TODO

func (*LinkSql) DoQuery

func (s *LinkSql) DoQuery() (*sql.Rows, error)

=======================================

func (*LinkSql) From

func (s *LinkSql) From(table string) *LinkSql

func (*LinkSql) Order

func (s *LinkSql) Order(order string) *LinkSql

func (*LinkSql) Print

func (s *LinkSql) Print()

func (*LinkSql) Select

func (s *LinkSql) Select(columns string) *LinkSql

func (*LinkSql) Table

func (s *LinkSql) Table(table string) *LinkSql

func (*LinkSql) Where

func (s *LinkSql) Where(where string) *LinkSql

type MetaColumn

type MetaColumn struct {
	SchemaName string
	TableName  string
	ColumnName string

	ColumnDefault string // longtext in database
	Nullable      string // yes or no, varchar(3) in database
	DataType      string //	varchar long ...varchar(64) in database
	ColumnType    string // varchar(50), decimal(19, 2) ...
	ColumnKey     string // PRI or null
	ColumnComment string // 1024

	OrdinalPosition    int64 // col seq
	CharacterMaxLength int64 // varchar(500) is 500
	NumericPrecision   int64 // long(19) is 19
	NumericScale       int64 // number or null
	DatetimePrecision  int64 //
}

func (MetaColumn) HasDefault

func (c MetaColumn) HasDefault() (r bool)

func (MetaColumn) IsNullable

func (c MetaColumn) IsNullable() (r bool)

func (MetaColumn) IsPrimaryKey

func (c MetaColumn) IsPrimaryKey() (r bool)

type MetaDatabase

type MetaDatabase struct {
	SchemaName string
}

inspect database. most of meta relation functions depends on ROOT user or has select rights for database INFORMATION_SCHEMA.

Only for mysql.

type MetaTable

type MetaTable struct {
	SchemaName string
	TableName  string

	// when create a table, can set comment in mysql.
	TableComment string //2048
	Columns      []MetaColumn
}

type Query

type Query struct {
	Sql *Sql
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(sql *Sql) *Query

NewQuery

func (*Query) Columns

func (q *Query) Columns(columns string) *Query

Columns

func (*Query) GetQuerySql

func (q *Query) GetQuerySql() string

func (*Query) Order

func (q *Query) Order(order string) *Query

Order

func (*Query) Print

func (q *Query) Print(args ...interface{})

Query Print

func (*Query) Run

func (q *Query) Run(args ...interface{})

Query Run TODO what to return? execute query and return result.

func (*Query) SqlStr

func (q *Query) SqlStr(sql string) *Query

SqlStr

func (*Query) Table

func (q *Query) Table(table string) *Query

Query Table

func (*Query) Where

func (q *Query) Where(where string) *Query

Where

type Sql

type Sql struct {
	DB         *sql.DB
	SchemaName string
	Dialect    string // defautl to mysql.
	ShowSql    bool
}

Sql wrap sqlDB and provide many functions.

func New

func New() *Sql

New creates sql

func NewSql

func NewSql(db *sql.DB) *Sql

NewSql create a new Sql instance TODO add other dialect support

func (Sql) AlterAddColumn

func (s Sql) AlterAddColumn(table, column, dataType string) error

alter table, add column

func (Sql) AlterAddPrimaryKey

func (s Sql) AlterAddPrimaryKey(table string, colName string) error

alter table add primary key to specific column

func (Sql) AlterAddPrimaryKeyToIDColumn

func (s Sql) AlterAddPrimaryKeyToIDColumn(table string) error

alter table add primay key to ID column

func (Sql) AlterColumnCharDefault

func (s Sql) AlterColumnCharDefault(db, table, column string)

AlterColumnCharDefault

func (Sql) AlterColumnDataType

func (s Sql) AlterColumnDataType(table, column, dataType string) error

alter table, redifine column data type

func (Sql) AlterColumnDefault

func (s Sql) AlterColumnDefault(db, table, column string)

func (Sql) AlterColumnNumDefault

func (s Sql) AlterColumnNumDefault(db, table, column string)

func (Sql) AlterColumnToDecimal

func (s Sql) AlterColumnToDecimal(db, table, column, oldType string) error

alter table column to decimal

func (Sql) AlterDbCharDefault

func (s Sql) AlterDbCharDefault(db string)

func (Sql) AlterDbColumnDefault

func (s Sql) AlterDbColumnDefault(db string)

set varchar char to ” set int bigint to 0

func (Sql) AlterDbNumDefault

func (s Sql) AlterDbNumDefault(db string)

func (Sql) AlterDbToDecimal

func (s Sql) AlterDbToDecimal(db string, oldType string)

alter db all double column to decimal

func (Sql) AlterDropColumn

func (s Sql) AlterDropColumn(table, column string) error

alter table, drop column

func (Sql) AlterDropPrimaryKey

func (s Sql) AlterDropPrimaryKey(table string) error

alter table, drop primary key

func (Sql) AlterMetaColumnDefault

func (s Sql) AlterMetaColumnDefault(col MetaColumn)

func (Sql) AlterMetaColumnsDefault

func (s Sql) AlterMetaColumnsDefault(cols []MetaColumn)

func (Sql) AlterRenameColumn

func (s Sql) AlterRenameColumn(table, column, newName string) error

alter table, rename column name

func (Sql) AlterRenameTable

func (s Sql) AlterRenameTable(table, newName string) error

alter table, rename

func (Sql) AlterTableAddUniqueCloumn

func (s Sql) AlterTableAddUniqueCloumn(table, column string)

add unique constraint to column.

func (Sql) AlterTableAddUniqueWithName

func (s Sql) AlterTableAddUniqueWithName(table, name string, columns ...string)

add unique constraint to columns.

func (Sql) AlterTableCharDefault

func (s Sql) AlterTableCharDefault(db, table string)

func (Sql) AlterTableColumnDefault

func (s Sql) AlterTableColumnDefault(db, table string)

func (Sql) AlterTableDropUnique

func (s Sql) AlterTableDropUnique(table, constraintName string)

drop unique constraint need provide the constraint name.

func (Sql) AlterTableNumDefault

func (s Sql) AlterTableNumDefault(db, table string)

func (Sql) AlterTableToDecimal

func (s Sql) AlterTableToDecimal(db, table, oldType string) error

alter table all double column to decimal

func (Sql) BuildColumnsWhere

func (s Sql) BuildColumnsWhere(columns []string) string

return where ColumnA = ? and CloumnB = ?

func (Sql) BuildSelectColumns

func (s Sql) BuildSelectColumns(columns []string) string

Join columns , return "ColumnA, ColumnB"

func (Sql) BuildValueHoder

func (s Sql) BuildValueHoder(args ...interface{}) string

return ?,?,?

func (Sql) CheckErrorWithSucceedMsg

func (s Sql) CheckErrorWithSucceedMsg(err error, format string, args ...interface{})

func (Sql) ClearModel

func (s Sql) ClearModel(model interface{}) error

ClearModel

func (Sql) ClearModels

func (s Sql) ClearModels(models ...interface{}) error

ClearModels

func (Sql) ClearTable

func (s Sql) ClearTable(table string) error

ClearTable clear table rows

func (Sql) ClearTables

func (s Sql) ClearTables(tables ...string) error

ClearTables clears tables rows one by one

func (Sql) ColumnExec

func (s Sql) ColumnExec(table, column, format string) error

ColumnExec format include 2 string place holder

func (Sql) CountModelRows

func (s Sql) CountModelRows(model interface{}) (int64, error)

CountModelRows

func (Sql) CountTableColumns

func (s Sql) CountTableColumns(table string) int

CountTableColumns returns table rows number.

func (Sql) CountTableRows

func (s Sql) CountTableRows(table string) (int64, error)

CountTableRows returns table rows num.

func (Sql) CreateDatabase

func (s Sql) CreateDatabase(db string) (err error)

CreateDatabase create db TODO only work for mysql

func (Sql) DbTablesExec

func (s Sql) DbTablesExec(db string, format string) error

DbTablesExec loop all tables in db, format include 1 string place holder.

func (Sql) DisableTableRowColumn

func (s Sql) DisableTableRowColumn(table string, id interface{}, column string)

func (Sql) DropDatabase

func (s Sql) DropDatabase(db string) error

DropDatabase drop db

func (Sql) DropModelTable

func (s Sql) DropModelTable(model interface{}) error

DropModelTable

func (Sql) DropModelsTable

func (s Sql) DropModelsTable(models ...interface{}) error

DropModelsTable

func (Sql) DropTable

func (s Sql) DropTable(table string) error

DropTable drops table

func (Sql) DropTables

func (s Sql) DropTables(tables ...string) error

DropTables drops tables

func (Sql) EnableTableRowColumn

func (s Sql) EnableTableRowColumn(table string, id interface{}, column string)

Column value should be 0 or 1

func (Sql) Exec

func (s Sql) Exec(query string, v ...interface{}) (r sql.Result, err error)

Exec override sql.DB.Exec(), add some logs, print sql and args, when occur error print it.

func (Sql) ExecForHtml

func (s Sql) ExecForHtml(q string, args []interface{}, renderArgs ...string) string

func (Sql) ExportCsv

func (s Sql) ExportCsv(location string, sql string, args ...interface{}) (err error)

ExportCsv

func (Sql) GenTableCreateSql

func (s Sql) GenTableCreateSql(db, table string) string

Generate create table sql form database table. used for export exist tables struct.

func (Sql) GetColumnDataType

func (s Sql) GetColumnDataType(db, table, column string) (r string, err error)

GetColumnDataType return column datatype, varchar, int etc.

func (Sql) GetColumnDefault

func (s Sql) GetColumnDefault(db, table, column string) (r string, err error)

GetColumnDefault returns table column define

func (Sql) GetColumnType

func (s Sql) GetColumnType(db, table, column string) (r string, err error)

GetColumnType return column type. varchar(60), decimal(18,2), etc.

func (Sql) GetDbTableColumns

func (s Sql) GetDbTableColumns(dbName, table string) []string

GetDbTableColumns return table columns

func (Sql) GetMetaColumn

func (s Sql) GetMetaColumn(db, table, col string) MetaColumn

get table one column meta. FIXME too much query, should run more fast.

func (Sql) GetMetaColumns

func (s Sql) GetMetaColumns(db, table string) (r []MetaColumn)

get table all columns meta. loop all columns.

func (Sql) GetMetaDatabases

func (s Sql) GetMetaDatabases() (r []MetaDatabase)

get all database metas for loop. not used often, because user should know which database to process.

func (Sql) GetMetaTable

func (s Sql) GetMetaTable(db, table string) (m MetaTable)

get one Table meta. used for process one table.

func (Sql) GetMetaTables

func (s Sql) GetMetaTables(schema string) (r []MetaTable)

get all table meta from db. schema equal database. used for loop all tables.

func (Sql) GetQueryColumns

func (s Sql) GetQueryColumns(sql string, args ...interface{}) ([]string, error)

GetQueryColumns returns columns name in string array.

func (Sql) GetQueryRows

func (s Sql) GetQueryRows(sql string, args ...interface{}) (int64, error)

GetQueryRows returns query rows count

func (Sql) GetSchemaName

func (s Sql) GetSchemaName() string

GetSchemaName return schema name store in Sql.

func (Sql) GetSchemas

func (s Sql) GetSchemas() []string

GetSchemas return all dbs

func (Sql) GetTableColumns

func (s Sql) GetTableColumns(table string) ([]string, error)

GetTableColumns returns table column names

func (Sql) GetTableName

func (s Sql) GetTableName(model interface{}) string

GetTableName returns tablename

func (Sql) GetTableRowsJSONData

func (s Sql) GetTableRowsJSONData(table string) map[string]string

GetTableRowsJSONData gets table rows JSON data

func (Sql) GetTableRowsMap

func (s Sql) GetTableRowsMap(table string) ([]map[string]interface{}, []string, error)

GetTableRowsMap

func (Sql) GetTables

func (s Sql) GetTables(db string) []string

GetTables if db not exists, return blank array

func (Sql) InitTableRow

func (s Sql) InitTableRow(table string, columns []string, values ...interface{})

Create a new row with Column and Values, other columns use database default value. not include id id is generated by db UUID

func (Sql) InitTableRowWithID

func (s Sql) InitTableRowWithID(table string, id interface{})

Create a new row with id Table must has ID column

func (Sql) IsBlank

func (s Sql) IsBlank(v interface{}, name string) bool

func (Sql) IsColumnNullable

func (s Sql) IsColumnNullable(db, table, column string) (r bool, err error)

IsColumnNullable returns ture or false

func (Sql) IsColumnPrimary

func (s Sql) IsColumnPrimary(db, table, column string) (r bool, err error)

IsColumnPrimary returns true or false

func (Sql) IsDbExistTable

func (s Sql) IsDbExistTable(db, table string) bool

IsDbExistTable check db tabke exists.

func (Sql) IsDbTableExistColumn

func (s Sql) IsDbTableExistColumn(db, table, column string) bool

IsDbTableExistColumn check db table column exists.

func (Sql) IsExistColumn

func (s Sql) IsExistColumn(table, column string) (r bool)

IsExistColumn checks table column exists.

func (Sql) IsExistTable

func (s Sql) IsExistTable(table string) bool

IsExistTable checks table exists.

func (Sql) IsHasDatabase

func (s Sql) IsHasDatabase(db string) bool

IsHasDatabase check db exists TODO only work for mysql

func (Sql) IsHasTable

func (s Sql) IsHasTable(table string) bool

IsHasTable check table exists.

func (Sql) IsModelHasRows

func (s Sql) IsModelHasRows(model interface{}) (r bool, err error)

IsModelHasRows

func (Sql) IsModelQueryHasRows

func (s Sql) IsModelQueryHasRows(model interface{}, query string, args ...interface{}) bool

IsModelQueryHasRows

func (Sql) IsQueryHasRows

func (s Sql) IsQueryHasRows(sql string, args ...interface{}) bool

IsQueryHasRows returns query rows exists. if error, return false

func (Sql) IsTableHasColumn

func (s Sql) IsTableHasColumn(table string, column string) bool

IsTableHasColumn equals to IsExistColumn

func (Sql) IsTableHasID

func (s Sql) IsTableHasID(table string, id interface{}) bool

IsTableHasID checks if table has specific id

func (Sql) IsTableHasRowsByColumns

func (s Sql) IsTableHasRowsByColumns(table string, columns []string, values ...interface{}) (b bool)

IsTableHasRowsByColumns checks table has example IsTableHasRowsByColumns(table, []string{"OrgName","Flag"}, "一局") TODO check

func (Sql) IsTableQueryHasRows

func (s Sql) IsTableQueryHasRows(table, query string, args ...interface{}) (r bool)

IsTableQueryHasRows checks table query has rows

func (Sql) IsValidTableName

func (s Sql) IsValidTableName(table string) bool

func (Sql) IsZero

func (s Sql) IsZero(v interface{}, name string) bool

func (*Sql) LinkSql

func (s *Sql) LinkSql() *LinkSql

use Sql for entries

func (Sql) Log

func (s Sql) Log(query string, args ...interface{})

SqlLogger Log

func (Sql) ModelQuery

func (s Sql) ModelQuery(modelType interface{}, qs string, args ...interface{}) interface{}

ModelQuery

func (*Sql) NewQuery

func (s *Sql) NewQuery() *Query

NewQuery

func (*Sql) NewTable

func (s *Sql) NewTable(table string) *Table

NewTable create a new Table instance. Table extends from Sql

func (Sql) Ping

func (s Sql) Ping() error

func (Sql) PrintDBTables

func (s Sql) PrintDBTables(db string)

PrintDBTables TODO only work for mysql

func (Sql) PrintDBTablesDetail

func (s Sql) PrintDBTablesDetail(db string)

PrintDBTablesDetail TODO only work for mysql

func (Sql) PrintDatabases

func (s Sql) PrintDatabases()

PrintDatabases TODO only work for mysql

func (*Sql) PrintModel

func (s *Sql) PrintModel(model interface{})

PrintModel

func (*Sql) PrintModelTable

func (s *Sql) PrintModelTable(model interface{})

PrintModelTable

func (*Sql) PrintModelTableFriendly

func (s *Sql) PrintModelTableFriendly(model interface{})

PrintModelTableFriendly

func (*Sql) PrintModelTableQuery

func (s *Sql) PrintModelTableQuery(model interface{}, ql string, args ...interface{})

PrintModelTableQuery

func (*Sql) PrintModelTableQueryVertical

func (s *Sql) PrintModelTableQueryVertical(model interface{}, ql string, args ...interface{})

PrintModelTableQueryVertical

func (*Sql) PrintModelTableVertical

func (s *Sql) PrintModelTableVertical(model interface{})

PrintModelTableVertical

func (*Sql) PrintModels

func (s *Sql) PrintModels(models ...interface{})

PrintModels

func (*Sql) PrintQuery

func (s *Sql) PrintQuery(q string, args ...interface{})

PrintQuery print query.

func (Sql) PrintQueryData

func (s Sql) PrintQueryData(sql string, args ...interface{})

func (*Sql) PrintQueryFriendly

func (s *Sql) PrintQueryFriendly(q string, args ...interface{})

PrintQueryFriendly prints query friendly.

func (*Sql) PrintQueryInJSONFormat

func (s *Sql) PrintQueryInJSONFormat(sql string, args ...interface{})

PrintQueryInJSONFormat prints query in JSON format.

func (*Sql) PrintQueryVertical

func (s *Sql) PrintQueryVertical(q string, args ...interface{})

PrintQueryVertical prints query vertical.

func (*Sql) PrintTable

func (s *Sql) PrintTable(table string)

PrintTable prints table

func (Sql) PrintTableColumns

func (s Sql) PrintTableColumns(db string, table string)

PrintTableColumns TODO only work for mysql

func (Sql) PrintTableColumnsDetail

func (s Sql) PrintTableColumnsDetail(db string, table string)

PrintTableColumnsDetail TODO only work for mysql

func (*Sql) PrintTableFriendly

func (s *Sql) PrintTableFriendly(table string)

PrintTableFriendly print table friendly.

func (*Sql) PrintTableInJSONFormat

func (s *Sql) PrintTableInJSONFormat(table string)

PrintTableInJSONFormat prints table in JSON format.

func (*Sql) PrintTableQuery

func (s *Sql) PrintTableQuery(table string, ql string, args ...interface{})

PrintTableQuery print table query.

func (*Sql) PrintTableQueryVertical

func (s *Sql) PrintTableQueryVertical(table string, ql string, args ...interface{})

PrintTableQueryVertical print table query vertical.

func (*Sql) PrintTableVertical

func (s *Sql) PrintTableVertical(table string)

PrintTableVertical prints table vertical

func (Sql) Query

func (s Sql) Query(query string, args ...interface{}) (*sql.Rows, error)

Query overide sql.DB Query, add logs

func (Sql) QueryColumnForArray

func (s Sql) QueryColumnForArray(sql string, args ...interface{}) (r []string)

QueryColumnForArray only one column in sql, mulity rows wrap to array

func (Sql) QueryForArray

func (s Sql) QueryForArray(withHeader bool, sql string, args ...interface{}) (result [][]string)

QueryForArray use [][]string array to store sql query result. if withHeader is true, the result contain column names in array first element.

func (Sql) QueryForArrayWithHeader

func (s Sql) QueryForArrayWithHeader(query string, args ...interface{}) [][]string

result [][]string include header

func (Sql) QueryForArrayWithoutHeader

func (s Sql) QueryForArrayWithoutHeader(query string, args ...interface{}) [][]string

result [][]string not include header

func (Sql) QueryForBool

func (s Sql) QueryForBool(sql string, args ...interface{}) bool

QueryForBool returns bool result.

func (Sql) QueryForData

func (s Sql) QueryForData(sql string, args ...interface{}) (rowsData [][]string)

QueryForJsonData

func (Sql) QueryForDataArray

func (s Sql) QueryForDataArray(q string, args ...interface{}) (data [][]string, columns []string)

QueryForArrayData

func (Sql) QueryForFloat

func (s Sql) QueryForFloat(sql string, args ...interface{}) (r float64, err error)

func (Sql) QueryForFloatNoError

func (s Sql) QueryForFloatNoError(sql string, args ...interface{}) float64

func (Sql) QueryForHtml

func (s Sql) QueryForHtml(q string, args []interface{}, renderArgs ...string) string

QueryForHtml

func (Sql) QueryForInt

func (s Sql) QueryForInt(sql string, args ...interface{}) (r int64, err error)

QueryForInt return query int result. Must only one column in sql. eg. 1.select count(*) from table eg. 2.select Age from table where Id = ? if more than one column, return err if not a int column return err

func (Sql) QueryForIntNoError

func (s Sql) QueryForIntNoError(sql string, args ...interface{}) int64

QueryForIntNoError returns int result.

func (Sql) QueryForJSONData

func (s Sql) QueryForJSONData(sql string, args ...interface{}) map[string]string

QueryForJSONData returns Map key is rows id, value stores row marshal JSON data. marshal row to string. not a good way.

func (Sql) QueryForMaps

func (s Sql) QueryForMaps(sql string, args ...interface{}) (JSONDatas []map[string]interface{}, columns []string, err error)

QueryForMaps query for maps JSONDatas holds rows key and value columns holds include columns good ways to store query result. because map has no sequence concepts, so columns is needed when access columns.

func (Sql) QueryForString

func (s Sql) QueryForString(sql string, args ...interface{}) (r string, err error)

QueryForString returns string value of a column show only one column in sql, eg: selelct Name from table wehre id = ? if more than one clolumn or not found any rows returns error not restrict in string column, support all data types

func (Sql) QueryForStringNoError

func (s Sql) QueryForStringNoError(sql string, args ...interface{}) string

QueryForStringNoError returns string result.

func (Sql) QueryMetaColumns

func (s Sql) QueryMetaColumns(db, where string, args ...interface{}) (r []MetaColumn)

not specific table, return all columns match conditions

func (Sql) QueryRow

func (s Sql) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow overide sql.DB QueryRow, add logs

func (Sql) QueryToExcel

func (s Sql) QueryToExcel(out io.Writer,
	include string,
	exclude string,
	q string, args ...interface{}) error

QueryToExcel NoLocal support

func (Sql) QueryToExcelFile

func (s Sql) QueryToExcelFile(
	location string,
	include string,
	exclude string,
	q string, args ...interface{}) error

QueryToExcelFile

func (Sql) QueryToExcelFileWithLocale

func (s Sql) QueryToExcelFileWithLocale(
	location string,
	table string,
	include string,
	exclude string,
	locale string,
	enableLocale bool,
	q string, args ...interface{}) error

QueryToExcelFileWithLocale

func (Sql) QueryToExcelWithLocale

func (s Sql) QueryToExcelWithLocale(out io.Writer,
	table string,
	include string,
	exclude string,
	locale string,
	enableLocale bool,
	q string, args ...interface{}) error

QueryToExcelWithLocale locale enableLocaleHeader

func (Sql) RemoveRow

func (s Sql) RemoveRow(table string, id interface{})

Equal to RemoveTableRow()

func (Sql) RemoveRows

func (s Sql) RemoveRows(table string, columns []string, args ...interface{})

Remove rows by conditions

func (Sql) RemoveTableRow

func (s Sql) RemoveTableRow(table string, id interface{}) error

RemoveTableRow removes table row with id.

func (Sql) RemoveWhereRows

func (s Sql) RemoveWhereRows(table string, where string, whereArgs ...interface{})

Remove rows by query

func (*Sql) SetDialect

func (s *Sql) SetDialect(dialect string) *Sql

SetDialect set sql dialect.

func (*Sql) SetShowSql

func (s *Sql) SetShowSql(b bool)

func (Sql) StatAvgColumn

func (s Sql) StatAvgColumn(table string, column string, where string, args ...interface{}) float64

func (Sql) StatMaxColumn

func (s Sql) StatMaxColumn(table string, column string, where string, args ...interface{}) float64

func (Sql) StatMinColumn

func (s Sql) StatMinColumn(table string, column string, where string, args ...interface{}) float64

func (Sql) StatSumColumn

func (s Sql) StatSumColumn(table string, column string, where string, args ...interface{}) float64

SumNoError(stat_sum_org, income, BuFlag = ?, 'jijian')

func (Sql) TableExec

func (s Sql) TableExec(table string, format string) error

TableExec format include 1 string place holder

func (Sql) UpdateTableColumn

func (s Sql) UpdateTableColumn(table string, column string, newValue interface{}, where string, whereArgs ...interface{})

update column value

func (Sql) UpdateTableRowColumn

func (s Sql) UpdateTableRowColumn(table string, id interface{}, column string, newValue interface{})

update a row column value.

func (*Sql) Use

func (s *Sql) Use(db *sql.DB, schemaName string) *Sql

Use which schema/database.

type SqlRunError

type SqlRunError struct {
	mcore.RuntimeException
	// contains filtered or unexported fields
}

not a fatal error.

func NewSqlRunError

func NewSqlRunError(sql string, err error) SqlRunError

func (SqlRunError) Error

func (e SqlRunError) Error() string

overide default Error.

type Table

type Table struct {
	*Sql
	Name string
}

Table defines Table

func NewTable

func NewTable(sql *Sql, table string) *Table

NewTable creates Table

func (Table) Clear

func (t Table) Clear()

Clear clears table rows.

func (Table) CountColumns

func (t Table) CountColumns() int

CountColumns return table column numbers.

func (Table) CountRows

func (t Table) CountRows() (int64, error)

CountRows returns table rows number.

func (Table) Drop

func (t Table) Drop()

Drop drops table

func (Table) GetColumns

func (t Table) GetColumns() ([]string, error)

GetColumns returns table column names.

func (Table) GetRowsJSONData

func (t Table) GetRowsJSONData() map[string]string

GetRowsJSONData returns table rows JSON data.

func (Table) IsHasRow

func (t Table) IsHasRow(id interface{}) bool

IsHasRow checks table id row exists.

func (Table) Print

func (t Table) Print()

Print prints table datas.

func (Table) RemoveRow

func (t Table) RemoveRow(id interface{}) error

RemoveRow table id row

type Xorm

type Xorm struct {
	*xorm.Engine
}

Xorm extends xorm.Engine and mdb.Sql. so we can provide more functions.

func NewXorm

func NewXorm(e *xorm.Engine) *Xorm

func (Xorm) DropMigrate

func (s Xorm) DropMigrate(models ...interface{}) error

func (Xorm) DropTables

func (s Xorm) DropTables(models ...interface{}) error

Drop

func (Xorm) Find

func (s Xorm) Find(beans interface{}, condiBeans ...interface{}) error

Find wraps xorm Find.

func (Xorm) GetById

func (s Xorm) GetById(model interface{}, id interface{}) (bool, error)

GetById

func (Xorm) Insert

func (s Xorm) Insert(model interface{}) (int64, error)

Overide Engine.Insert

func (Xorm) Migrate

func (s Xorm) Migrate(models ...interface{}) error

Migrate models

func (Xorm) Ping

func (s Xorm) Ping() error

func (Xorm) Save

func (s Xorm) Save(model interface{}) (int64, error)

equal to Insert.

func (Xorm) SaveOrUpdate

func (s Xorm) SaveOrUpdate(model interface{}) (int64, error)

SaveOrUpdate

func (Xorm) Update

func (s Xorm) Update(model interface{}) (int64, error)

model must have field Id and Id not null.

func (Xorm) UuidSave

func (s Xorm) UuidSave(model interface{}) (int64, error)

Id is uuid value. model is a pointer.

Directories

Path Synopsis
ioc
wrap mysql driver.
wrap mysql driver.
implement for SimpleTable
implement for SimpleTable

Jump to

Keyboard shortcuts

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