Socket
Socket
Sign inDemoInstall

json-odm

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-odm

MaF) Object document mapper for JSON data that provides mongodb methods for querying and transformation as well as additional joining that is not provided by mongodb


Version published
Maintainers
1
Created
Source

JSON ODM v0.1.1

by Konsultaner, Richard Burkhardt

This Project aims to be provide a json object document mapper.
Why would I need this?
There are many cases where you do not want to have the server query your data. You may also see this mapper as a fancy way to filter your data or prepare a view model. The original use case was an ionic app that was not interactive so providing a server backend was not needed, but structuring my data into joinable collections seemed very helpful.

If you like the project please support it with a star here on GitHub

If commercial support is needed please contact me.

Docs

You can find the documentation here or compiled to the folder /doc/jsonOdm/0.1/*.

Road map

  • Implement query methods from mongo db
    • Comparison ($eq,$gt,$gte,$lt,$lte,$ne,$in,$nin) 100%
    • Logical ($or,$and,$not(= $nand as alias),$nor) 100%
    • Element ($exists,$type) 100% (+ $isNull, for is null or undefined)
    • Evaluation ($mod,$regex,$text,$where) 100%
    • Geospatial ($geoWithin,$geoIntersects,$near,$nearSphere) 50% (maybe have a hard and a soft check -> performance)
    • Array ($all,$elementMatch,$size) 0% // i may not implement the first two
    • Projection Operators ($,$elemMatch,$meta,$slice) 0%
  • Support Promise/A+ sources for the odm.addSource
  • Full CRUD support
  • Aggregation

Required NPM-Packages

To build it from source use command gulp and after adding:

npm install --save-dev gulp
npm install --save-dev gulp-concat
npm install --save-dev gulp-filesize
npm install --save-dev gulp-jsdoc
npm install --save-dev gulp-uglify
npm install --save-dev jsdoc3-bootstrap

To execute the benchmark use command gulp bench after adding:

npm install --save-dev gulp-bench

Browser Support

Unit test ran successfully under Chrome,iOS7+,IE9+,Firefox,Android 4.4.2+
To be tested: Safari on OSX, IE8(test driver does not run in IE < 9 so it will be hard to test)

Example

This is only a basic example. Find more in the docs, i.e. how to use $geoWithin

<!-- add minified version from https://github.com/konsultaner/jsonOdm/tree/master/bin to the html head -->
<script type="text/javascript" src="js/json.odm.min.js"></script>
// initialize The mapper
var odm = new jsonOdm();
// add a source to the mapper
odm.addSource('people',{
   "Person" : [
       {"id":1,"name":"Richi",jobId:1,hobbyIds:[1,3,4]},
       {"id":2,"name":"Dave",jobId:2,hobbyIds:[2,4]},
       {"id":3,"name":"Tom",jobId:3,hobbyIds:[3,5]},
       {"id":4,"name":"Lisa",jobId:4,hobbyIds:[1,2,3]},
       {"id":5,"name":"Hanni",jobId:3,hobbyIds:[1,5]},
       {"id":6,"name":"Selma",jobId:3,hobbyIds:[1,4]},
       {"id":7,"name":"Ralf",jobId:1,hobbyIds:[4,3]}
   ],
   "Jobs" : [
       {"id":1,"name":"plumber"},
       {"id":2,"name":"programmer"},
       {"id":3,"name":"chef"},
       {"id":4,"name":"hairdresser"}
   ],
   "Hobbies" : [
       {"id":1,"name":"swimming"},
       {"id":2,"name":"cycling"},
       {"id":3,"name":"fishing"},
       {"id":4,"name":"coding"},
       {"id":5,"name":"dancing"}
   ]
});
// instantiate a collection object
var people = new jsonOdm.Collection('Person');
people.$hasOne("jobId","id","Jobs","job");
people.$hasMany("hobbyIds","id","Hobbies","hobbies");

var q = people.query();
// get all hairdresser and plumber
var hairdresser = q.$or(
   q.$branch("jobId").$eq(1)
   q.$branch("jobId").$eq(4)
).$all();

// get all but hairdressers and plumbers
var hairdresser = q.$and(
   q.$branch("jobId").$ne(1)
   q.$branch("jobId").$ne(4)
).$all();

// delete all plumbers
q.$branch("job","name").$eq("plumber").$delete();

License

The MIT License (MIT)

Copyright (c) 2015 Richard Burkhardt - Konsultaner GmbH & Co. KG

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 22 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc