database

package
v0.0.0-...-5240e22 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 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(primary ...string) 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) Map

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

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) Result

func (M Model) Result() *Result

func (Model) Select

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

func (Model) Sum

func (M Model) Sum(field string) int

func (Model) Total

func (M Model) Total() int

func (Model) TotalPage

func (M Model) TotalPage() 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) And

func (O *Orm) And(conds ...interface{}) *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(primary ...string) 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) Map

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

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) Result

func (O *Orm) Result() *Result

func (*Orm) Select

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

func (*Orm) Sum

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

func (*Orm) Total

func (O *Orm) Total() int

func (*Orm) TotalPage

func (O *Orm) TotalPage() 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

type Result

type Result struct {
	Page  int
	Limit int
	// contains filtered or unexported fields
}

func (*Result) Columns

func (R *Result) Columns(fields ...string) map[string]string

返回指定列做key指定列做value的map

func (*Result) Empty

func (R *Result) Empty() bool

返回结果集是否为空

func (*Result) Fields

func (R *Result) Fields() map[string]string

返回结果集字段

func (*Result) List

func (R *Result) List() []map[string]string

返回查询结果切片

func (*Result) Map

func (R *Result) Map(fields ...string) map[string]map[string]string

返回指定列为key记录为值的map

func (*Result) MapList

func (R *Result) MapList(key string, value string) map[string][]string

返回指定列为key指定列为值的切片

func (*Result) Merge

func (R *Result) Merge(M *Result) []map[string]string

找到两个结果集的唯一交集key,合并结果集

func (*Result) Response

func (R *Result) Response() map[string]any

返回列表分页标准格式响应

func (*Result) Total

func (R *Result) Total() int

返回记录总条数

func (*Result) TotalPage

func (R *Result) TotalPage() int

返回记录总页数

func (*Result) Values

func (R *Result) Values(field string) []string

返回指定列切片

func (*Result) Walk

func (R *Result) Walk(callback func(v map[string]string) map[string]string)

walk函数遍历

func (Result) Zero

func (R Result) Zero() *Result

Jump to

Keyboard shortcuts

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