- CheckCharDoSpecial 检查字符串,去掉特殊字符
- InArray 判断某个值是否包含在内
实现golang的数据库增删改查操作,无需传入表结构,快捷操作数据库
var config = DBConfig{
Host: "localhost",
Port: 3308,
Name: "root",
Pass: "123456",
DBName: "sgfoot",
Charset: "utf8mb4",
}
var (
MasterDB Modeler //定义主DB
)
func init() {
db := InitDB(config)
model := NewDB(db)
MasterDB = model
}
ls, err := MasterDB.Find("select * from book")
ls, err := MasterDB.First("select * from book where id = ?", 1)
ls, err := MasterDB.Pluck("select * from book where id = ?", "book_name", 3)
ls, err := MasterDB.Insert("insert into book set book_name=?, book_author=?, book_province=?", "论语", "孔子", "山东")
ls, err := MasterDB.Update("update book set book_name=? where id=?", "国学-论语", 3)
ls, err := MasterDB.Delete("delete from book where id = ?", 1)