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 ¶
- Variables
- func BuildColumnsWhere(columns []string) string
- func BuildSelectColumns(columns []string) string
- func BuildValueHoder(args ...interface{}) string
- func BuildWhere(where string) string
- func BuildWhereQuery(sql, where string) string
- func CheckErrorWithSucceedMsg(err error, format string, args ...interface{})
- func GetClearTableSql(table string) string
- func GetCountColumnsSql(table string) string
- func GetCountRowsSql(table string) string
- func GetDropTableSql(table string) string
- func GetIsHasIDSql(table string) string
- func GetModelFields(model interface{}) string
- func GetModelFieldsMap(model interface{}) map[string]string
- func GetRemoveRowSql(table string) string
- func GetSelectAllSql(table string) string
- func GetSqlBeginFrom(sql string) string
- func GetString(value interface{}) string
- func GetTableName(model interface{}) string
- func IsBlank(value interface{}, name string) bool
- func IsValidColumnName(column string) bool
- func IsValidTableName(table string) bool
- func IsZero(value interface{}, name string) bool
- func ParseSqlTableName(sql string) string
- func PrintArrayFriendly(data [][]string)
- func PrintArrayVerticalFriendly(data [][]string)
- func PrintCloumns(cols []string)
- func PrintData(data [][]string)
- func PrintMap(m map[string]string)
- func PrintMapWithColumns(m []map[string]interface{}, columns []string)
- func PrintModel(model interface{})
- func PrintModels(models ...interface{})
- func PrintRowData(row []string)
- func PrintRowsArray(data [][]string)
- func QueryForXml(sql string, args ...interface{}) (result string)
- func QulifyWhere(where string) string
- func TableName(model interface{}) string
- func ToType(i interface{}) (reflect.Type, error)
- type ConnErr
- type DBService
- type LinkSql
- func (s *LinkSql) Args(args ...interface{}) *LinkSql
- func (s *LinkSql) Asc(asc string) *LinkSql
- func (s *LinkSql) BuildQuery() string
- func (s *LinkSql) Columns(columns string) *LinkSql
- func (s *LinkSql) Desc(desc string) *LinkSql
- func (s *LinkSql) DoDelete() error
- func (s *LinkSql) DoExec() (r sql.Result, err error)
- func (s *LinkSql) DoQuery() (*sql.Rows, error)
- func (s *LinkSql) From(table string) *LinkSql
- func (s *LinkSql) Order(order string) *LinkSql
- func (s *LinkSql) Print()
- func (s *LinkSql) Select(columns string) *LinkSql
- func (s *LinkSql) Table(table string) *LinkSql
- func (s *LinkSql) Where(where string) *LinkSql
- type MetaColumn
- type MetaDatabase
- type MetaTable
- type Query
- func (q *Query) Columns(columns string) *Query
- func (q *Query) GetQuerySql() string
- func (q *Query) Order(order string) *Query
- func (q *Query) Print(args ...interface{})
- func (q *Query) Run(args ...interface{})
- func (q *Query) SqlStr(sql string) *Query
- func (q *Query) Table(table string) *Query
- func (q *Query) Where(where string) *Query
- type Sql
- func (s Sql) AlterAddColumn(table, column, dataType string) error
- func (s Sql) AlterAddPrimaryKey(table string, colName string) error
- func (s Sql) AlterAddPrimaryKeyToIDColumn(table string) error
- func (s Sql) AlterColumnCharDefault(db, table, column string)
- func (s Sql) AlterColumnDataType(table, column, dataType string) error
- func (s Sql) AlterColumnDefault(db, table, column string)
- func (s Sql) AlterColumnNumDefault(db, table, column string)
- func (s Sql) AlterColumnToDecimal(db, table, column, oldType string) error
- func (s Sql) AlterDbCharDefault(db string)
- func (s Sql) AlterDbColumnDefault(db string)
- func (s Sql) AlterDbNumDefault(db string)
- func (s Sql) AlterDbToDecimal(db string, oldType string)
- func (s Sql) AlterDropColumn(table, column string) error
- func (s Sql) AlterDropPrimaryKey(table string) error
- func (s Sql) AlterMetaColumnDefault(col MetaColumn)
- func (s Sql) AlterMetaColumnsDefault(cols []MetaColumn)
- func (s Sql) AlterRenameColumn(table, column, newName string) error
- func (s Sql) AlterRenameTable(table, newName string) error
- func (s Sql) AlterTableAddUniqueCloumn(table, column string)
- func (s Sql) AlterTableAddUniqueWithName(table, name string, columns ...string)
- func (s Sql) AlterTableCharDefault(db, table string)
- func (s Sql) AlterTableColumnDefault(db, table string)
- func (s Sql) AlterTableDropUnique(table, constraintName string)
- func (s Sql) AlterTableNumDefault(db, table string)
- func (s Sql) AlterTableToDecimal(db, table, oldType string) error
- func (s Sql) BuildColumnsWhere(columns []string) string
- func (s Sql) BuildSelectColumns(columns []string) string
- func (s Sql) BuildValueHoder(args ...interface{}) string
- func (s Sql) CheckErrorWithSucceedMsg(err error, format string, args ...interface{})
- func (s Sql) ClearModel(model interface{}) error
- func (s Sql) ClearModels(models ...interface{}) error
- func (s Sql) ClearTable(table string) error
- func (s Sql) ClearTables(tables ...string) error
- func (s Sql) ColumnExec(table, column, format string) error
- func (s Sql) CountModelRows(model interface{}) (int64, error)
- func (s Sql) CountTableColumns(table string) int
- func (s Sql) CountTableRows(table string) (int64, error)
- func (s Sql) CreateDatabase(db string) (err error)
- func (s Sql) DbTablesExec(db string, format string) error
- func (s *Sql) DisableShowSql()
- func (s Sql) DisableTableRowColumn(table string, id interface{}, column string)
- func (s Sql) DropDatabase(db string) error
- func (s Sql) DropModelTable(model interface{}) error
- func (s Sql) DropModelsTable(models ...interface{}) error
- func (s Sql) DropTable(table string) error
- func (s Sql) DropTables(tables ...string) error
- func (s *Sql) EnableShowSql()
- func (s Sql) EnableTableRowColumn(table string, id interface{}, column string)
- func (s Sql) Exec(query string, v ...interface{}) (r sql.Result, err error)
- func (s Sql) ExecForHtml(q string, args []interface{}, renderArgs ...string) string
- func (s Sql) ExportCsv(location string, sql string, args ...interface{}) (err error)
- func (s Sql) GenTableCreateSql(db, table string) string
- func (s Sql) GetColumnDataType(db, table, column string) (r string, err error)
- func (s Sql) GetColumnDefault(db, table, column string) (r string, err error)
- func (s Sql) GetColumnType(db, table, column string) (r string, err error)
- func (s Sql) GetDbTableColumns(dbName, table string) []string
- func (s Sql) GetMetaColumn(db, table, col string) MetaColumn
- func (s Sql) GetMetaColumns(db, table string) (r []MetaColumn)
- func (s Sql) GetMetaDatabases() (r []MetaDatabase)
- func (s Sql) GetMetaTable(db, table string) (m MetaTable)
- func (s Sql) GetMetaTables(schema string) (r []MetaTable)
- func (s Sql) GetQueryColumns(sql string, args ...interface{}) ([]string, error)
- func (s Sql) GetQueryRows(sql string, args ...interface{}) (int64, error)
- func (s Sql) GetSchemaName() string
- func (s Sql) GetSchemas() []string
- func (s Sql) GetTableColumns(table string) ([]string, error)
- func (s Sql) GetTableName(model interface{}) string
- func (s Sql) GetTableRowsJSONData(table string) map[string]string
- func (s Sql) GetTableRowsMap(table string) ([]map[string]interface{}, []string, error)
- func (s Sql) GetTables(db string) []string
- func (s Sql) InitTableRow(table string, columns []string, values ...interface{})
- func (s Sql) InitTableRowWithID(table string, id interface{})
- func (s Sql) IsBlank(v interface{}, name string) bool
- func (s Sql) IsColumnNullable(db, table, column string) (r bool, err error)
- func (s Sql) IsColumnPrimary(db, table, column string) (r bool, err error)
- func (s Sql) IsDbExistTable(db, table string) bool
- func (s Sql) IsDbTableExistColumn(db, table, column string) bool
- func (s Sql) IsExistColumn(table, column string) (r bool)
- func (s Sql) IsExistTable(table string) bool
- func (s Sql) IsHasDatabase(db string) bool
- func (s Sql) IsHasTable(table string) bool
- func (s Sql) IsModelHasRows(model interface{}) (r bool, err error)
- func (s Sql) IsModelQueryHasRows(model interface{}, query string, args ...interface{}) bool
- func (s Sql) IsQueryHasRows(sql string, args ...interface{}) bool
- func (s Sql) IsTableHasColumn(table string, column string) bool
- func (s Sql) IsTableHasID(table string, id interface{}) bool
- func (s Sql) IsTableHasRowsByColumns(table string, columns []string, values ...interface{}) (b bool)
- func (s Sql) IsTableQueryHasRows(table, query string, args ...interface{}) (r bool)
- func (s Sql) IsValidTableName(table string) bool
- func (s Sql) IsZero(v interface{}, name string) bool
- func (s *Sql) LinkSql() *LinkSql
- func (s Sql) Log(query string, args ...interface{})
- func (s Sql) ModelQuery(modelType interface{}, qs string, args ...interface{}) interface{}
- func (s *Sql) NewQuery() *Query
- func (s *Sql) NewTable(table string) *Table
- func (s Sql) Ping() error
- func (s Sql) PrintDBTables(db string)
- func (s Sql) PrintDBTablesDetail(db string)
- func (s Sql) PrintDatabases()
- func (s *Sql) PrintModel(model interface{})
- func (s *Sql) PrintModelTable(model interface{})
- func (s *Sql) PrintModelTableFriendly(model interface{})
- func (s *Sql) PrintModelTableQuery(model interface{}, ql string, args ...interface{})
- func (s *Sql) PrintModelTableQueryVertical(model interface{}, ql string, args ...interface{})
- func (s *Sql) PrintModelTableVertical(model interface{})
- func (s *Sql) PrintModels(models ...interface{})
- func (s *Sql) PrintQuery(q string, args ...interface{})
- func (s Sql) PrintQueryData(sql string, args ...interface{})
- func (s *Sql) PrintQueryFriendly(q string, args ...interface{})
- func (s *Sql) PrintQueryInJSONFormat(sql string, args ...interface{})
- func (s *Sql) PrintQueryVertical(q string, args ...interface{})
- func (s *Sql) PrintTable(table string)
- func (s Sql) PrintTableColumns(db string, table string)
- func (s Sql) PrintTableColumnsDetail(db string, table string)
- func (s *Sql) PrintTableFriendly(table string)
- func (s *Sql) PrintTableInJSONFormat(table string)
- func (s *Sql) PrintTableQuery(table string, ql string, args ...interface{})
- func (s *Sql) PrintTableQueryVertical(table string, ql string, args ...interface{})
- func (s *Sql) PrintTableVertical(table string)
- func (s Sql) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (s Sql) QueryColumnForArray(sql string, args ...interface{}) (r []string)
- func (s Sql) QueryForArray(withHeader bool, sql string, args ...interface{}) (result [][]string)
- func (s Sql) QueryForArrayWithHeader(query string, args ...interface{}) [][]string
- func (s Sql) QueryForArrayWithoutHeader(query string, args ...interface{}) [][]string
- func (s Sql) QueryForBool(sql string, args ...interface{}) bool
- func (s Sql) QueryForData(sql string, args ...interface{}) (rowsData [][]string)
- func (s Sql) QueryForDataArray(q string, args ...interface{}) (data [][]string, columns []string)
- func (s Sql) QueryForFloat(sql string, args ...interface{}) (r float64, err error)
- func (s Sql) QueryForFloatNoError(sql string, args ...interface{}) float64
- func (s Sql) QueryForHtml(q string, args []interface{}, renderArgs ...string) string
- func (s Sql) QueryForInt(sql string, args ...interface{}) (r int64, err error)
- func (s Sql) QueryForIntNoError(sql string, args ...interface{}) int64
- func (s Sql) QueryForJSONData(sql string, args ...interface{}) map[string]string
- func (s Sql) QueryForMaps(sql string, args ...interface{}) (rowMaps []map[string]interface{}, columns []string, err error)
- func (s Sql) QueryForString(sql string, args ...interface{}) (r string, err error)
- func (s Sql) QueryForStringNoError(sql string, args ...interface{}) string
- func (s Sql) QueryMetaColumns(db, where string, args ...interface{}) (r []MetaColumn)
- func (s Sql) QueryRow(query string, args ...interface{}) *sql.Row
- func (s Sql) QueryToExcel(out io.Writer, include string, exclude string, q string, args ...interface{}) error
- func (s Sql) QueryToExcelFile(location string, include string, exclude string, q string, args ...interface{}) error
- func (s Sql) QueryToExcelFileWithLocale(location string, table string, include string, exclude string, locale string, ...) error
- func (s Sql) QueryToExcelWithLocale(out io.Writer, table string, include string, exclude string, locale string, ...) error
- func (s Sql) RemoveRow(table string, id interface{})
- func (s Sql) RemoveRows(table string, columns []string, args ...interface{})
- func (s Sql) RemoveTableRow(table string, id interface{}) error
- func (s Sql) RemoveWhereRows(table string, where string, whereArgs ...interface{})
- func (s *Sql) SetDialect(dialect string) *Sql
- func (s *Sql) SetShowSql(b bool)
- func (s Sql) StatAvgColumn(table string, column string, where string, args ...interface{}) float64
- func (s Sql) StatMaxColumn(table string, column string, where string, args ...interface{}) float64
- func (s Sql) StatMinColumn(table string, column string, where string, args ...interface{}) float64
- func (s Sql) StatSumColumn(table string, column string, where string, args ...interface{}) float64
- func (s Sql) TableExec(table string, format string) error
- func (s Sql) UpdateTableColumn(table string, column string, newValue interface{}, where string, ...)
- func (s Sql) UpdateTableRowColumn(table string, id interface{}, column string, newValue interface{})
- func (s *Sql) Use(db *sql.DB, schemaName string) *Sql
- type SqlRunError
- type Table
- func (t Table) Clear()
- func (t Table) CountColumns() int
- func (t Table) CountRows() (int64, error)
- func (t Table) Drop()
- func (t Table) GetColumns() ([]string, error)
- func (t Table) GetRowsJSONData() map[string]string
- func (t Table) IsHasRow(id interface{}) bool
- func (t Table) Print()
- func (t Table) RemoveRow(id interface{}) error
- type Xorm
- func (s Xorm) DropMigrate(models ...interface{}) error
- func (s Xorm) DropTables(models ...interface{}) error
- func (s Xorm) Find(beans interface{}, condiBeans ...interface{}) error
- func (s Xorm) GetById(model interface{}, id interface{}) (bool, error)
- func (s Xorm) Insert(model interface{}) (int64, error)
- func (s Xorm) Migrate(models ...interface{}) error
- func (s Xorm) Ping() error
- func (s Xorm) Save(model interface{}) (int64, error)
- func (s Xorm) SaveOrUpdate(model interface{}) (int64, error)
- func (s Xorm) Update(model interface{}) (int64, error)
- func (s Xorm) UuidSave(model interface{}) (int64, error)
Constants ¶
This section is empty.
Variables ¶
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"} )
var KeyShowSql = "MDB_SHOW_SQL"
Functions ¶
func BuildColumnsWhere ¶
return where Column = ? and cloumnB = ?
func BuildSelectColumns ¶
Join columns, return "ColumnA, ColumnB"
func BuildWhere ¶
func BuildWhereQuery ¶
func CheckErrorWithSucceedMsg ¶
print the succeed message.
func GetModelFieldsMap ¶
GetModelFieldsMap
func IsValidColumnName ¶
func IsValidTableName ¶
Used for check provide table name if blank.
func ParseSqlTableName ¶
ParseSqLTableName gets table name from sql. from table
func PrintArrayVerticalFriendly ¶
func PrintArrayVerticalFriendly(data [][]string)
func PrintMapWithColumns ¶
PrintMapWithColumns
func PrintRowData ¶
func PrintRowData(row []string)
func QulifyWhere ¶
Types ¶
type DBService ¶
DBService holds Sql and Xorm db base application extends DBService.
func NewDBService ¶
NewDBService creates DBService instance.
type LinkSql ¶
type LinkSql struct { *Sql // contains filtered or unexported fields }
Link program.
func NewLinkSql ¶
func (*LinkSql) BuildQuery ¶
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 (*Query) GetQuerySql ¶
type Sql ¶
type Sql struct { DB *sql.DB Host string Schema string Dialect string // defautl to mysql. ShowSql bool }
Sql wrap sqlDB and provide many functions.
func (Sql) AlterAddColumn ¶
alter table, add column
func (Sql) AlterAddPrimaryKey ¶
alter table add primary key to specific column
func (Sql) AlterAddPrimaryKeyToIDColumn ¶
alter table add primay key to ID column
func (Sql) AlterColumnCharDefault ¶
AlterColumnCharDefault
func (Sql) AlterColumnDataType ¶
alter table, redifine column data type
func (Sql) AlterColumnDefault ¶
func (Sql) AlterColumnNumDefault ¶
func (Sql) AlterColumnToDecimal ¶
alter table column to decimal
func (Sql) AlterDbCharDefault ¶
func (Sql) AlterDbColumnDefault ¶
set varchar char to ” set int bigint to 0
func (Sql) AlterDbNumDefault ¶
func (Sql) AlterDbToDecimal ¶
alter db all double column to decimal
func (Sql) AlterDropColumn ¶
alter table, drop column
func (Sql) AlterDropPrimaryKey ¶
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 ¶
alter table, rename column name
func (Sql) AlterRenameTable ¶
alter table, rename
func (Sql) AlterTableAddUniqueCloumn ¶
add unique constraint to column.
func (Sql) AlterTableAddUniqueWithName ¶
add unique constraint to columns.
func (Sql) AlterTableCharDefault ¶
func (Sql) AlterTableColumnDefault ¶
func (Sql) AlterTableDropUnique ¶
drop unique constraint need provide the constraint name.
func (Sql) AlterTableNumDefault ¶
func (Sql) AlterTableToDecimal ¶
alter table all double column to decimal
func (Sql) BuildColumnsWhere ¶
return where ColumnA = ? and CloumnB = ?
func (Sql) BuildSelectColumns ¶
Join columns , return "ColumnA, ColumnB"
func (Sql) CheckErrorWithSucceedMsg ¶
func (Sql) ClearTables ¶
ClearTables clears tables rows one by one
func (Sql) ColumnExec ¶
ColumnExec format include 2 string place holder
func (Sql) CountModelRows ¶
CountModelRows
func (Sql) CountTableColumns ¶
CountTableColumns returns table rows number.
func (Sql) CountTableRows ¶
CountTableRows returns table rows num.
func (Sql) CreateDatabase ¶
CreateDatabase create db TODO only work for mysql
func (Sql) DbTablesExec ¶
DbTablesExec loop all tables in db, format include 1 string place holder.
func (Sql) DisableTableRowColumn ¶
func (Sql) DropModelsTable ¶
DropModelsTable
func (Sql) EnableTableRowColumn ¶
Column value should be 0 or 1
func (Sql) Exec ¶
Exec override sql.DB.Exec(), add some logs, print sql and args, when occur error print it.
func (Sql) ExecForHtml ¶
func (Sql) GenTableCreateSql ¶
Generate create table sql form database table. used for export exist tables struct.
func (Sql) GetColumnDataType ¶
GetColumnDataType return column datatype, varchar, int etc.
func (Sql) GetColumnDefault ¶
GetColumnDefault returns table column define
func (Sql) GetColumnType ¶
GetColumnType return column type. varchar(60), decimal(18,2), etc.
func (Sql) GetDbTableColumns ¶
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 ¶
get one Table meta. used for process one table.
func (Sql) GetMetaTables ¶
get all table meta from db. schema equal database. used for loop all tables.
func (Sql) GetQueryColumns ¶
GetQueryColumns returns columns name in string array.
func (Sql) GetQueryRows ¶
GetQueryRows returns query rows count
func (Sql) GetSchemaName ¶
GetSchemaName return schema name store in Sql.
func (Sql) GetTableColumns ¶
GetTableColumns returns table column names
func (Sql) GetTableName ¶
GetTableName returns tablename
func (Sql) GetTableRowsJSONData ¶
GetTableRowsJSONData gets table rows JSON data
func (Sql) GetTableRowsMap ¶
GetTableRowsMap
func (Sql) InitTableRow ¶
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 ¶
Create a new row with id Table must has ID column
func (Sql) IsColumnNullable ¶
IsColumnNullable returns ture or false
func (Sql) IsColumnPrimary ¶
IsColumnPrimary returns true or false
func (Sql) IsDbExistTable ¶
IsDbExistTable check db tabke exists.
func (Sql) IsDbTableExistColumn ¶
IsDbTableExistColumn check db table column exists.
func (Sql) IsExistColumn ¶
IsExistColumn checks table column exists.
func (Sql) IsExistTable ¶
IsExistTable checks table exists.
func (Sql) IsHasDatabase ¶
IsHasDatabase check db exists TODO only work for mysql
func (Sql) IsModelHasRows ¶
IsModelHasRows
func (Sql) IsModelQueryHasRows ¶
IsModelQueryHasRows
func (Sql) IsQueryHasRows ¶
IsQueryHasRows returns query rows exists. if error, return false
func (Sql) IsTableHasColumn ¶
IsTableHasColumn equals to IsExistColumn
func (Sql) IsTableHasID ¶
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 ¶
IsTableQueryHasRows checks table query has rows
func (Sql) IsValidTableName ¶
func (Sql) ModelQuery ¶
ModelQuery
func (Sql) PrintDBTables ¶
PrintDBTables TODO only work for mysql
func (Sql) PrintDBTablesDetail ¶
PrintDBTablesDetail TODO only work for mysql
func (*Sql) PrintModelTableFriendly ¶
func (s *Sql) PrintModelTableFriendly(model interface{})
PrintModelTableFriendly
func (*Sql) PrintModelTableQuery ¶
PrintModelTableQuery
func (*Sql) PrintModelTableQueryVertical ¶
PrintModelTableQueryVertical
func (*Sql) PrintModelTableVertical ¶
func (s *Sql) PrintModelTableVertical(model interface{})
PrintModelTableVertical
func (*Sql) PrintQuery ¶
PrintQuery print query.
func (Sql) PrintQueryData ¶
func (*Sql) PrintQueryFriendly ¶
PrintQueryFriendly prints query friendly.
func (*Sql) PrintQueryInJSONFormat ¶
PrintQueryInJSONFormat prints query in JSON format.
func (*Sql) PrintQueryVertical ¶
PrintQueryVertical prints query vertical.
func (Sql) PrintTableColumns ¶
PrintTableColumns TODO only work for mysql
func (Sql) PrintTableColumnsDetail ¶
PrintTableColumnsDetail TODO only work for mysql
func (*Sql) PrintTableFriendly ¶
PrintTableFriendly print table friendly.
func (*Sql) PrintTableInJSONFormat ¶
PrintTableInJSONFormat prints table in JSON format.
func (*Sql) PrintTableQuery ¶
PrintTableQuery print table query.
func (*Sql) PrintTableQueryVertical ¶
PrintTableQueryVertical print table query vertical.
func (*Sql) PrintTableVertical ¶
PrintTableVertical prints table vertical
func (Sql) QueryColumnForArray ¶
QueryColumnForArray only one column in sql, mulity rows wrap to array
func (Sql) QueryForArray ¶
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 ¶
result [][]string include header
func (Sql) QueryForArrayWithoutHeader ¶
result [][]string not include header
func (Sql) QueryForBool ¶
QueryForBool returns bool result.
func (Sql) QueryForData ¶
QueryForJsonData
func (Sql) QueryForDataArray ¶
QueryForArrayData
func (Sql) QueryForFloat ¶
func (Sql) QueryForFloatNoError ¶
func (Sql) QueryForHtml ¶
QueryForHtml
func (Sql) QueryForInt ¶
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 ¶
QueryForIntNoError returns int result.
func (Sql) QueryForJSONData ¶
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{}) (rowMaps []map[string]interface{}, columns []string, err error)
QueryForMaps query for maps rowMaps 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 ¶
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 ¶
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) 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) RemoveRows ¶
Remove rows by conditions
func (Sql) RemoveTableRow ¶
RemoveTableRow removes table row with id.
func (Sql) RemoveWhereRows ¶
Remove rows by query
func (*Sql) SetShowSql ¶
func (Sql) StatAvgColumn ¶
func (Sql) StatMaxColumn ¶
func (Sql) StatMinColumn ¶
func (Sql) StatSumColumn ¶
SumNoError(stat_sum_org, income, BuFlag = ?, 'jijian')
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.
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
type Table ¶
Table defines Table
func (Table) CountColumns ¶
CountColumns return table column numbers.
func (Table) GetColumns ¶
GetColumns returns table column names.
func (Table) GetRowsJSONData ¶
GetRowsJSONData returns table rows JSON data.
Source Files ¶
- common.go
- db.go
- doc.go
- error.go
- link_sql.go
- logger.go
- model_meta.go
- model_print.go
- model_sql.go
- sql.go
- sql_alter.go
- sql_data.go
- sql_db.go
- sql_db_print.go
- sql_excel.go
- sql_export_csv.go
- sql_html.go
- sql_init.go
- sql_inspect.go
- sql_json.go
- sql_logger.go
- sql_meta.go
- sql_overide.go
- sql_print.go
- sql_query_array.go
- sql_query_map.go
- sql_remove.go
- sql_stat.go
- sql_table.go
- sql_type_query.go
- sql_type_table.go
- sql_update.go
- sql_util.go
- sql_xml.go
- util.go
- util_print.go
- util_str.go
- xorm.go
- xorm_inspect.go
Directories ¶
Path | Synopsis |
---|---|
wrap mysql driver.
|
wrap mysql driver. |
implement for SimpleTable
|
implement for SimpleTable |