rethink
RethinkDB-enabled services for the Angel framework.
Installation
Add the following to your pubspec.yaml:
1. dependencies:
2. angel_rethink: ^1.0.0
package:rethinkdb_driver2 will be installed as well.
Usage
This library exposes one class: RethinkService. By default, these services will evenlisten to changefeeds from the database,which makes them very suitable for WebSocket use.
However, only CREATED, UPDATED and REMOVED events will be fired. This is technically nota problem, as it lowers the numbers of events you have to handle on the client side. ;)
Model
Model is class with no real functionality; however, it represents a basic document, and your services should host inherited classes.Other Angel service providers host Model as well, so you will easily be able to modify your application if you ever switch databases.
1. class User extends Model {
2. String username;
3. String password;
4. }
6. main() async {
7. var r = new RethinkDb();
8. var conn = await r.connect();
10. app.use('/api/users', new RethinkService(conn, r.table('users')));
12. // Add type de/serialization if you want
13. app.use('/api/users', new TypedService<User>(new RethinkService(conn, r.table('users'))));
15. // You don't have to even use a table...
16. app.use('/api/pro_users', new RethinkService(conn, r.table('users').filter({'membership': 'pro'})));
18. app.service('api/users').afterCreated.listen((event) {
19. print("New user: ${event.result}");
20. });
21. }
RethinkService
This class interacts with a Query (usually a table) and serializes data to and from Maps.
RethinkTypedService
Does the same as above, but serializes to and from a target class using package:json_god and its support for reflection.
Querying
You can query these services as follows:
1. /path/to/service?foo=bar
The above will query the database to find records where 'foo' equals 'bar'.
The former will sort result in ascending order of creation, and so will the latter.
You can use advanced queries:
1. // Pass an actual query...
2. service.index({'query': r.table('foo').filter(...)});
4. // Or, a function that creates a query from a table...
5. service.index({'query': (table) => table.getAll('foo')});
7. // Or, a Map, which will be transformed into a `filter` query:
8. service.index({'query': {'foo': 'bar', 'baz': 'quux'}});
You can also apply sorting by adding a reql parameter on the server-side.
1. service.index({'reql': (query) => query.sort(...)});
See the tests for more usage examples.

