https://github.com/muka/compose-datamap
key-value mapper
https://github.com/muka/compose-datamap
Last synced: about 2 months ago
JSON representation
key-value mapper
- Host: GitHub
- URL: https://github.com/muka/compose-datamap
- Owner: muka
- License: apache-2.0
- Created: 2014-10-14T13:23:29.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-10-30T17:05:36.000Z (over 10 years ago)
- Last Synced: 2025-02-05T05:18:05.130Z (4 months ago)
- Language: JavaScript
- Size: 195 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#compose-datamap
Small library to match external IDs with service objects id.
##Install
`sudo apt-get install redis`
`npm i compose-datamap`
`cp node_modules/compose-datamap/config.dist.js map-config.js`
Review settings in `map-config.js` to match your settings
##Configuration
```javascript
var config = {// enable debug?
debug: false,// prefix for the keys in redis, default to "compose"
// ensure you use one to avoid that ops (like import/export) impacts on other data
key_prefix: "compose",// a string or object compatible with then-redis
// https://github.com/mjackson/then-redis
redis: 'tcp://localhost:6379',// a string or object compatible with compose.io
// https://github.com/compose-eu/Appcelerator/
compose: {
debug: false,
apiKey: 'your api key',
transport: 'http',
},
};require("compose-datamap").setup(config).then(function(mapper){
// NOTE: All methods return a Promise
// setter
// serviceObject has to have an "id" property
// mapper.set(key, serviceObject)
// // .then(function() { ... })// getter
// mapper.get(key)// create
// `.then` has as argument a compose.io ServiceObject instance
// mapper.create(key, serviceObject).then(function(so) {})// read
// mapper.read(key).then(function(so) {})// update
// mapper.update(key, serviceObject).then(function(so) {})// delete
// mapper.update(key).then(function() {})});
```
##Usage
```javascript
var mapper = require('compose-datamap');
mapper.setup(require('./map-config')).then(function() {var code = 'abcd.1234';
var serviceObject = {
name: "my object"
// ...
}// can be a compose.io object too
// serviceObject = new map.ServiceObject(serviceObject);mapper.create(code, serviceObject).then(function(so) {
// so is a ServiceObject instance from compose.io library
console.log("Mapped %s to %s", code, so.id);
console.log(so.toString());map.load(code).then(function(so2) {
if(so.id === so2.id) {
console.log("It works!");
// do other cool stuff...
// so.getStream('myStream').subscribe(function(data) {
// console.log(data);
// })
}
else {
console.log("Something has gone wrong ?!");
}
});});
});
```
##Import & Export
It is possible to migrate the mappings with `export` and `import`
###Export
```javascript
mapper.setup(config).then(function() {
return mapper.export();
})
.then(function(data) {
mapper.db.disconnect();
return Promise.resolve(JSON.stringify(data, null, 2));
})
.then(console.log);
```###Import
```javascript
var map = require('./piped-export.json')
mapper.setup(config).then(function() {
return mapper.import(map);
})
.then(function() {
mapper.db.disconnect();
console.log('Import completed.')
});
```##License
Apache2