gorm快速使用

2021-09-11 20:57:55 字數 916 閱讀 3728

)//模型:為表中的字段,記得欄位名開頭大寫

type patient struct

//此例為postgresql

func main()

//不重新建立複數結尾的表,還是原來的表,可以利用原表中的結構,資料

db.singulartable(true)

//defer db.close()

// 建立

patient

db.create(&patient)

// 讀取

var patient patient

db.first(&patient , "name= ?", "huo4") // 查詢name為huo4的patient

db.where(&patient ).first(&patient)

// 更新 - 更新patient的name為huo3

db.model(&patient).where("patientid= ?", "abc").update("name", "huo3")

//update patient set name="huo3" where patientid="abc"

// 刪除 - 刪除patient

db.delete(patient{}, "patientid= ?", "abc")

//delete from patienti where patientid="abc"

}

GORM基本使用

目錄go get u github.com jinzhu gorm要連線資料庫首先要匯入驅動程式 gorm已經包裝了一些驅動 import github.com jinzhu gorm dialects mssql 資料庫連線 func main 2.postgresql db2,err gorm....

能夠快速使用的Gorm框架使用筆記

使用 見之前的部落格 gorm事務處理 nil 延時關閉資料庫連線 defer db.close gorm.open mysql root 123456 tcp 127.0.0.1 3306 mysql?charset utf8 詳解 在高併發實踐中,為了提高資料庫連線的使用率,避免重複建立資料庫連...

go語言gorm使用

var jsondata map string inte ce 全域性變數 存放配置檔案的map物件 func initjson configstr string bytes reg regexp.mustcompile configstr reg.replaceallstring configst...