You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.9 KiB
83 lines
1.9 KiB
package main
|
|
|
|
/*
|
|
go get github.com/go-xorm/cmd/xorm
|
|
go get github.com/go-xorm/xorm
|
|
|
|
# 注意模板的路径问题,否则无法生成文件
|
|
cd C:\Users\Administrator\go\pkg\mod\github.com\go-xorm\cmd\xorm@v0.0.0-20190426080617-f87981e709a1
|
|
xorm reverse mysql base:dsideal4r5t6y7u@(10.10.6.200:22066)/base_db?charset=utf8 templates/goxorm E:\Work\dsSso\Model
|
|
|
|
文档不要看“看云”的,太老了,要看:
|
|
https://github.com/xormplus/xorm
|
|
*/
|
|
import (
|
|
"dsSso/Model"
|
|
"dsSso/Utils/DbUtil"
|
|
"fmt"
|
|
"github.com/oklog/ulid"
|
|
"github.com/rs/xid"
|
|
"math/rand"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestOrmInsert(t *testing.T) {
|
|
//1、测试插入
|
|
app := new(Model.TJoinApp)
|
|
|
|
ak := xid.New()
|
|
app.AppKey = ak.String()
|
|
|
|
t2 := time.Now().UTC()
|
|
entropy := rand.New(rand.NewSource(t2.UnixNano()))
|
|
sk := ulid.MustNew(ulid.Timestamp(t2), entropy)
|
|
app.AppSecret = strings.ToLower(sk.String())
|
|
|
|
app.RedirectUri = "http://www.baidu.com"
|
|
app.AppName = "黄海测试orm"
|
|
app.LastUpdatedTime = time.Now()
|
|
affected, err := DbUtil.Engine.Insert(app)
|
|
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
} else {
|
|
fmt.Println(affected)
|
|
}
|
|
}
|
|
|
|
func TestOrmUpdate(t *testing.T) {
|
|
app := Model.TJoinApp{AppName: "黄海没心"}
|
|
affected, err := DbUtil.Engine.Id(1).Cols("app_name").Update(&app)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
} else {
|
|
fmt.Println(affected)
|
|
}
|
|
}
|
|
|
|
func TestOrmSelectSingle(t *testing.T) {
|
|
var app Model.TJoinApp
|
|
has, err := DbUtil.Engine.Where("app_id = ?", 1).Get(&app)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
} else {
|
|
if has {
|
|
fmt.Println(app.AppName, app.AppId, app.AppKey, app.AppSecret)
|
|
} else {
|
|
fmt.Println("没有找到!")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOrmSelectMulti(t *testing.T) {
|
|
var apps []Model.TJoinApp
|
|
err := DbUtil.Engine.Where("redirect_uri = ?", "http://www.baidu.com").And("app_id > 2").Desc("app_id").Limit(10, 0).Find(&apps)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
} else {
|
|
fmt.Println(apps)
|
|
}
|
|
}
|