Aded rethinkdb support
This commit is contained in:
parent
c18e0dabb5
commit
3411e16418
4 changed files with 26 additions and 29 deletions
|
@ -66,14 +66,14 @@ See the tests for more usage examples.
|
||||||
|
|
||||||
## **Important Notes**
|
## **Important Notes**
|
||||||
|
|
||||||
When connecting to the locally installed instance of MongoDB or docker based MongoDB with authentication enabled, the following connection string is not supported by the MongoDB driver yet.
|
When connecting to a locally installed instance of MongoDB or docker based MongoDB with authentication enabled, the following connection string is not supported yet.
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
var db = Db('mongodb://<username>:<password>@localhost:27017/local');
|
var db = Db('mongodb://<username>:<password>@localhost:27017/testDB');
|
||||||
await db.open();
|
await db.open();
|
||||||
```
|
```
|
||||||
|
|
||||||
Use the following instead.
|
Use the following instead. By default the user access information is stored in `admin` database.
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
var db = Db('mongodb://localhost:27017/testDB');
|
var db = Db('mongodb://localhost:27017/testDB');
|
||||||
|
@ -81,5 +81,7 @@ Use the following instead.
|
||||||
await db.authenticate("<username>", "<password>", authDb: "admin");
|
await db.authenticate("<username>", "<password>", authDb: "admin");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Where
|
||||||
|
|
||||||
* `<username>` is MongoDB username
|
* `<username>` is MongoDB username
|
||||||
* `<password>` is MongoDB password
|
* `<password>` is MongoDB password
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: angel3_mongo
|
name: angel3_mongo
|
||||||
version: 8.2.0
|
version: 8.2.0
|
||||||
description: MongoDB-enabled services for the Angel3 framework. Well-tested.
|
description: This is MongoDB-enabled service for the Angel3 framework.
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
repository: https://github.com/dart-backend/angel/tree/master/packages/mongo
|
repository: https://github.com/dart-backend/angel/tree/master/packages/mongo
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
[![version 1.0.7](https://img.shields.io/badge/pub-1.0.7-brightgreen.svg)](https://pub.dartlang.org/packages/angel_rethink)
|
[![version 1.0.7](https://img.shields.io/badge/pub-1.0.7-brightgreen.svg)](https://pub.dartlang.org/packages/angel_rethink)
|
||||||
[![build status](https://travis-ci.org/angel-dart/rethink.svg?branch=master)](https://travis-ci.org/angel-dart/rethink)
|
[![build status](https://travis-ci.org/angel-dart/rethink.svg?branch=master)](https://travis-ci.org/angel-dart/rethink)
|
||||||
|
|
||||||
RethinkDB-enabled services for the Angel framework.
|
RethinkDB-enabled service for the Angel3 framework.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -14,21 +14,16 @@ dependencies:
|
||||||
angel3_rethink: ^8.0.0
|
angel3_rethink: ^8.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
`package:rethinkdb_driver2` will be installed as well.
|
`belatuk-rethinkdb` driver will be used for connecting to RethinkDB.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
This library exposes one class: `RethinkService`. By default, these services will even
|
This library exposes one class: `RethinkService`. By default, these services will listen to [changefeeds](https://www.rethinkdb.com/docs/changefeeds/ruby/) from the database, which makes them very suitable for WebSocket use. However, only `CREATED`, `UPDATED` and `REMOVED` events will be fired. Technically not
|
||||||
listen to [changefeeds](https://www.rethinkdb.com/docs/changefeeds/ruby/) from the database,
|
a problem, as it lowers the number of events that need to be handled on the client side.
|
||||||
which makes them very suitable for WebSocket use.
|
|
||||||
|
|
||||||
However, only `CREATED`, `UPDATED` and `REMOVED` events will be fired. This is technically not
|
|
||||||
a problem, as it lowers the numbers of events you have to handle on the client side. ;)
|
|
||||||
|
|
||||||
## Model
|
## Model
|
||||||
|
|
||||||
`Model` is class with no real functionality; however, it represents a basic document, and your services should host inherited classes.
|
`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.
|
||||||
Other Angel service providers host `Model` as well, so you will easily be able to modify your application if you ever switch databases.
|
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
class User extends Model {
|
class User extends Model {
|
||||||
|
@ -37,16 +32,21 @@ class User extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
var r = new RethinkDb();
|
var r = RethinkDb();
|
||||||
var conn = await r.connect();
|
var conn = await r.connect(
|
||||||
|
db: 'testDB',
|
||||||
|
host: "localhost",
|
||||||
|
port: 28015,
|
||||||
|
user: "admin",
|
||||||
|
password: "");
|
||||||
|
|
||||||
app.use('/api/users', new RethinkService(conn, r.table('users')));
|
app.use('/api/users', RethinkService(conn, r.table('users')));
|
||||||
|
|
||||||
// Add type de/serialization if you want
|
// Add type de/serialization if you want
|
||||||
app.use('/api/users', new TypedService<User>(new RethinkService(conn, r.table('users'))));
|
app.use('/api/users', TypedService<User>(RethinkService(conn, r.table('users'))));
|
||||||
|
|
||||||
// You don't have to even use a table...
|
// You don't have to even use a table...
|
||||||
app.use('/api/pro_users', new RethinkService(conn, r.table('users').filter({'membership': 'pro'})));
|
app.use('/api/pro_users', RethinkService(conn, r.table('users').filter({'membership': 'pro'})));
|
||||||
|
|
||||||
app.service('api/users').afterCreated.listen((event) {
|
app.service('api/users').afterCreated.listen((event) {
|
||||||
print("New user: ${event.result}");
|
print("New user: ${event.result}");
|
||||||
|
@ -60,17 +60,17 @@ This class interacts with a `Query` (usually a table) and serializes data to and
|
||||||
|
|
||||||
## RethinkTypedService<T>
|
## RethinkTypedService<T>
|
||||||
|
|
||||||
Does the same as above, but serializes to and from a target class using `package:json_god` and its support for reflection.
|
Does the same as above, but serializes to and from a target class using `belatuk_json_serializer` and it supports reflection.
|
||||||
|
|
||||||
## Querying
|
## Querying
|
||||||
|
|
||||||
You can query these services as follows:
|
You can query these services as follows:
|
||||||
|
|
||||||
|
```curl
|
||||||
/path/to/service?foo=bar
|
/path/to/service?foo=bar
|
||||||
|
```
|
||||||
|
|
||||||
The above will query the database to find records where 'foo' equals '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.
|
||||||
|
|
||||||
The former will sort result in ascending order of creation, and so will the latter.
|
|
||||||
|
|
||||||
You can use advanced queries:
|
You can use advanced queries:
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
name: angel3_rethinkdb
|
name: angel3_rethinkdb
|
||||||
version: 8.0.0
|
version: 8.0.0
|
||||||
description: RethinkDB-enabled services for the Angel3 framework.
|
description: This is RethinkDB-enabled service for the Angel3 framework.
|
||||||
publish_to: none
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.3.0 <4.0.0"
|
sdk: ">=3.3.0 <4.0.0"
|
||||||
homepage: https://angel3-framework.web.app/
|
homepage: https://angel3-framework.web.app/
|
||||||
|
@ -19,7 +18,3 @@ dev_dependencies:
|
||||||
test: ^1.25.0
|
test: ^1.25.0
|
||||||
lints: ^4.0.0
|
lints: ^4.0.0
|
||||||
|
|
||||||
dependency_overrides:
|
|
||||||
belatuk_rethinkdb:
|
|
||||||
path: ../../../rethink_db
|
|
||||||
|
|
Loading…
Reference in a new issue