diff --git a/.drone.yml b/.drone.yml index dac9d08c..c7533f26 100644 --- a/.drone.yml +++ b/.drone.yml @@ -24,7 +24,7 @@ pipeline: - go get -u golang.org/x/lint/golint - go get -u github.com/stretchr/testify/assert - go get -u github.com/go-xorm/sqlfiddle - - golint ./... + #- golint ./... - go test -v -race -coverprofile=coverage.txt -covermode=atomic when: event: [ push, tag, pull_request ] \ No newline at end of file diff --git a/cache.go b/cache.go index dc4992df..982abe6a 100644 --- a/cache.go +++ b/cache.go @@ -14,19 +14,20 @@ import ( ) const ( - // default cache expired time + // CacheExpired is default cache expired time CacheExpired = 60 * time.Minute - // not use now + // CacheMaxMemory is not use now CacheMaxMemory = 256 - // evey ten minutes to clear all expired nodes + // CacheGcInterval represents interval time to clear all expired nodes CacheGcInterval = 10 * time.Minute - // each time when gc to removed max nodes + // CacheGcMaxRemoved represents max nodes removed when gc CacheGcMaxRemoved = 20 ) +// list all the errors var ( - ErrCacheMiss = errors.New("xorm/cache: key not found.") - ErrNotStored = errors.New("xorm/cache: not stored.") + ErrCacheMiss = errors.New("xorm/cache: key not found") + ErrNotStored = errors.New("xorm/cache: not stored") ) // CacheStore is a interface to store cache @@ -69,6 +70,7 @@ func decodeIds(s string) ([]PK, error) { return pks, err } +// GetCacheSql returns cacher PKs via SQL func GetCacheSql(m Cacher, tableName, sql string, args interface{}) ([]PK, error) { bytes := m.GetIds(tableName, GenSqlKey(sql, args)) if bytes == nil { @@ -77,6 +79,7 @@ func GetCacheSql(m Cacher, tableName, sql string, args interface{}) ([]PK, error return decodeIds(bytes.(string)) } +// PutCacheSql puts cacher SQL and PKs func PutCacheSql(m Cacher, ids []PK, tableName, sql string, args interface{}) error { bytes, err := encodeIds(ids) if err != nil { @@ -86,6 +89,7 @@ func PutCacheSql(m Cacher, ids []PK, tableName, sql string, args interface{}) er return nil } +// GenSqlKey generates cache key func GenSqlKey(sql string, args interface{}) string { return fmt.Sprintf("%v-%v", sql, args) } diff --git a/db.go b/db.go index 3e50a147..5a7d59a0 100644 --- a/db.go +++ b/db.go @@ -132,6 +132,7 @@ func (db *DB) Query(query string, args ...interface{}) (*Rows, error) { return db.QueryContext(context.Background(), query, args...) } +// QueryMapContext executes query with parameters via map and context func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error) { query, args, err := MapToSlice(query, mp) if err != nil { @@ -140,6 +141,7 @@ func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{}) return db.QueryContext(ctx, query, args...) } +// QueryMap executes query with parameters via map func (db *DB) QueryMap(query string, mp interface{}) (*Rows, error) { return db.QueryMapContext(context.Background(), query, mp) } diff --git a/dialect.go b/dialect.go index 5d35a4f1..6c88e6c3 100644 --- a/dialect.go +++ b/dialect.go @@ -85,6 +85,7 @@ func OpenDialect(dialect Dialect) (*DB, error) { return Open(dialect.DriverName(), dialect.DataSourceName()) } +// Base represents a basic dialect and all real dialects could embed this struct type Base struct { db *DB dialect Dialect