35 lines
635 B
Go
35 lines
635 B
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"log"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
func InitDB(filepath string) (db *sql.DB, err error) {
|
|
log.Printf("Init DB")
|
|
db, err = sql.Open("sqlite3", filepath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if db == nil {
|
|
panic("DB couldn't be initialized")
|
|
}
|
|
|
|
handleError(initDeviceTable(db))
|
|
handleError(initKeyTable(db))
|
|
handleError(initEventTable(db))
|
|
handleError(initRoomTable(db))
|
|
handleError(initTransactionTable(db))
|
|
handleError(initUserTable(db))
|
|
|
|
return
|
|
}
|
|
|
|
func handleError(err error) {
|
|
if err != nil {
|
|
panic(fmt.Sprintf("Could not execute Database Query: %s", err))
|
|
}
|
|
}
|