returnnil,fmt.Errorf("failed to get database instance: %v",err)
}
// Fetch pools from database
rows,err:=db.Query("SELECT DISTINCT `pool` FROM `user_pool` WHERE `user`=? AND `pool` IN (SELECT `pool` FROM `pool_question` GROUP BY `pool` HAVING COUNT(DISTINCT `question`) >= ?)",userID,QuestionsPerRound)
// Check whether query failed
iferr!=nil{
returnnil,fmt.Errorf("failed fetching pools from database: %v",err)
}
deferrows.Close()
// Generate output
varpools[]uint32
forrows.Next(){
varpooluint32
iferr:=rows.Scan(&pool);err!=nil{
returnnil,fmt.Errorf("failed aggregating pools from database: %v",err)
}
pools=append(pools,pool)
}
returnpools,nil
}
// PatchUserPools insert relations into user_pool for all pools in the array `selection`.
// Relations to pools that are not in `selection` are deleted.