forked from gohouse/gorose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres.go
38 lines (34 loc) · 974 Bytes
/
postgres.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"github.com/gohouse/gorose/v2"
//_ "github.com/lib/pq"
)
func main() {
// 测试时, 不要忘记打开import内的pg包注释
pgtest()
}
func main2() {
dsn := "user=postgres dbname=postgres password=123456 sslmode=disable"
engin, err := gorose.Open(&gorose.Config{Driver: "postgres", Dsn: dsn})
if err != nil {
panic(err.Error())
}
var orm = engin.NewOrm()
res, err := orm.Query("select * from users where uid>$1", 1)
fmt.Println(res, err)
fmt.Println(engin.NewOrm().Table("users").
Data(map[string]interface{}{"uname": "fizz22"}).
//Where("uid",4).BuildSql("insert"))
Where("uid", 4).BuildSql("update"))
}
func pgtest() {
dsn := "user=postgres dbname=postgres password=123456 sslmode=disable"
engin, err := gorose.Open(&gorose.Config{Driver: "postgres", Dsn: dsn})
if err != nil {
panic(err.Error())
}
var orm = engin.NewOrm()
res,p,err := orm.Table("users").Where("a",1).BuildSql()
fmt.Println(res,p, err)
}