lunny/fix_fmt_lint (#53)
This commit is contained in:
parent
817c743b93
commit
5d3ffb50de
|
@ -26,6 +26,7 @@ pipeline:
|
|||
- go get -u github.com/go-xorm/sqlfiddle
|
||||
- go get -u github.com/go-sql-driver/mysql
|
||||
- go get -u github.com/mattn/go-sqlite3
|
||||
- go vet
|
||||
- go test -v -race -coverprofile=coverage.txt -covermode=atomic -dbConn="root:@tcp(mysql:3306)/core_test?charset=utf8mb4"
|
||||
when:
|
||||
event: [ push, tag, pull_request ]
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
Core is a lightweight wrapper of sql.DB.
|
||||
|
||||
[](https://drone.gitea.com/xorm/core)
|
||||
[](http://gocover.io/xorm.io/core)
|
||||
[](https://goreportcard.com/report/xorm.io/core)
|
||||
|
||||
# Open
|
||||
```Go
|
||||
|
|
2
db.go
2
db.go
|
@ -15,6 +15,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// DefaultCacheSize sets the default cache size
|
||||
DefaultCacheSize = 200
|
||||
)
|
||||
|
||||
|
@ -198,6 +199,7 @@ var (
|
|||
re = regexp.MustCompile(`[?](\w+)`)
|
||||
)
|
||||
|
||||
// ExecMapContext exec map with context.Context
|
||||
// insert into (name) values (?)
|
||||
// insert into (name) values (?name)
|
||||
func (db *DB) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error) {
|
||||
|
|
|
@ -311,7 +311,7 @@ func RegisterDialect(dbName DbType, dialectFunc func() Dialect) {
|
|||
dialects[strings.ToLower(string(dbName))] = dialectFunc // !nashtsai! allow override dialect
|
||||
}
|
||||
|
||||
// QueryDialect query if registed database dialect
|
||||
// QueryDialect query if registered database dialect
|
||||
func QueryDialect(dbName DbType) Dialect {
|
||||
if d, ok := dialects[strings.ToLower(string(dbName))]; ok {
|
||||
return d()
|
||||
|
|
4
error.go
4
error.go
|
@ -7,6 +7,8 @@ package core
|
|||
import "errors"
|
||||
|
||||
var (
|
||||
ErrNoMapPointer = errors.New("mp should be a map's pointer")
|
||||
// ErrNoMapPointer represents error when no map pointer
|
||||
ErrNoMapPointer = errors.New("mp should be a map's pointer")
|
||||
// ErrNoStructPointer represents error when no struct pointer
|
||||
ErrNoStructPointer = errors.New("mp should be a struct's pointer")
|
||||
)
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
package core
|
||||
|
||||
// LogLevel defines a log level
|
||||
type LogLevel int
|
||||
|
||||
// enumerate all LogLevels
|
||||
const (
|
||||
// !nashtsai! following level also match syslog.Priority value
|
||||
LOG_DEBUG LogLevel = iota
|
||||
|
@ -16,7 +18,7 @@ const (
|
|||
LOG_UNKNOWN
|
||||
)
|
||||
|
||||
// logger interface
|
||||
// ILogger is a logger interface
|
||||
type ILogger interface {
|
||||
Debug(v ...interface{})
|
||||
Debugf(format string, v ...interface{})
|
||||
|
|
7
index.go
7
index.go
|
@ -9,12 +9,13 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// enumerate all index types
|
||||
const (
|
||||
IndexType = iota + 1
|
||||
UniqueType
|
||||
)
|
||||
|
||||
// database index
|
||||
// Index represents a database index
|
||||
type Index struct {
|
||||
IsRegular bool
|
||||
Name string
|
||||
|
@ -35,7 +36,7 @@ func (index *Index) XName(tableName string) string {
|
|||
return index.Name
|
||||
}
|
||||
|
||||
// add columns which will be composite index
|
||||
// AddColumn add columns which will be composite index
|
||||
func (index *Index) AddColumn(cols ...string) {
|
||||
for _, col := range cols {
|
||||
index.Cols = append(index.Cols, col)
|
||||
|
@ -65,7 +66,7 @@ func (index *Index) Equal(dst *Index) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// new an index
|
||||
// NewIndex new an index object
|
||||
func NewIndex(name string, indexType int) *Index {
|
||||
return &Index{true, name, indexType, make([]string, 0)}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
// name translation between struct, fields names and table, column names
|
||||
// IMapper represents a name convertation between struct's fields name and table's column name
|
||||
type IMapper interface {
|
||||
Obj2Table(string) string
|
||||
Table2Obj(string) string
|
||||
|
@ -184,7 +184,7 @@ func (mapper GonicMapper) Table2Obj(name string) string {
|
|||
return string(newstr)
|
||||
}
|
||||
|
||||
// A GonicMapper that contains a list of common initialisms taken from golang/lint
|
||||
// LintGonicMapper is A GonicMapper that contains a list of common initialisms taken from golang/lint
|
||||
var LintGonicMapper = GonicMapper{
|
||||
"API": true,
|
||||
"ASCII": true,
|
||||
|
@ -221,7 +221,7 @@ var LintGonicMapper = GonicMapper{
|
|||
"XSS": true,
|
||||
}
|
||||
|
||||
// provide prefix table name support
|
||||
// PrefixMapper provides prefix table name support
|
||||
type PrefixMapper struct {
|
||||
Mapper IMapper
|
||||
Prefix string
|
||||
|
@ -239,7 +239,7 @@ func NewPrefixMapper(mapper IMapper, prefix string) PrefixMapper {
|
|||
return PrefixMapper{mapper, prefix}
|
||||
}
|
||||
|
||||
// provide suffix table name support
|
||||
// SuffixMapper provides suffix table name support
|
||||
type SuffixMapper struct {
|
||||
Mapper IMapper
|
||||
Suffix string
|
||||
|
|
2
rows.go
2
rows.go
|
@ -170,7 +170,7 @@ func (rs *Rows) ScanMap(dest interface{}) error {
|
|||
newDest := make([]interface{}, len(cols))
|
||||
vvv := vv.Elem()
|
||||
|
||||
for i, _ := range cols {
|
||||
for i := range cols {
|
||||
newDest[i] = rs.db.reflectNew(vvv.Type().Elem()).Interface()
|
||||
}
|
||||
|
||||
|
|
1
stmt.go
1
stmt.go
|
@ -11,6 +11,7 @@ import (
|
|||
"reflect"
|
||||
)
|
||||
|
||||
// Stmt reprents a stmt objects
|
||||
type Stmt struct {
|
||||
*sql.Stmt
|
||||
db *DB
|
||||
|
|
9
table.go
9
table.go
|
@ -9,7 +9,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// database table
|
||||
// Table represents a database table
|
||||
type Table struct {
|
||||
Name string
|
||||
Type reflect.Type
|
||||
|
@ -41,6 +41,7 @@ func NewEmptyTable() *Table {
|
|||
return NewTable("", nil)
|
||||
}
|
||||
|
||||
// NewTable creates a new Table object
|
||||
func NewTable(name string, t reflect.Type) *Table {
|
||||
return &Table{Name: name, Type: t,
|
||||
columnsSeq: make([]string, 0),
|
||||
|
@ -87,7 +88,7 @@ func (table *Table) GetColumnIdx(name string, idx int) *Column {
|
|||
return nil
|
||||
}
|
||||
|
||||
// if has primary key, return column
|
||||
// PKColumns reprents all primary key columns
|
||||
func (table *Table) PKColumns() []*Column {
|
||||
columns := make([]*Column, len(table.PrimaryKeys))
|
||||
for i, name := range table.PrimaryKeys {
|
||||
|
@ -117,7 +118,7 @@ func (table *Table) DeletedColumn() *Column {
|
|||
return table.GetColumn(table.Deleted)
|
||||
}
|
||||
|
||||
// add a column to table
|
||||
// AddColumn adds a column to table
|
||||
func (table *Table) AddColumn(col *Column) {
|
||||
table.columnsSeq = append(table.columnsSeq, col.Name)
|
||||
table.columns = append(table.columns, col)
|
||||
|
@ -148,7 +149,7 @@ func (table *Table) AddColumn(col *Column) {
|
|||
}
|
||||
}
|
||||
|
||||
// add an index or an unique to table
|
||||
// AddIndex adds an index or an unique to table
|
||||
func (table *Table) AddIndex(index *Index) {
|
||||
table.Indexes[index.Name] = index
|
||||
}
|
||||
|
|
42
type.go
42
type.go
|
@ -87,16 +87,16 @@ var (
|
|||
UniqueIdentifier = "UNIQUEIDENTIFIER"
|
||||
SysName = "SYSNAME"
|
||||
|
||||
Date = "DATE"
|
||||
DateTime = "DATETIME"
|
||||
SmallDateTime = "SMALLDATETIME"
|
||||
Time = "TIME"
|
||||
TimeStamp = "TIMESTAMP"
|
||||
TimeStampz = "TIMESTAMPZ"
|
||||
Date = "DATE"
|
||||
DateTime = "DATETIME"
|
||||
SmallDateTime = "SMALLDATETIME"
|
||||
Time = "TIME"
|
||||
TimeStamp = "TIMESTAMP"
|
||||
TimeStampz = "TIMESTAMPZ"
|
||||
|
||||
Decimal = "DECIMAL"
|
||||
Numeric = "NUMERIC"
|
||||
Money = "MONEY"
|
||||
Decimal = "DECIMAL"
|
||||
Numeric = "NUMERIC"
|
||||
Money = "MONEY"
|
||||
SmallMoney = "SMALLMONEY"
|
||||
|
||||
Real = "REAL"
|
||||
|
@ -147,19 +147,19 @@ var (
|
|||
Clob: TEXT_TYPE,
|
||||
SysName: TEXT_TYPE,
|
||||
|
||||
Date: TIME_TYPE,
|
||||
DateTime: TIME_TYPE,
|
||||
Time: TIME_TYPE,
|
||||
TimeStamp: TIME_TYPE,
|
||||
TimeStampz: TIME_TYPE,
|
||||
SmallDateTime: TIME_TYPE,
|
||||
Date: TIME_TYPE,
|
||||
DateTime: TIME_TYPE,
|
||||
Time: TIME_TYPE,
|
||||
TimeStamp: TIME_TYPE,
|
||||
TimeStampz: TIME_TYPE,
|
||||
SmallDateTime: TIME_TYPE,
|
||||
|
||||
Decimal: NUMERIC_TYPE,
|
||||
Numeric: NUMERIC_TYPE,
|
||||
Real: NUMERIC_TYPE,
|
||||
Float: NUMERIC_TYPE,
|
||||
Double: NUMERIC_TYPE,
|
||||
Money: NUMERIC_TYPE,
|
||||
Decimal: NUMERIC_TYPE,
|
||||
Numeric: NUMERIC_TYPE,
|
||||
Real: NUMERIC_TYPE,
|
||||
Float: NUMERIC_TYPE,
|
||||
Double: NUMERIC_TYPE,
|
||||
Money: NUMERIC_TYPE,
|
||||
SmallMoney: NUMERIC_TYPE,
|
||||
|
||||
Binary: BLOB_TYPE,
|
||||
|
|
Loading…
Reference in New Issue