do
var stmt = select("ROWID, name, desc FROM beers WHERE ROWID = {id}")
if stmt == null then return null
- for row in stmt do return row.to_beer
- return null
+
+ var res = null
+ for row in stmt do
+ res = row.to_beer
+ break
+ end
+ return res
end
# Days where `beer` was available, all known days if `beer == null`
var user_id = row[0].to_i
var token = new_token(user_id)
var u = new User(user_id, row[1].to_s)
+ stmt.close
return new LoginResult(u, token)
end
return null
# TODO update token timestamp and platform/client hint of last connection.
# These informations could help detect malicious access to the account.
- for row in stmt do return row[0].to_i
- return null
+ var res = null
+ for row in stmt do
+ res = row[0].to_i
+ break
+ end
+ return res
end
# Get `User` data from the integer `id`
var stmt = select("name FROM users WHERE ROWID = {id}")
assert stmt != null
- for row in stmt do return new User(id, row[0].to_s)
- return null
+ var res = null
+ for row in stmt do
+ res = new User(id, row[0].to_s)
+ break
+ end
+ return res
end
# Try to sign up a new user, return `true` on success
var b = beer_from_id(beer)
if b == null then return null
- for row in stmt do return new BeerStats(b, row[0].to_f, row[1].to_i)
- return null
+ var res = null
+ for row in stmt do
+ res = new BeerStats(b, row[0].to_f, row[1].to_i)
+ break
+ end
+ return res
end
# Fetch the most recent rating left by `user_id` about `beer`
do
var stmt = select("rating FROM reviews WHERE author = {user_id} AND beer = {beer} ORDER BY ROWID DESC LIMIT 1")
assert stmt != null else print_error "Select 'rating' failed with: {error or else "?"}"
- for row in stmt do return row[0].to_i
- return null
+
+ var res = null
+ for row in stmt do
+ res = row[0].to_i
+ break
+ end
+ return res
end
# Register that `user_from` follows `user_to`
assert stmt != null else
print_error "Select 'follows' failed with: {error or else "?"}"
end
- for row in stmt do return true
+
+ for row in stmt.iterator.to_a do return true
return false
end