lunny/fix_fmt_lint (#53)

This commit is contained in:
Lunny Xiao 2019-07-15 13:42:17 +00:00 committed by Gitea
parent 817c743b93
commit 5d3ffb50de
12 changed files with 48 additions and 36 deletions

View File

@ -26,6 +26,7 @@ pipeline:
- go get -u github.com/go-xorm/sqlfiddle - go get -u github.com/go-xorm/sqlfiddle
- go get -u github.com/go-sql-driver/mysql - go get -u github.com/go-sql-driver/mysql
- go get -u github.com/mattn/go-sqlite3 - 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" - go test -v -race -coverprofile=coverage.txt -covermode=atomic -dbConn="root:@tcp(mysql:3306)/core_test?charset=utf8mb4"
when: when:
event: [ push, tag, pull_request ] event: [ push, tag, pull_request ]

View File

@ -1,6 +1,8 @@
Core is a lightweight wrapper of sql.DB. Core is a lightweight wrapper of sql.DB.
[![Build Status](https://drone.gitea.com/api/badges/xorm/core/status.svg)](https://drone.gitea.com/xorm/core) [![Build Status](https://drone.gitea.com/api/badges/xorm/core/status.svg)](https://drone.gitea.com/xorm/core)
[![](http://gocover.io/_badge/xorm.io/core)](http://gocover.io/xorm.io/core)
[![Go Report Card](https://goreportcard.com/badge/code.gitea.io/gitea)](https://goreportcard.com/report/xorm.io/core)
# Open # Open
```Go ```Go

2
db.go
View File

@ -15,6 +15,7 @@ import (
) )
var ( var (
// DefaultCacheSize sets the default cache size
DefaultCacheSize = 200 DefaultCacheSize = 200
) )
@ -198,6 +199,7 @@ var (
re = regexp.MustCompile(`[?](\w+)`) re = regexp.MustCompile(`[?](\w+)`)
) )
// ExecMapContext exec map with context.Context
// insert into (name) values (?) // insert into (name) values (?)
// insert into (name) values (?name) // insert into (name) values (?name)
func (db *DB) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error) { func (db *DB) ExecMapContext(ctx context.Context, query string, mp interface{}) (sql.Result, error) {

View File

@ -311,7 +311,7 @@ func RegisterDialect(dbName DbType, dialectFunc func() Dialect) {
dialects[strings.ToLower(string(dbName))] = dialectFunc // !nashtsai! allow override 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 { func QueryDialect(dbName DbType) Dialect {
if d, ok := dialects[strings.ToLower(string(dbName))]; ok { if d, ok := dialects[strings.ToLower(string(dbName))]; ok {
return d() return d()

View File

@ -7,6 +7,8 @@ package core
import "errors" import "errors"
var ( 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") ErrNoStructPointer = errors.New("mp should be a struct's pointer")
) )

View File

@ -4,8 +4,10 @@
package core package core
// LogLevel defines a log level
type LogLevel int type LogLevel int
// enumerate all LogLevels
const ( const (
// !nashtsai! following level also match syslog.Priority value // !nashtsai! following level also match syslog.Priority value
LOG_DEBUG LogLevel = iota LOG_DEBUG LogLevel = iota
@ -16,7 +18,7 @@ const (
LOG_UNKNOWN LOG_UNKNOWN
) )
// logger interface // ILogger is a logger interface
type ILogger interface { type ILogger interface {
Debug(v ...interface{}) Debug(v ...interface{})
Debugf(format string, v ...interface{}) Debugf(format string, v ...interface{})

View File

@ -9,12 +9,13 @@ import (
"strings" "strings"
) )
// enumerate all index types
const ( const (
IndexType = iota + 1 IndexType = iota + 1
UniqueType UniqueType
) )
// database index // Index represents a database index
type Index struct { type Index struct {
IsRegular bool IsRegular bool
Name string Name string
@ -35,7 +36,7 @@ func (index *Index) XName(tableName string) string {
return index.Name return index.Name
} }
// add columns which will be composite index // AddColumn add columns which will be composite index
func (index *Index) AddColumn(cols ...string) { func (index *Index) AddColumn(cols ...string) {
for _, col := range cols { for _, col := range cols {
index.Cols = append(index.Cols, col) index.Cols = append(index.Cols, col)
@ -65,7 +66,7 @@ func (index *Index) Equal(dst *Index) bool {
return true return true
} }
// new an index // NewIndex new an index object
func NewIndex(name string, indexType int) *Index { func NewIndex(name string, indexType int) *Index {
return &Index{true, name, indexType, make([]string, 0)} return &Index{true, name, indexType, make([]string, 0)}
} }

View File

@ -9,7 +9,7 @@ import (
"sync" "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 { type IMapper interface {
Obj2Table(string) string Obj2Table(string) string
Table2Obj(string) string Table2Obj(string) string
@ -184,7 +184,7 @@ func (mapper GonicMapper) Table2Obj(name string) string {
return string(newstr) 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{ var LintGonicMapper = GonicMapper{
"API": true, "API": true,
"ASCII": true, "ASCII": true,
@ -221,7 +221,7 @@ var LintGonicMapper = GonicMapper{
"XSS": true, "XSS": true,
} }
// provide prefix table name support // PrefixMapper provides prefix table name support
type PrefixMapper struct { type PrefixMapper struct {
Mapper IMapper Mapper IMapper
Prefix string Prefix string
@ -239,7 +239,7 @@ func NewPrefixMapper(mapper IMapper, prefix string) PrefixMapper {
return PrefixMapper{mapper, prefix} return PrefixMapper{mapper, prefix}
} }
// provide suffix table name support // SuffixMapper provides suffix table name support
type SuffixMapper struct { type SuffixMapper struct {
Mapper IMapper Mapper IMapper
Suffix string Suffix string

View File

@ -170,7 +170,7 @@ func (rs *Rows) ScanMap(dest interface{}) error {
newDest := make([]interface{}, len(cols)) newDest := make([]interface{}, len(cols))
vvv := vv.Elem() vvv := vv.Elem()
for i, _ := range cols { for i := range cols {
newDest[i] = rs.db.reflectNew(vvv.Type().Elem()).Interface() newDest[i] = rs.db.reflectNew(vvv.Type().Elem()).Interface()
} }

View File

@ -11,6 +11,7 @@ import (
"reflect" "reflect"
) )
// Stmt reprents a stmt objects
type Stmt struct { type Stmt struct {
*sql.Stmt *sql.Stmt
db *DB db *DB

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
) )
// database table // Table represents a database table
type Table struct { type Table struct {
Name string Name string
Type reflect.Type Type reflect.Type
@ -41,6 +41,7 @@ func NewEmptyTable() *Table {
return NewTable("", nil) return NewTable("", nil)
} }
// NewTable creates a new Table object
func NewTable(name string, t reflect.Type) *Table { func NewTable(name string, t reflect.Type) *Table {
return &Table{Name: name, Type: t, return &Table{Name: name, Type: t,
columnsSeq: make([]string, 0), columnsSeq: make([]string, 0),
@ -87,7 +88,7 @@ func (table *Table) GetColumnIdx(name string, idx int) *Column {
return nil return nil
} }
// if has primary key, return column // PKColumns reprents all primary key columns
func (table *Table) PKColumns() []*Column { func (table *Table) PKColumns() []*Column {
columns := make([]*Column, len(table.PrimaryKeys)) columns := make([]*Column, len(table.PrimaryKeys))
for i, name := range table.PrimaryKeys { for i, name := range table.PrimaryKeys {
@ -117,7 +118,7 @@ func (table *Table) DeletedColumn() *Column {
return table.GetColumn(table.Deleted) return table.GetColumn(table.Deleted)
} }
// add a column to table // AddColumn adds a column to table
func (table *Table) AddColumn(col *Column) { func (table *Table) AddColumn(col *Column) {
table.columnsSeq = append(table.columnsSeq, col.Name) table.columnsSeq = append(table.columnsSeq, col.Name)
table.columns = append(table.columns, col) 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) { func (table *Table) AddIndex(index *Index) {
table.Indexes[index.Name] = index table.Indexes[index.Name] = index
} }

42
type.go
View File

@ -87,16 +87,16 @@ var (
UniqueIdentifier = "UNIQUEIDENTIFIER" UniqueIdentifier = "UNIQUEIDENTIFIER"
SysName = "SYSNAME" SysName = "SYSNAME"
Date = "DATE" Date = "DATE"
DateTime = "DATETIME" DateTime = "DATETIME"
SmallDateTime = "SMALLDATETIME" SmallDateTime = "SMALLDATETIME"
Time = "TIME" Time = "TIME"
TimeStamp = "TIMESTAMP" TimeStamp = "TIMESTAMP"
TimeStampz = "TIMESTAMPZ" TimeStampz = "TIMESTAMPZ"
Decimal = "DECIMAL" Decimal = "DECIMAL"
Numeric = "NUMERIC" Numeric = "NUMERIC"
Money = "MONEY" Money = "MONEY"
SmallMoney = "SMALLMONEY" SmallMoney = "SMALLMONEY"
Real = "REAL" Real = "REAL"
@ -147,19 +147,19 @@ var (
Clob: TEXT_TYPE, Clob: TEXT_TYPE,
SysName: TEXT_TYPE, SysName: TEXT_TYPE,
Date: TIME_TYPE, Date: TIME_TYPE,
DateTime: TIME_TYPE, DateTime: TIME_TYPE,
Time: TIME_TYPE, Time: TIME_TYPE,
TimeStamp: TIME_TYPE, TimeStamp: TIME_TYPE,
TimeStampz: TIME_TYPE, TimeStampz: TIME_TYPE,
SmallDateTime: TIME_TYPE, SmallDateTime: TIME_TYPE,
Decimal: NUMERIC_TYPE, Decimal: NUMERIC_TYPE,
Numeric: NUMERIC_TYPE, Numeric: NUMERIC_TYPE,
Real: NUMERIC_TYPE, Real: NUMERIC_TYPE,
Float: NUMERIC_TYPE, Float: NUMERIC_TYPE,
Double: NUMERIC_TYPE, Double: NUMERIC_TYPE,
Money: NUMERIC_TYPE, Money: NUMERIC_TYPE,
SmallMoney: NUMERIC_TYPE, SmallMoney: NUMERIC_TYPE,
Binary: BLOB_TYPE, Binary: BLOB_TYPE,