12345678910111213141516171819202122232425262728293031323334353637 |
- package main
- import (
- "fmt"
- "gorm.io/driver/clickhouse"
- "gorm.io/gorm"
- "log"
- "net/url"
- "testing"
- )
- func TestUpdateCk(T *testing.T) {
- username := "jytop"
- password := "pwdTopJy123"
- host := "192.168.3.207:19000"
- encodedPassword := url.QueryEscape(password)
- dn := fmt.Sprintf("clickhouse://%s:%s@%s/information?dial_timeout=10s&read_timeout=20s", username, encodedPassword, host)
- db, err := gorm.Open(clickhouse.Open(dn), &gorm.Config{})
- if err != nil {
- log.Fatal("链接数据库失败")
- } else {
- log.Println("数据库连接成功", db.Name())
- }
- exist := EntMapCode{}
- where := EntMapCode{AName: "北京森嘉家具发展公司", BName: "北京森嘉义东家具有限公司"}
- db.Where(&where).First(&exist)
- if exist.CreateTime > 0 {
- //存在数据,需要更新
- update := EntMapCode{
- InvestRatio: "0.3",
- InvestPrice: "30",
- }
- db.Model(&exist).Where(&where).Updates(&update)
- }
- }
|