mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
增加webssh及数据库查询
This commit is contained in:
72
base/model/model_test.go
Normal file
72
base/model/model_test.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/controllers/vo"
|
||||
"mayfly-go/models"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
type AccountDetailVO struct {
|
||||
Id int64
|
||||
Username string
|
||||
}
|
||||
|
||||
func init() {
|
||||
orm.RegisterDriver("mysql", orm.DRMySQL)
|
||||
|
||||
orm.RegisterDataBase("default", "mysql", "root:111049@tcp(localhost:3306)/mayfly-go?charset=utf8")
|
||||
orm.Debug = true
|
||||
}
|
||||
|
||||
func TestGetList(t *testing.T) {
|
||||
query := QuerySetter(new(models.Account)).OrderBy("-Id")
|
||||
list := new([]AccountDetailVO)
|
||||
GetList(query, new([]models.Account), list)
|
||||
fmt.Println(list)
|
||||
}
|
||||
|
||||
func TestGetOne(t *testing.T) {
|
||||
model := new(models.Account)
|
||||
query := QuerySetter(model).Filter("Id", 2)
|
||||
adv := new(AccountDetailVO)
|
||||
GetOne(query, model, adv)
|
||||
fmt.Println(adv)
|
||||
}
|
||||
|
||||
func TestMap(t *testing.T) {
|
||||
//o := getOrm()
|
||||
//
|
||||
////v := new([]Account)
|
||||
//var maps []orm.Params
|
||||
//_, err := o.Raw("SELECT a.Id, a.Username, r.Id AS 'Role.Id', r.Name AS 'Role.Name' FROM " +
|
||||
// "t_account a JOIN t_role r ON a.id = r.account_id").Values(&maps)
|
||||
//fmt.Println(err)
|
||||
//////res := new([]Account)
|
||||
////model := &Account{}
|
||||
////o.QueryTable("t_account").Filter("id", 1).RelatedSel().One(model)
|
||||
////o.LoadRelated(model, "Role")
|
||||
res := new([]vo.AccountVO)
|
||||
sql := "SELECT a.Id, a.Username, r.Id AS 'Role.Id', r.Name AS 'Role.Name' FROM t_account a JOIN t_role r ON a.id = r.account_id"
|
||||
//limitSql := sql + " LIMIT 1, 3"
|
||||
//selectIndex := strings.Index(sql, "SELECT ") + 7
|
||||
//fromIndex := strings.Index(sql, " FROM")
|
||||
//selectCol := sql[selectIndex:fromIndex]
|
||||
//countSql := strings.Replace(sql, selectCol, "COUNT(*)", 1)
|
||||
//fmt.Println(limitSql)
|
||||
//fmt.Println(selectCol)
|
||||
//fmt.Println(countSql)
|
||||
page := GetPageBySql(sql, res, &PageParam{PageNum: 1, PageSize: 1})
|
||||
fmt.Println(page)
|
||||
//return res
|
||||
}
|
||||
|
||||
func TestCase2Camel(t *testing.T) {
|
||||
fmt.Println(utils.Case2Camel("create_time"))
|
||||
fmt.Println(strings.Title("username"))
|
||||
}
|
||||
Reference in New Issue
Block a user