You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'use strict';const{ ServiceBroker }=require('moleculer');constRService=require('@kothique/moleculer-rethinkdbdash');constbroker=newServiceBroker({logLevel: 'debug'});// Create a DB service for `user` entitiesbroker.createService({name: 'users',mixins: [RService],/* Options passed to `rethinkdbdash` directly. */rOptions: {db: 'mydb',// rethinkdbdash's option, has nothing to do with the mixintimeout: 30,buffer: 80},/* Ensure certain dbs, tables, and indices are created. */rInitial: r=>({mydb: {// Ensure database `mydb` existsusers: {// Ensure table `users` exists in `mydb`$default: true,// So that `this.rTable` === `this.r.db('mydb').table('users')`$options: {// Options passed to `tableCreate`primaryKey: 'boom',durability: 'soft'},// Ensure indexes exist in `users`username: true,my_awesome_compound_index: {$function: [r.row('compound'),r.row('index')]// Index function},nicknames: {$function: r.row('nestedData')('nicknames'),$options: {multi: true}}},/* anotherTable: { ... }, ... */},/* anotherDB: { ... }, ... */}),/* Called when all dbs, tables, and indices are created. */asyncrOnReady(){constusersByAge=awaitthis.rTable.orderBy(this.r.desc('age'));constchangesCursor=awaitthis.r.db('boom').table('meow').changes();// ...}});broker.start();
About
Moleculer service ensuring specified dbs, tables, and indices exist, and giving access to the driver.