Skip to content

Database

Use gorm for database operations

TIP

learn more gorm

Preparation

Install

sh
$ go get -u ghostbb.io/gb/contrib/driver/mssql
sh
$ go get -u ghostbb.io/gb/contrib/driver/mysql
sh
$ go get -u ghostbb.io/gb/contrib/driver/pgsql

Getting started

Configuration

yaml
# config.yaml
database:
  logger:
    path: "./log/database"
    level: "all"
    stdout: false
  default:
    host: "localhost"
    port: "1433"
    user: "sa"
    pass: "123456"
    name: "hr"
    type: "mssql" # mysql, mssql, pgsql...
    maxIdle: 10
    maxOpen: 100
    slowThreshold: "2s"

Running

go
package main

import (
  _ "ghostbb.io/gb/contrib/driver/mssql"
  "ghostbb.io/gb"
)

func main() {
  db := g.DB()
  // ...operate
}