database

package
v0.0.0-...-d391ba0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 10 Imported by: 2

README

Mysql数据库

1、注册数据库参数

//参数为数据库标识、数据库名、DSN
database.Register("database", "test", "root:123456@tcp(localhost:3306)/test")

2、创建模型

//参数为库名.表名,方便多个数据库的情况自主选库
Goods := database.Model{"database.goods"}

3、查询

Goods.Where("1").Find()

更多查询示例见orm_test.go

4、执行测试

go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dbname

func Dbname(tag string) string

func Dsn

func Dsn(tag string) string

func Open

func Open(tag string) *sql.DB

func Register

func Register(tag string, dbname string, dsn string)

Types

type Model

type Model struct {
	Table string
}

func (Model) Columns

func (M Model) Columns(fields ...string) map[string]string

func (Model) Count

func (M Model) Count() int

func (Model) Delete

func (M Model) Delete() int64

func (Model) Exist

func (M Model) Exist(primary string) bool

func (Model) Field

func (M Model) Field(fields string) *Orm

func (Model) Find

func (M Model) Find() map[string]string

func (Model) Group

func (M Model) Group(fields ...string) *Orm

func (Model) Having

func (M Model) Having(field string, opr string, criteria int) *Orm

func (Model) Insert

func (M Model) Insert(data map[string]string) int64

func (Model) Limit

func (M Model) Limit(limit int) *Orm

func (Model) New

func (M Model) New() *Orm

func (Model) Order

func (M Model) Order(field string, sort string) *Orm

func (Model) Page

func (M Model) Page(page int) *Orm

func (Model) Relate

func (M Model) Relate(list *[]map[string]string, fields string)

func (Model) Select

func (M Model) Select() []map[string]string

func (Model) Sum

func (M Model) Sum(field string) int

func (Model) Update

func (M Model) Update(data map[string]string) int64

func (Model) Value

func (M Model) Value(field string) string

func (Model) Values

func (M Model) Values(field string) []string

func (Model) Where

func (M Model) Where(conds ...interface{}) *Orm

type Orm

type Orm struct {
	// contains filtered or unexported fields
}

func NewOrm

func NewOrm(tag ...string) *Orm

func (*Orm) Columns

func (O *Orm) Columns(fields ...string) map[string]string

func (*Orm) Count

func (O *Orm) Count() int

func (*Orm) Delete

func (O *Orm) Delete() int64

func (*Orm) Exist

func (O *Orm) Exist(primary string) bool

func (*Orm) Field

func (O *Orm) Field(fields string) *Orm

func (*Orm) Find

func (O *Orm) Find() map[string]string

func (*Orm) Group

func (O *Orm) Group(fields ...string) *Orm

func (*Orm) Having

func (O *Orm) Having(field string, opr string, criteria int) *Orm

func (*Orm) Init

func (O *Orm) Init(dbtag string, table string) *Orm

func (*Orm) Insert

func (O *Orm) Insert(data map[string]string) int64

func (*Orm) Limit

func (O *Orm) Limit(limit int) *Orm

func (*Orm) Order

func (O *Orm) Order(field string, sort string) *Orm

func (*Orm) Page

func (O *Orm) Page(page int) *Orm

func (*Orm) Relate

func (O *Orm) Relate(list *[]map[string]string, fields string)

func (*Orm) Select

func (O *Orm) Select() []map[string]string

func (*Orm) Sum

func (O *Orm) Sum(field string) int

func (*Orm) Update

func (O *Orm) Update(data map[string]string) int64

func (*Orm) Value

func (O *Orm) Value(field string) string

func (*Orm) Values

func (O *Orm) Values(field string) []string

func (*Orm) Where

func (O *Orm) Where(conds ...interface{}) *Orm

Jump to

Keyboard shortcuts

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