数据库操作
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.

51 lines
1.2 KiB

3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
  1. package dbquery
  2. import (
  3. "log"
  4. "testing"
  5. )
  6. func Test_Connet(t *testing.T) {
  7. //go func() {
  8. for i := 0; i < 1; i++ {
  9. dbhost := "localhost"
  10. dbname := "shop"
  11. dbusername := "tetele"
  12. dbpassword := "fly123456"
  13. dbport := "3306"
  14. table := "ttl_order_product"
  15. err := Connect(dbhost, dbusername, dbpassword, dbname, dbport)
  16. if err != nil {
  17. log.Println(err.Error())
  18. }
  19. //_,err = new(Query).Db(dbname).Table("ttl_user").Where("id > 0").Select()
  20. // _, err = new(Query).Db(dbname).Table("ttl_news").
  21. // Datas([]string{"title=?", "content=?"}).
  22. // Values([]interface{}{"aaaaaaaaa", "bbbbbb"}).Create()
  23. title := "op.id,op.sn,op.order_price"
  24. alias := "op"
  25. join := [][]string{}
  26. join = append(join, []string{"ttl_product as p", "op.product_id=p.id"})
  27. where := []string{}
  28. where_or := []string{}
  29. valueList := []interface{}{}
  30. orderby := "id desc"
  31. debug := true
  32. // count, row, err := GetRow(dbname, table, alias, title, join, where, where_or, valueList, orderby, debug)
  33. count, row, err := FetchRows(dbname, table, alias, title, join, where, where_or, valueList, orderby, "", 1, 10, debug)
  34. log.Println(count)
  35. log.Println(row)
  36. log.Println(err)
  37. if err != nil {
  38. log.Println(err.Error())
  39. }
  40. }
  41. //}()
  42. }