UNPKG

@real-db/server

Version:

The library for syncing data changes to multiple devices from your database

56 lines (48 loc) 1.03 kB
import { RealDBCore } from './src'; import * as http from 'http'; const server = http.createServer((req, res) => { console.log(req, res); }); const db = new RealDBCore({ dbUrl: '', adapterId: 'mongodb', httpServer: server }); const m1 = (payload, cb) => { console.log(payload); cb(true); }; const m2 = (oayload, cb) => { cb(false); }; db.setMiddlewares(m1, m2); db.route('room_1', { template: `{ "name": "{{name}}", "_id": "{{userId}}", "$or": [ {"age": {{age}}}, {"holly": {{holy}}} ], "dateOfBirth": { "$lte": {{date}} } }`, queryOptions: { collection: 'users' }, queryParams: { name: "string", userId: "string", age: "number", holy: "boolean", date: 'date' } }); db.route('room_2', { template: '{}', queryOptions: { collection: 'users' }, queryParams: {} });