1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
select.go 804 Bytes
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-12-01 18:49 . feat: update tk
// Copyright (c) 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/**
*@describe:
*@author wfl19/Kristas
*@date 2021/10/30
*/
package tk
import (
"fmt"
"gitee.com/kristas/booting-go/framework/core/statement/types"
"gorm.io/gorm"
)
type SelectMapper struct {
types.Repository
table string
db *gorm.DB
}
func NewSelectMapper(table string, db *gorm.DB) *SelectMapper {
return &SelectMapper{
table: table,
db: db,
}
}
func (s *SelectMapper) SelectByExample(example Example, value interface{}) error {
var sql = fmt.Sprintf("%s * %s `%s` ", KeywordSelect, KeywordFrom, s.table)
explain, values := example.explain()
sql += explain
return s.db.Raw(sql, values...).First(value).Error
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.4.3

搜索帮助