guzeng 89c478b953 | 2 years ago | |
---|---|---|
README.md | 3 years ago | |
chain.go | 2 years ago | |
chain_test.go | 2 years ago | |
conn.go | 2 years ago | |
db.go | 2 years ago | |
db_test.go | 2 years ago | |
go.mod | 2 years ago | |
go.sum | 2 years ago | |
prepare.go | 3 years ago | |
prepare_test.go | 3 years ago | |
sqlserver.go | 3 years ago | |
transaction.go | 2 years ago | |
transaction_chain.go | 2 years ago |
数据库操作
查询单条记录
map,err := new(Query).Db(dbname).Table(tablename).Where("id=?").Where("name=?").Value(1).Value("test").Find()
查询列表
list,err := new(Query).Db(dbname).Table(tablename).Where("id=?").Where("name=?").Value(1).Value("test").Select()
条件"或"
list,err := new(Query).Db(dbname).Table(tablename).Where("id=?").Where("name=?").WhereOr("mobile=?").Value(1).Value("test").Value("22").Select()
联表查
使用Join
list,err := new(Query).Db(dbname).Table(tablename).Join([]string{jointable,tablename.id=jointable.cid,"LEFT"}).Where("id=?").Where("name=?").Value(1).Value("test").Select()
更新
ret,err := new(Query).Db(dbname).Table(tablename).Data("name=?").Data("depart=?").Value("xxx").Value("test").Update()
插入
ret,err := new(Query).Db(dbname).Table(tablename).Data("name=?").Data("depart=?").Value("xxx").Value("test").Create()
删除
ret,err := new(Query).Db(dbname).Table(tablename).Where("name=?").Where("depart=?").Value("xxx").Value("test").Delete()