package dbquery
|
|
|
|
import (
|
|
"log"
|
|
"testing"
|
|
)
|
|
|
|
func Test_Connet(t *testing.T) {
|
|
for i := 0; i < 1; i++ {
|
|
dbhost := "localhost"
|
|
dbname := "shop"
|
|
dbusername := "tetele"
|
|
dbpassword := "fly123456"
|
|
dbport := "3306"
|
|
table := "ttl_order_product"
|
|
err := Connect(dbhost, dbusername, dbpassword, dbname, dbport)
|
|
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
}
|
|
|
|
//_,err = new(Query).Db(dbname).Table("ttl_user").Where("id > 0").Select()
|
|
|
|
// _, err = new(Query).Db(dbname).Table("ttl_news").
|
|
// Datas([]string{"title=?", "content=?"}).
|
|
// Values([]interface{}{"aaaaaaaaa", "bbbbbb"}).Create()
|
|
|
|
title := "op.id,op.sn,op.order_price"
|
|
alias := "op"
|
|
join := [][]string{}
|
|
join = append(join, []string{"ttl_product as p", "op.product_id=p.id"})
|
|
where := []string{}
|
|
where_or := []string{}
|
|
valueList := []interface{}{}
|
|
orderby := "id desc"
|
|
debug := true
|
|
|
|
//count, row, err := GetRow(dbname, table, alias, title, join, where, where_or, valueList, orderby, debug)
|
|
count, row, err := FetchRows(dbname, table, alias, title, join, join, where, where_or, valueList, orderby, "", "", 1, 10, debug)
|
|
|
|
log.Println(count)
|
|
log.Println(row)
|
|
log.Println(err)
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
}
|
|
}
|
|
}
|
|
|
|
func Test_Query(t *testing.T) {
|
|
token := "67c121aa-6e1c-011f-ebb6-976d855fd777"
|
|
dbhost := "192.168.233.134"
|
|
dbname := "canyin"
|
|
dbusername := "bin"
|
|
dbpassword := "Bin123456"
|
|
dbport := "5432"
|
|
table := "ttl_user_token"
|
|
err := PgConnect(dbhost, dbusername, dbpassword, dbname, dbport)
|
|
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
}
|
|
|
|
title := "user.*,ut.expiretime"
|
|
alias := "ut"
|
|
join := [][]string{}
|
|
join = append(join, []string{"ttl_user as user", "ut.user_id= user.id"})
|
|
where := []string{
|
|
"ut.token=?",
|
|
}
|
|
where_or := []string{}
|
|
valueList := []interface{}{
|
|
token,
|
|
}
|
|
orderby := ""
|
|
debug := true
|
|
|
|
count, row, err := GetRow(dbname, table, alias, title, [][]string{}, join, where, where_or, valueList, orderby, "", "", debug)
|
|
//count, row, err := FetchRows(dbname, table, alias, title, join, join, where, where_or, valueList, orderby, "", "", 1, 10, debug)
|
|
|
|
log.Println(count)
|
|
log.Println(row)
|
|
log.Println(err)
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
}
|
|
}
|