Dexie module for Angular 2.0+ projects
npm install ngx-dexie --save
//...
import {DexieModule,DexieConfig} from 'ngx-dexie';
const config: DexieConfig = {
databaseName: 'AppDatabase',//your database name here
schema: {
friends: '++id,first_name,last_name',
teachers: '++id,first_name,last_name'
} // any schema of your choice
};
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
DexieModule.forRoot(config)
],
providers: [
],
bootstrap: [AppComponent]
})
export class AppModule { }
The DexieModule
provides now a configured Dexie db instance and a Dexie db service,i.e. DexieService
which can be injected anywhere inside the AppModule
.
import {Injectable} from '@angular/core';
import {DexieService} from 'ngx-dexie';
@Injectable()
export class IndexedDbService {
constructor(private dexieService: DexieService) {}
addOneFriend(friendObject: Object) {
this.dexieService.addOne('friends',friendObject);
}
}
Adds the entry object
to the dexie table table
Returns a promise which when resolved gives the key of the object added,when rejected gives the error that occured.
Adds multiple objects
to the dexie table table
Returns a promise which works similar to Dexie bulkAdd()
Returns a promise which when resolved gives the number of objects in the table table
Works similar to Dexie put()
Works similar to Dexie bulkPut()
Works similar to Dexie delete()
Works similar to Dexie bulkDelete()
Works similar to Dexie clear()
Works similar to Dexie each()
Works similar to Dexie filter()
Works similar to Dexie get()
Works similar to Dexie get()
Works similar to Dexie limit()
Works similar to Dexie orderBy()
Works similar to Dexie offset()
Works similar to Dexie reverse()
Works similar to Dexie toArray()
Works similar to Dexie toCollection()
Works similar to Dexie update()