simple-odata-server-lowdb
v2.0.0
Published
Adapter for node.js simple odata server using lowdb
Downloads
3
Maintainers
Readme
Adapter for node.js simple odata server using lowdb.
It can be used as follows:
import { createServer } from "http";
import { Low, Memory } from "lowdb";
import Adapter from "simple-odata-server-lowdb";
import ODataServer from "simple-odata-server";
const model = {
namespace: "jsreport",
entityTypes: {
"UserType": {
"_id": {"type": "Edm.String", key: true},
"test": {"type": "Edm.String"},
}
},
entitySets: {
"users": {
entityType: "jsreport.UserType"
}
}
};
const memoryDB = new Memory();
const db = new Low(memoryDB);
if (!db.data) {
db.data = {};
db.write();
}
const odataServer = ODataServer("http://localhost:1777");
odataServer
.model(model)
.adapter(Adapter(function (coll, cb) {
if (!db.data[coll]) {
db.data[coll] = [];
}
const hasPendingChanges = cb(null, db.data[coll]);
if (hasPendingChanges) {
db.write();
}
}));
createServer(odataServer.handle.bind(odataServer)).listen(1777);