예제 #1
0
func InitDatabase(s *r.Session, databaseName string) error {
	exists, err := ListContains(s, r.DbList(), databaseName)
	if err != nil {
		return err
	}
	if !exists {
		err := r.DbCreate(databaseName).Exec(s)
		if err != nil {
			return err
		}
	}
	return nil
}
예제 #2
0
// Check if the database has been setup
func (db *RethinkDBAdapter) DbExists() (bool, *CASServerError) {
	cursor, err := r.
		DbList().
		Run(db.session)
	if err != nil {
		casErr := &DbExistsCheckFailedError
		casErr.err = &err
		return false, casErr
	}

	var response []interface{}
	err = cursor.All(&response)

	// Check that the list contains the database name for the adapter
	for _, listedDb := range response {
		if listedDb == db.dbName {
			return true, nil
		}
	}
	return false, nil
}