1 Star 0 Fork 0

mq-go / bluebell

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
柒染 提交于 2023-10-01 20:15 . 社区设计
/*
* @Author: drowningwhale 351231768@qq.com
* @Date: 2023-10-01 16:30:07
* @LastEditors: drowningwhale 351231768@qq.com
* @LastEditTime: 2023-10-01 16:34:39
* @FilePath: \bluebell\models\create\main.go
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
package main
import (
"log"
"os"
"time"
"gitee.com/mq-go/bluebell/models"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
)
func main() {
dsn := "root:root@tcp(192.168.12.100:3306)/bluebell?charset=utf8mb4&parseTime=True&loc=Local"
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // 缓慢的 SQL 阈值
LogLevel: logger.Info, // 日志级别
IgnoreRecordNotFoundError: true, // 忽略日志记录器 ErrRecordNotFound 错误
ParameterizedQueries: true, // 不要在 SQL 日志中包含参数
Colorful: true, // 禁用颜色
},
)
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true,
},
Logger: newLogger,
})
if err != nil {
panic(err)
}
value1 := &models.Community{
CommunityId: 1,
CommunityName: "Go",
Introduction: "Golang",
}
value2 := &models.Community{
CommunityId: 2,
CommunityName: "leetcode",
Introduction: "刷题刷题刷题",
}
value3 := &models.Community{
CommunityId: 3,
CommunityName: "CS:GO",
Introduction: "Rush B。。。",
}
value4 := &models.Community{
CommunityId: 4,
CommunityName: "LOL",
Introduction: "欢迎来到英雄联盟!",
}
db.Create(&value1)
db.Create(&value2)
db.Create(&value3)
db.Create(&value4)
}
Go
1
https://gitee.com/mq-go/bluebell.git
git@gitee.com:mq-go/bluebell.git
mq-go
bluebell
bluebell
d993e0e507c7

搜索帮助