database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: LGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBTypeSQLite3 = "sqlite3"
	DBTypeMySQL   = "mysql" // TODO
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Init(dbname string, cfg *viper.Viper, logger *zap.Logger) error
	Close()
	InitTables(ctsqls, cisqls []string) error

	Count(table string, where []Where) (int, error)

	Insert(table string, feilds []Feild) (sql.Result, error)
	Replace(table string, feilds []Feild) (sql.Result, error) // insert or replace
	Delete(table string, where []Where) (sql.Result, error)
	Update(table string, toupdate []Feild, where []Where) (sql.Result, error)
	SelectRows(table string, where []Where, order *Order, paging *Paging, result interface{}) error
	SelectRowsOffset(table string, where []Where, order *Order, offset, limit uint64, result interface{}) error

	Begin() error
	Commit() error
	Rollback() error
}

Database interface for app database-operation

type Feild

type Feild struct {
	Name  string
	Value interface{}
}

Feild database feild

type Order

type Order struct {
	Type   string   // "asc" or "desc"
	Feilds []string // order by x
}

Order used to identify query order

func MakeOrder

func MakeOrder(ordertype string, feilds ...string) (*Order, error)

MakeOrder make a order object

func (*Order) GetOp

func (o *Order) GetOp() string

GetOp used in sql

type Paging

type Paging struct {
	CursorName  string // cursor column
	CursorValue uint64 // cursor column
	Limit       uint   // limit
}

func MakePaging

func MakePaging(colName string, colValue uint64, limit uint) *Paging

MakePaging make a paging object

type Where

type Where struct {
	Name  string
	Value interface{}
	Op    string // can be =、>、<、<> and any operator supported by sql-database
}

Where query feild

func (*Where) GetOp

func (w *Where) GetOp() string

GetOp get operator of current where clause, default =

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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