package main

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
)

var DB *gorm.DB


func init() {
	var err error

	DB, err = gorm.Open("mysql", "root:123456@tcp(192.168.88.130:3306)/test?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}

	DB.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户'").AutoMigrate(&UserInfo{})
}

type UserInfo struct {
	Name     string `orm:"pk;column(name)"`
	Password string
}
func main(){
	var count  int
name非daw的记录个数
	DB.Model(&UserInfo{}).Where("name <> ?","daw").Count(&count)
	fmt.Println(count)
}

 

Logo

更多推荐