function withLock($bitcoinAddr, \Closure $action)
{
    $lockName = "bitcoin-address-{$bitcoinAddr}";
    $r = DB\queryAndFetchAll("SELECT GET_LOCK('{$lockName}', 0)");
    if ($r[0][0] == 1) {
        $action();
        DB\query("SELECT RELEASE_LOCK('{$lockName}')");
        return true;
    } else {
        return false;
    }
}
function select($whereClause, $params = array())
{
    return DB\queryAndFetchAll('SELECT w.*, DATE_FORMAT(w.ending, "%Y-%m-%d") as ending, a.satoshis
     FROM widgets w LEFT JOIN bitcoin_addresses a ON a.address = w.address
     WHERE ' . $whereClause, $params);
}