Ok, to begin with your db
declaration declares a single customer, not a collection of customers, which is what you want to do, I believe. I'd suggest to declare it as a map from customer numbers to customer data as:
db /customer : intmap(Customer)
Now with customers = /customer
you can get the complete collection of customers and do arbitrary processing on it. Alternatively Db.intmap_fold_range
gives you a fold function on a range of keys from the collection; with that you can easily code your first query as:
names_with_ids_gt(x) =
get_names(names, id) = [/customer[id]/name | names]
Db.intmap_fold_range(@/customer, get_names, [], x, none, (_ -> true))
Of course getting full collection of customers and doing some processing on it will not be very efficient. For a more efficient solution you will need to use an external database and its querying capabilities. Opa support for those is coming very soon: http://blog.opalang.org/2011/11/opas-database-and-where-its-heading.html.