**https://github.com/remixlabs/protoquery/pull/327**
Reference docs: https://github.com/remixlabs/protoquery/wiki/stdlib-db-new
Functions like db_save are no longer outside db:
db_save becomes db.savedb_save_one becomes db.saveOneBefore, 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:
db.toStream: returns the result as streamdb.toArray: returns the result as arraydb.first: returns the first element of the resultdb.last: returns the last element of the resultdb.length: returns the number of result elementsRemember 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
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: