1 Star 0 Fork 15

TerryLiu/gosql

forked from fifsky/gosql 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mapper.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
fifsky 提交于 2019-10-16 16:19 . support postgres sql quotes,fix #15
package gosql
type Mapper struct {
db *DB
SQLBuilder
}
// Table select table name
func Table(t string) *Mapper {
db := &DB{database: Sqlx(defaultLink)}
return &Mapper{db: db, SQLBuilder: SQLBuilder{table: t, dialect: newDialect(db.DriverName())}}
}
func (m *Mapper) ShowSQL() *Mapper {
m.db.logging = true
return m
}
//Where
func (m *Mapper) Where(str string, args ...interface{}) *Mapper {
m.SQLBuilder.Where(str, args...)
return m
}
//Update data from to map[string]interface
func (m *Mapper) Update(data map[string]interface{}) (affected int64, err error) {
result, err := m.db.Exec(m.updateString(data), m.args...)
if err != nil {
return 0, err
}
return result.RowsAffected()
}
//Create data from to map[string]interface
func (m *Mapper) Create(data map[string]interface{}) (lastInsertId int64, err error) {
result, err := m.db.Exec(m.insertString(data), m.args...)
if err != nil {
return 0, err
}
return result.LastInsertId()
}
//Delete data from to map[string]interface
func (m *Mapper) Delete() (affected int64, err error) {
result, err := m.db.Exec(m.deleteString(), m.args...)
if err != nil {
return 0, err
}
return result.RowsAffected()
}
//Count data from to map[string]interface
func (m *Mapper) Count() (num int64, err error) {
err = m.db.Get(&num, m.countString(), m.args...)
return num, err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tela2013/gosql.git
git@gitee.com:tela2013/gosql.git
tela2013
gosql
gosql
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385