Changes in the db module

**https://github.com/remixlabs/protoquery/pull/327**

Reference docs: https://github.com/remixlabs/protoquery/wiki/stdlib-db-new

Moving many functions into the db module

Functions like db_save are no longer outside db:

Queries are no longer streams

Before, any query could also be used as a stream. In fact, type query = data*. That way, you could mix functions from db and stream, e.g.

db.head() | db.filter(...) | stream.map(...) | stream.first        // OLD

Also, queries were actually mutable data structures like streams - once you pull data from it, the inner state is mutated. Effectively, you could only pull the result once from the query.

This is now very different. Now the type query is no longer a stream. Rather, a query is just a description, and you need to execute it in order to get the result. You can now execute a query several times, e.g. to get once the number of elements, and then a range of elements. In order to execute a query, use:

Remember that you now have to put db.toStream into the pipeline before you can call stream functions:

db.head() | db.filter(...) | db.toStream | stream.map(...) | stream.first

For rewritten queries, there is by default no fallback Mix code

The db engine can only execute certain filters. For example, the comparison == is supported, but >= is not (yet). In the old db module, the executor automatically fell back to Mix code if one of the unsupported filter elements was spotted. E.g. this worked:

db.head() | db.filter(.field >= "abc") | db.first               // OLD

If you compile this with the new compiler, this filter condition is now rejected (you get a compile-time error).

There are two workarounds. The first means absolute control: