Exemple #1
0
// OpenServerDB Opens a database connection to the server database file or if
// that file does not exists, creates it and then opens a database connection to it.
func OpenServerDB() (*SDB, error) {
	if err := verifyServerDbPath(); err != nil {
		// will panic if not verified
		return nil, logger.LogAppError(err)
	}
	conn, err := sql.Open("sqlite3", constants.GetServerDBPath())
	if err != nil {
		return nil, logger.LogAppError(err)
	}
	return &SDB{db: conn}, nil
}
Exemple #2
0
func verifyServerDbPath() error {
	if err := util.CreateDirectory(constants.DbDirectory); err != nil {
		logger.LogAppError(err)
		panic(fmt.Sprintf("Unable to create database directory %s: %s",
			constants.DbDirectory, err))
	}
	if err := createServerDBtable(constants.GetServerDBPath()); err != nil {
		logger.LogAppErrorf("Unable to verify database path: %s", err)
		panic("Unable to verify database path")
	}

	return nil
}