db_repo

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 0 Imported by: 0

README

使用示例

user_demo 为例:

// 查询:多条 + 分页 
page := 2
num := 2
offset := (page - 1) * num

user, err = user_demo_repo.NewQueryBuilder().
    WhereIdNotIn([]int32{1, 2, 3}).
    WhereUserName(db_repo.EqualPredicate, "tom").
    Limit(num).
    Offset(offset).
    QueryAll(u.db.GetDbR().WithContext(ctx.RequestContext()))

// 查询:总数
count, err := user_demo_repo.NewQueryBuilder().
    WhereIdNotIn([]int32{1, 2, 3}).
    WhereUserName(db_repo.EqualPredicate, "tom").
    Count(u.db.GetDbR().WithContext(ctx.RequestContext()))

// 查询:单条
user, err = user_demo_repo.NewQueryBuilder().
    WhereUserName(db_repo.EqualPredicate, "tom").
    QueryOne(u.db.GetDbR().WithContext(ctx.RequestContext()))

// 创建
model := user_demo_repo.NewModel()
model.UserName = user.UserName
model.NickName = user.NickName
model.Mobile = user.Mobile

id, err = model.Create(u.db.GetDbW().WithContext(ctx.RequestContext()))

// 编辑
model := user_demo_repo.NewModel()
model.Id = id

data := map[string]interface{}{
    "nick_name": nickname,
}

err = model.Updates(u.db.GetDbW().WithContext(ctx.RequestContext()), data)

// 删除
model := user_demo_repo.NewModel()
model.Id = id
err = model.Delete(u.db.GetDbW().WithContext(ctx.RequestContext()))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EqualPredicate              = Predicate("=")
	NotEqualPredicate           = Predicate("<>")
	GreaterThanPredicate        = Predicate(">")
	GreaterThanOrEqualPredicate = Predicate(">=")
	SmallerThanPredicate        = Predicate("<")
	SmallerThanOrEqualPredicate = Predicate("<=")
	LikePredicate               = Predicate("LIKE")
)

Functions

This section is empty.

Types

type Predicate

type Predicate string

Predicate is a string that acts as a condition in the where clause

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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