database

package
v0.0.0-...-be98215 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2016 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TIME_FORMATER = "2006-01-02 15:04:05"
)

Variables

View Source
var (
	TIME_PTR_TYPE = reflect.TypeOf(&time.Time{})
)

Functions

func GetPkValue

func GetPkValue(m Model) (string, interface{})

Types

type Database

type Database struct {
	Debug bool
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB) *Database

func (*Database) Close

func (d *Database) Close()

func (*Database) Del

func (d *Database) Del(m Model, field string, value interface{}) (affect int64, err error)

func (*Database) DelPk

func (d *Database) DelPk(m Model) (int64, error)

func (*Database) Get

func (d *Database) Get(m Model, field string, value interface{}) error

need value to reduce once reflect expense d.Get(&User{}, "openid", "123456")

func (*Database) GetCondition

func (d *Database) GetCondition(m Model, condition interface{}, value ...interface{}) ([]Model, error)

d.GetCondition(&User{}, "where level >10 and money <? limit ?, 10", 100, 5)

func (*Database) GetMultiIn

func (d *Database) GetMultiIn(m Model, field string, value ...interface{}) ([]Model, error)

mysql in usage ms := d.GetMultiIn(&User{}, "openid", "12", "34") ms[0].(*User) [return interface{} need type change]

func (*Database) GetMultiPkIn

func (d *Database) GetMultiPkIn(m Model, value ...interface{}) ([]Model, error)

func (*Database) GetPk

func (d *Database) GetPk(m Model) error

primary key get

func (*Database) Insert

func (d *Database) Insert(m Model) (last int64, err error)

func (*Database) Select

func (d *Database) Select(m Model, field string, condition interface{}, value ...interface{}) (ms []Model, err error)

func (*Database) Update

func (d *Database) Update(m Model, field string, value interface{}) (affect int64, err error)

func (*Database) UpdatePk

func (d *Database) UpdatePk(m Model) (int64, error)

type DeafultModel

type DeafultModel struct{}

if you don't want provide TableName, you can combine DeafultModel

func (*DeafultModel) TableName

func (m *DeafultModel) TableName() string

type Model

type Model interface {
	TableName() string
}

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
}

Jump to

Keyboard shortcuts

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