資料庫
使用gorm進行資料庫操作
TIP
資料庫操作參考gorm文擋
前置準備
安裝
sh
$ go get -u ghostbb.io/gb/contrib/drivers/mssql
sh
$ go get -u ghostbb.io/gb/contrib/drivers/mysql
sh
$ go get -u ghostbb.io/gb/contrib/drivers/pgsql
快速開始
配置
yaml
# config.yaml
database:
logger:
path: "./log/database"
level: "all"
stdout: false
default:
host: "localhost"
port: "1433"
user: "sa"
pass: "123456"
name: "gb"
type: "mssql" # mysql, mssql, pgsql...
maxIdle: 10
maxOpen: 100
slowThreshold: "2s"
使用
go
package main
import (
_ "ghostbb.io/gb/contrib/driver/mssql"
"ghostbb.io/gb"
)
func main() {
db := g.DB()
// ...操作
}