1
0
Fork 0
lunch/db.go

32 lines
796 B
Go
Raw Permalink Normal View History

2016-12-23 06:19:10 -05:00
package main
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
"gopkg.in/gorp.v1"
"log"
)
var DB *gorp.DbMap = initDB()
func initDB() *gorp.DbMap {
db, err := sql.Open("sqlite3", "file:lunch.sqlite?cache=shared&mode=rwc")
if err != nil {
log.Fatal(err)
}
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}
dbmap.AddTableWithName(User{}, "users").SetKeys(true, "UserId")
2017-01-10 08:08:45 -05:00
dbmap.AddTableWithName(Group{}, "groups").SetKeys(true, "GroupId")
2016-12-23 06:19:10 -05:00
dbmap.AddTableWithName(Session{}, "sessions").SetKeys(true, "SessionId")
2016-12-23 08:30:29 -05:00
dbmap.AddTableWithName(Attendee{}, "attendees").SetKeys(true, "AttendeeId")
2016-12-24 10:00:21 -05:00
dbmap.AddTableWithName(Suggestion{}, "suggestions").SetKeys(true, "SuggestionId")
2016-12-23 06:19:10 -05:00
err = dbmap.CreateTablesIfNotExists()
if err != nil {
log.Fatal(err)
}
return dbmap
}