sqlbase

package module
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

sqlbase

对gorm得简单封装,比较简单,自娱自乐

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = &gorm.Config{
	Logger: logger.New(log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{
		SlowThreshold: 100 * time.Millisecond,
		LogLevel:      logger.Error,
		Colorful:      true,
	}),
}

Functions

This section is empty.

Types

type Query added in v0.0.3

type Query struct {
	SortBy string
	Order  string
	Offset int
	Limit  int
}

func ConvertParams2DbQuery added in v0.0.3

func ConvertParams2DbQuery(initQuery *gorm.DB, params map[string]string) (*gorm.DB, Query)

转化请求的参数变成查询 把判断操作都直接放入到查询中 把 limit offset order 这些操作提取出来

type Storage

type Storage struct {
	DB *gorm.DB
}

func NewStorage

func NewStorage(engine string, port int, dbName string,
	user string, host string, passWd string, config *gorm.Config) (*Storage, error)

func (*Storage) BatchInsert added in v0.0.5

func (p *Storage) BatchInsert(baseSql string, valueFmt string, batchSize int, values [][]interface{}) error

func (*Storage) Close

func (p *Storage) Close()

func (*Storage) Delete

func (p *Storage) Delete(dbType interface{}, params map[string]string) (rowsAffected int64, err error)

func (*Storage) GetLastID added in v0.0.5

func (p *Storage) GetLastID(table string, primaryName string) (uint, error)

GetLastID: get table last primary id by table and primaryName

func (*Storage) RawScan added in v0.0.4

func (p *Storage) RawScan(baseSql string, conditionAndLimitPart string, scan func(rows *sql.Rows) error, values ...interface{}) error

RawScan this method can execute raw sql and use the scan function to scan rows this can package many are easy to overlook operations, like close. baseSql: the main sql body, provide query logic. conditionAndLimitPart: the sql condition body and limit part. scan: this revoke function to scan result rows. values: the values to replace sql placeholders

func (*Storage) SaveOrCreate

func (p *Storage) SaveOrCreate(params map[string]string, data interface{}) error

func (*Storage) Search

func (p *Storage) Search(dbType interface{}, params map[string]string, needCount bool, preLoads []string, data interface{}) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL