1
0
Fork 0
lunch/db.go

32 lines
796 B
Go

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")
dbmap.AddTableWithName(Group{}, "groups").SetKeys(true, "GroupId")
dbmap.AddTableWithName(Session{}, "sessions").SetKeys(true, "SessionId")
dbmap.AddTableWithName(Attendee{}, "attendees").SetKeys(true, "AttendeeId")
dbmap.AddTableWithName(Suggestion{}, "suggestions").SetKeys(true, "SuggestionId")
err = dbmap.CreateTablesIfNotExists()
if err != nil {
log.Fatal(err)
}
return dbmap
}