Another API for querying and KeySelector

I am restarting my work on python asyncio foundationdb bindings.

One feedback I get a lot about foundationdb is about how to query the database: “Where is the declarative language”… This is mostly in comparison with SQL databases, even if eventually most people hide the SQL with an API with something like an ORM!

In fact, there is really 6 methods to know about to be able to be productive:

  • get (read)
  • set (create or update)
  • range (read)
  • range_startswith (read)
  • clear (delete)
  • clear_range (delete)

We can add to that get_key but so far I do not use it.

I want to reduce further the API surface in (my) python asyncio bindings and introduce a Transaction.query method that will merge the behavior of get, range and range_startswith together, also clear and clear_range will be a single method.

Here is the signature of Transaction.query:

Transaction.query(selector, other=None, limit=None)

In particular if other.key < selector.key then it means that results should be returned reversed and is equivalent to tr.range(selector, other, reverse=True)

Also, will make tuple.strinc public to be able to query by prefix (or add a prefix keyword argument?)

Similarly, to clear a range or single key there will be:

Transaction.delete(selector, other=None)

Case in point: I think this is more explicit how to query since there is a method called query.

Long story, I struggle with KeySelector:

I will not explain what I do not understand to avoid to add confusion except ask the question:

Why first_greater_or_equal has or_equal == False