func (s *DB) Count(value interface{}) *DB {
	return s.NewScope(s.Value).count(value).db
}
Count get how many records for a model
package gorm
import (
	"database/sql"
	"errors"
	"fmt"
	"reflect"
	"strings"
	"time"
)
type DB struct {
	Value        interface{}
	Error        error
	RowsAffected int64
	db                SQLCommon
	blockGlobalUpdate bool
	logMode           int
	logger            logger
	search            *search
	values            map[string]interface{}
	parent        *DB
	callbacks     *Callback
	dialect       Dialect
	singularTable bool
}
func Open(dialect string, args ...interface{}) (db *DB, err error) {
	if len(args) == 0 {
		err = errors.New("invalid database source")
		return nil, err
	}
	var source string
	var dbSQL SQLCommon
	switch value := args[0].(type) {
	case string:
		var driver = dialect
		if len(args) == 1 {
			source = value
		} else if len(args) >= 2 {
			driver = value
			source = args[1].(string)
		}
		dbSQL, err = sql.Open(driver, source)
	case SQLCommon:
		dbSQL = value
	}
	db = &DB{
		db:        dbSQL,
		logger:    defaultLogger,
		values:    map[string]interface{}{},
		callbacks: DefaultCallback,
		dialect:   newDialect(dialect, dbSQL),
	}
	db.parent = db
	if err != nil {
		return
	}
	if d, ok := dbSQL.(*sql.DB); ok {
		if err = d.Ping(); err != nil {
			d.Close()
		}
	}
	return
}
func (s *DB) New() *DB {
	clone := s.clone()
	clone.search = nil
	clone.Value = nil
	return clone
}
type closer interface {
	Close() error
}
func (s *DB) Close() error {
	if db, ok := s.parent.db.(closer); ok {
		return db.Close()
	}
	return errors.New("can't close current db")
}
func (s *DB) DB() *sql.DB {
	db, _ := s.db.(*sql.DB)
	return db
}
func (s *DB) CommonDB() SQLCommon {
	return s.db
}
func (s *DB) Dialect() Dialect {
	return s.parent.dialect
}
func (s *DB) Callback() *Callback {
	s.parent.callbacks = s.parent.callbacks.clone()
	return s.parent.callbacks
}
func (s *DB) SetLogger(log logger) {
	s.logger = log
}
func (s *DB) LogMode(enable bool) *DB {
	if enable {
		s.logMode = 2
	} else {
		s.logMode = 1
	}
	return s
}
func (s *DB) BlockGlobalUpdate(enable bool) *DB {
	s.blockGlobalUpdate = enable
	return s
}
func (s *DB) HasBlockGlobalUpdate() bool {
	return s.blockGlobalUpdate
}
func (s *DB) SingularTable(enable bool) {
	modelStructsMap = newModelStructsMap()
	s.parent.singularTable = enable
}
func (s *DB) NewScope(value interface{}) *Scope {
	dbClone := s.clone()
	dbClone.Value = value
	return &Scope{db: dbClone, Search: dbClone.search.clone(), Value: value}
}
func (s *DB) QueryExpr() *expr {
	scope := s.NewScope(s.Value)
	scope.InstanceSet("skip_bindvar", true)
	scope.prepareQuerySQL()
	return Expr(scope.SQL, scope.SQLVars...)
}
func (s *DB) SubQuery() *expr {
	scope := s.NewScope(s.Value)
	scope.InstanceSet("skip_bindvar", true)
	scope.prepareQuerySQL()
	return Expr(fmt.Sprintf("(%v)", scope.SQL), scope.SQLVars...)
}
func (s *DB) Where(query interface{}, args ...interface{}) *DB {
	return s.clone().search.Where(query, args...).db
}
func (s *DB) Or(query interface{}, args ...interface{}) *DB {
	return s.clone().search.Or(query, args...).db
}
func (s *DB) Not(query interface{}, args ...interface{}) *DB {
	return s.clone().search.Not(query, args...).db
}
func (s *DB) Limit(limit interface{}) *DB {
	return s.clone().search.Limit(limit).db
}
func (s *DB) Offset(offset interface{}) *DB {
	return s.clone().search.Offset(offset).db
}
func (s *DB) Order(value interface{}, reorder ...bool) *DB {
	return s.clone().search.Order(value, reorder...).db
}
func (s *DB) Select(query interface{}, args ...interface{}) *DB {
	return s.clone().search.Select(query, args...).db
}
func (s *DB) Omit(columns ...string) *DB {
	return s.clone().search.Omit(columns...).db
}
func (s *DB) Group(query string) *DB {
	return s.clone().search.Group(query).db
}
func (s *DB) Having(query interface{}, values ...interface{}) *DB {
	return s.clone().search.Having(query, values...).db
}
func (s *DB) Joins(query string, args ...interface{}) *DB {
	return s.clone().search.Joins(query, args...).db
}
func (s *DB) Scopes(funcs ...func(*DB) *DB) *DB {
	for _, f := range funcs {
		s = f(s)
	}
	return s
}
func (s *DB) Unscoped() *DB {
	return s.clone().search.unscoped().db
}
func (s *DB) Attrs(attrs ...interface{}) *DB {
	return s.clone().search.Attrs(attrs...).db
}
func (s *DB) Assign(attrs ...interface{}) *DB {
	return s.clone().search.Assign(attrs...).db
}
func (s *DB) First(out interface{}, where ...interface{}) *DB {
	newScope := s.NewScope(out)
	newScope.Search.Limit(1)
	return newScope.Set("gorm:order_by_primary_key", "ASC").
		inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
}
func (s *DB) Take(out interface{}, where ...interface{}) *DB {
	newScope := s.NewScope(out)
	newScope.Search.Limit(1)
	return newScope.inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
}
func (s *DB) Last(out interface{}, where ...interface{}) *DB {
	newScope := s.NewScope(out)
	newScope.Search.Limit(1)
	return newScope.Set("gorm:order_by_primary_key", "DESC").
		inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
}
func (s *DB) Find(out interface{}, where ...interface{}) *DB {
	return s.NewScope(out).inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
}
func (s *DB) Scan(dest interface{}) *DB {
	return s.NewScope(s.Value).Set("gorm:query_destination", dest).callCallbacks(s.parent.callbacks.queries).db
}
func (s *DB) Row() *sql.Row {
	return s.NewScope(s.Value).row()
}
func (s *DB) Rows() (*sql.Rows, error) {
	return s.NewScope(s.Value).rows()
}
func (s *DB) ScanRows(rows *sql.Rows, result interface{}) error {
	var (
		scope        = s.NewScope(result)
		clone        = scope.db
		columns, err = rows.Columns()
	)
	if clone.AddError(err) == nil {
		scope.scan(rows, columns, scope.Fields())
	}
	return clone.Error
}
func (s *DB) Pluck(column string, value interface{}) *DB {
	return s.NewScope(s.Value).pluck(column, value).db
}