OMG.js is an Object-Relation Mapper for HTML5 Local Storage
JavaScript CSS
Switch branches/tags
Permalink
Failed to load latest commit information.
tests
.bower.json
.editorconfig
.gitignore
LICENSE
README.md
bower.json
component.json
omg.js
package.json

README.md

omg.js: An object oriented interface, ORM, and caching layer for HTML5 Local Storage

Local storage is dope, but current browser implementations only provide a UI blocking, string based interface for key-value pairs.

omg.js is an object oriented, CRUD interface for HTML5 Local Storage. It enables asynchronous read and writes with a built in caching layer for less code and better performing frontend applications.

Use

Create Collections

Create an empty collection

omg.create('People');

Create a collection with seed data by passing an object.

omg.create('People', {name: 'Zelda'});

or pass an array of objects.

omg.create('People', [{name: 'Link'}, {name: 'Ganon'}]);

Add Objects

Add singe object (or array of objects) to collection

omg.add('People', {name: 'Navi'});

Read / Get Objects

Get an entire collection as an array of objects

omg.get('People');

Get a single object from a collection (by ID)

omg.getOne('People', '_xrtfghn09');

Get an array of objects by property

omg.getBy('People', 'name', 'Link');

Get any property from an object

omg.getOne('People', '_xrtfghn09').name;

Delete objects

Delete any collection

omg.delete('People');

Delete a single object from collection by ID

omg.deleteOne('People', '_xrtfghn09');

omg automatically generates a unique ID for every object added to storage.

Update / Save

Update single object in collection

var person = omg.getBy('People', 'name', 'Ganon');
person.name = 'Ganondorf';
omg.save('People', person);

Callbacks

Run callback functions when specific omg function is called

omg.on('create', function() {
	console.log('Something was created!');
};

To Do Soon

  • Write docs for caching objects
  • Rename caching functions to match other CRUD functions
  • only get/set on window load/unload or during user silence

Set up relationship

omg.link('People', 'Weapons');

Get Weapons of People _ax4e390x

omg.get('People', '_ax4e390x', 'Weapons');

Limit return to 2

omg.get('People', 'Weapons').limit(1);

Last / First Weapon

omg.get('People', '_ax4e390x', 'Weapons').first();
omg.get('People', '_ax4e390x', 'Weapons').last();

To Do later

  • Rename collections
omg.update('People', 'Characters');
  • Make delete / update functions more efficient (Calling setItem() with a named key that already exists will silently overwrite the previous value.)