Matrix/utils/database/databaseConnector.go
2020-10-01 17:45:57 +02:00

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))
}
}