db_handler

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayJoin

func ArrayJoin(arr []string, sep string) string

func StringArrayContains

func StringArrayContains(arr []string, item string) bool

func ToCamelString

func ToCamelString(s string) string

snake string to camel string xx_yy => XxYy

func ToSnakeString

func ToSnakeString(s string) string

camel string to snake string XxYy = > xx_yy

Types

type Condition

type Condition struct {
	Where  string        //  "user=? and status=?"
	Params []interface{} // [ 1,0]
	Desc   []string
	Asc    []string
	Limit  int
	Offset int
}

type DBHandler

type DBHandler struct {
	DB *xorm.Engine

	Redis *redis.Client
	// contains filtered or unexported fields
}

func New

func New(dbConf *DbConfig, redisConf *RedisConfig) (*DBHandler, error)

func (*DBHandler) Count

func (db *DBHandler) Count(name string, condition *Condition) (int64, error)

func (*DBHandler) Del

func (db *DBHandler) Del(bean interface{}, name string, id interface{}) error

delete by id

func (*DBHandler) Exec

func (db *DBHandler) Exec(sql string, params ...interface{}) error

func (*DBHandler) Flush

func (db *DBHandler) Flush() error

func (*DBHandler) Get

func (db *DBHandler) Get(bean interface{}, name string, id interface{}) (bool, error)

find by id

func (*DBHandler) GetOne

func (db *DBHandler) GetOne(bean interface{}, name string, field string, value interface{}, idName ...string) (bool, error)

func (*DBHandler) List

func (db *DBHandler) List(bean interface{}, name string, condition *Condition) error

func (*DBHandler) ListAndCount

func (db *DBHandler) ListAndCount(bean interface{}, name string, condition *Condition) (int64, error)

func (*DBHandler) MultiGet

func (db *DBHandler) MultiGet(bean interface{}, name string, idList []interface{}, columnNames ...string) error

multiGet by column (default is id)

func (*DBHandler) Query

func (db *DBHandler) Query(sql string, params ...interface{}) ([]map[string]interface{}, error)

func (*DBHandler) Save

func (db *DBHandler) Save(bean interface{}, name string, idName ...string) error

func (*DBHandler) Sum

func (db *DBHandler) Sum(bean interface{}, name string, columnName string, condition *Condition) (float64, error)

func (*DBHandler) SumInt

func (db *DBHandler) SumInt(bean interface{}, name string, columnName string, condition *Condition) (int64, error)

func (*DBHandler) Sums

func (db *DBHandler) Sums(bean interface{}, name string, condition *Condition, columnNames ...string) ([]float64, error)

func (*DBHandler) SumsInt

func (db *DBHandler) SumsInt(bean interface{}, name string, condition *Condition, columnNames ...string) ([]int64, error)

type DbConfig

type DbConfig struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	UserName string `json:"user_name"`
	Password string `json:"password"`
	DbName   string `json:"db_name"`
	Charset  string `json:"charset"`
	ShowLog  bool   `json:"show_log"`
}

type RedisConfig

type RedisConfig struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Password string `json:"password"`
	DB       int    `json:"db"`
	Expire   int64  `json:"expire"`
}

Jump to

Keyboard shortcuts

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