forked from asm-products/firesize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.go
More file actions
37 lines (29 loc) · 778 Bytes
/
db.go
File metadata and controls
37 lines (29 loc) · 778 Bytes
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
package models
import (
"database/sql"
"log"
"os"
"github.com/go-gorp/gorp"
_ "github.com/lib/pq"
)
var Dbm *gorp.DbMap
// Init creates a connection to postgres and returns a gorp
func InitDb(url string) {
db, err := sql.Open("postgres", url)
if err != nil {
panic(err)
}
Dbm = &gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}}
Dbm.AddTableWithName(Account{}, "accounts").SetKeys(true, "Id")
Dbm.AddTableWithName(ImageRequest{}, "image_requests").SetKeys(true, "Id")
Dbm.TraceOn("[gorp]", log.New(os.Stdout, "sql:", log.Lmicroseconds))
}
func Insert(m interface{}) error {
return Dbm.Insert(m)
}
func Update(m interface{}) (count int64, err error) {
return Dbm.Update(m)
}
func Delete(m interface{}) (count int64, err error) {
return Dbm.Delete(m)
}