angular-rethinkDB | Angular module for NoSQL realtime database #angular_js_directive…

  • This is an Angular module for RethinkDB NoSQL realtime database using Observables and Socket.io-client, this is based and influenced by AngularFire2 module created by David East so, thanks to him.
  • In order to use this, you will need to build a backend seervice for RethinkDB, or you might use this one

This is an Angular module for RethinkDB NoSQL realtime database using Observables and Socket.io-client, this is based and influenced by AngularFire2 module created by
David East so, thanks to him.

This is an work in progress so apologies for the lack of documentation.

Usage

Here is a simple demo

Module 1st

In order to use this, you will need to build a backend seervice for RethinkDB, or you might use this one
https://github.com/mariolenis/rethinkdb-daas


import {AngularRethinkDBModule} from ‘angular-rethinkdb’;

@NgModule({
declarations: […],
imports: [
…,
AngularRethinkDBModule.forRoot({
api_key: ‘AAAA-BBBBB-CCCCC’,
database: ‘your-db’,
host: ‘://<:port>‘
})
],
providers: […],
bootstrap: [AppComponent]
})
export class AppModule { }

Component Then


import {AngularRethinkDBService, AngularRethinkDBObservable, IRethinkDBQuery} from ‘angular-rethinkdb’;
import {BehaviorSubject} from ‘rxjs/BehaviorSubject’;

interface IMyObjectType {

}

@Component({

})
export class Component {

myTable: AngularRethinkDBObservable;
myQuery$ = new BehaviorSubject(undefined);

constructor(private ar: AngularRethinkDBService) {

// Initialize your object from table, if does not exists, it will be created
// this.ar.list(table : string, query$? : BehaviorSubject)
this.myTable = this.ar.list(‘myTable’, this.myQuery$);

// Query data will register a new filter and only will listen to changes
// according to the next value of query
this.myQuery$.next({
limit: 100,
orderBy: ‘lastUpdate’,
filter: {
name: ‘some name’
}
});

// Subscribe to your object and listen to data
this.myTable
.subscribe(data => console.log(data));

// Push data
let myNewData: IMyObjectType = {…};
this.myTable.push(myNewData)
.subscribe(res => console.log(res));

// Delete data by id
this.myTable.remove(‘random-id’)
.subscribe(res => console.log(res));

// Delete data by custom index
this.myTable.remove({ indexName:’custom-id’, indexValue: ‘id-value’ })
.subscribe(res => console.log(res));

// Modify data
let myUpdatedData = Object.assign(myNewData, {myProp: ‘new value’});

// Then update at myTable
this.myTable.update(myUpdatedData)
.subscribe(
response => console.log(response),
error => console.warn(error) // This is triggered if myUpdatedData has no id as property.
);

// Or you can update by query filter using IRethinkDBQuery interface
this.myTable.update(myUpdatedData, {
filter: {
name: ‘author’
},
limit: 10
})
.subscribe(
response => console.log(response),
error => console.warn(error)
);
}
}

Any change on ‘myTable’ will be published on subscribe method.
push, remove, update methods returns Observables to track the operation result
IRethinkDBQuery All properties are optional. Valid properties are limit: number, orderBy: string and filter : Object;
TODO

[ SECURITY ] Authentication.
[ DOCUMENTATION ] All.


@dataloco: angular-rethinkDB | Angular module for NoSQL realtime database #angular_js_directive…

This is an Angular module for RethinkDB NoSQL realtime database using Observables and Socket.io-client, this is based and influenced by AngularFire2 module created by David East so, thanks to him.

This is an work in progress so apologies for the lack of documentation.

angular-rethinkDB

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.