80 Star 451 Fork 139

Ulric Qin/Nightingale

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
builtin_cate.go 971 Bytes
一键复制 编辑 原始数据 按行查看 历史
ning 提交于 2023-03-09 17:43 +08:00 . v6 release
package models
import (
"github.com/ccfos/nightingale/v6/pkg/ctx"
)
type BuiltinCate struct {
Id int64 `json:"id" gorm:"primaryKey"`
Name string `json:"name"`
UserId int64 `json:"user_id"`
}
func (b *BuiltinCate) TableName() string {
return "builtin_cate"
}
// 创建 builtin_cate
func (b *BuiltinCate) Create(c *ctx.Context) error {
return Insert(c, b)
}
// 删除 builtin_cate
func BuiltinCateDelete(c *ctx.Context, name string, userId int64) error {
return DB(c).Where("name=? and user_id=?", name, userId).Delete(&BuiltinCate{}).Error
}
// 根据 userId 获取 builtin_cate
func BuiltinCateGetByUserId(c *ctx.Context, userId int64) (map[string]BuiltinCate, error) {
var builtinCates []BuiltinCate
err := DB(c).Where("user_id=?", userId).Find(&builtinCates).Error
var builtinCatesMap = make(map[string]BuiltinCate)
for _, builtinCate := range builtinCates {
builtinCatesMap[builtinCate.Name] = builtinCate
}
return builtinCatesMap, err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/cnperl/Nightingale.git
[email protected]:cnperl/Nightingale.git
cnperl
Nightingale
Nightingale
main

搜索帮助