mysql_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package mysql
  2. import (
  3. "log"
  4. "testing"
  5. //_ "github.com/ClickHouse/clickhouse-go/v2"
  6. )
  7. func TestMysqlSelect(t *testing.T) {
  8. m := &Mysql{
  9. Address: "192.168.3.217:4000",
  10. UserName: "root",
  11. PassWord: "=PDT49#80Z!RVv52_z",
  12. DBName: "jianyu",
  13. MaxOpenConns: 2, //用于设置最大打开的连接数,默认值为0表示不限制。
  14. MaxIdleConns: 2, //用于设置闲置的连接数。
  15. }
  16. m.Init()
  17. list := m.SelectBySql(`select * from entniche_info limit ?`, 1)
  18. log.Println("-----", list)
  19. }
  20. func TestClickHouseSelect(t *testing.T) {
  21. m := NewInit("clickhouse", "clickhouse://jytop:pwdTopJy123@192.168.3.207:19000/information?dial_timeout=2000ms&max_execution_time=60s", 1, 1)
  22. m.UpdateOrDeleteBySql(`ALTER TABLE jianyu.sub_recommend_list update area='123' where userid='5d6378301c298a5aac7b5402'`)
  23. return
  24. m.SelectByBath(1, func(l *[]map[string]interface{}) bool {
  25. log.Println(l)
  26. return true
  27. }, `select * from information where createtime>=1708673243 and createtime<1708673245`)
  28. //}, `select id from information limit ?`, 1)
  29. return
  30. list := m.SelectBySql(`select id from information limit ?`, 1)
  31. c := m.CountBySql(`select count(1) as c from information`)
  32. log.Println("-----", list, c)
  33. log.Println(m.InsertBatch("wcj.test", []string{"name"}, []interface{}{"456"}))
  34. }