sqlbase

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: Apache-2.0 Imports: 6 Imported by: 1

README

sqlbase

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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) (*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)

func (*Storage) Update

func (p *Storage) Update(data interface{}) error

Jump to

Keyboard shortcuts

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