Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samusgray/omg
OMG.js is an Object-Relation Mapper for HTML5 Local Storage
https://github.com/samusgray/omg
Last synced: 4 months ago
JSON representation
OMG.js is an Object-Relation Mapper for HTML5 Local Storage
- Host: GitHub
- URL: https://github.com/samusgray/omg
- Owner: samusgray
- License: other
- Created: 2014-06-20T02:48:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-15T22:28:53.000Z (over 10 years ago)
- Last Synced: 2024-08-10T10:06:02.279Z (4 months ago)
- Language: JavaScript
- Size: 387 KB
- Stars: 35
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```javascript
omg.create('People');
```#### Create a collection with seed data by passing an object.
```javascript
omg.create('People', {name: 'Zelda'});
```
#### or pass an array of objects.
```javascript
omg.create('People', [{name: 'Link'}, {name: 'Ganon'}]);
```### Add Objects
#### Add singe object (or array of objects) to collection
```javascript
omg.add('People', {name: 'Navi'});
```### Read / Get Objects
#### Get an entire collection as an array of objects
```javascript
omg.get('People');
```#### Get a single object from a collection (by ID)
```javascript
omg.getOne('People', '_xrtfghn09');
```#### Get an array of objects by property
```javascript
omg.getBy('People', 'name', 'Link');
```#### Get any property from an object
```javascript
omg.getOne('People', '_xrtfghn09').name;
```### Delete objects
#### Delete any collection
```javascript
omg.delete('People');
```#### Delete a single object from collection by ID
```javascript
omg.deleteOne('People', '_xrtfghn09');
```
_omg automatically generates a unique ID for every object added to storage._### Update / Save
#### Update single object in collection
```javascript
var person = omg.getBy('People', 'name', 'Ganon');
person.name = 'Ganondorf';
omg.save('People', person);
```### Callbacks
#### Run callback functions when specific omg function is called
```javascript
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
```javascript
omg.link('People', 'Weapons');
```
#### Get Weapons of People _ax4e390x
```javascript
omg.get('People', '_ax4e390x', 'Weapons');
```#### Limit return to 2
```javascript
omg.get('People', 'Weapons').limit(1);
```#### Last / First Weapon
```javascript
omg.get('People', '_ax4e390x', 'Weapons').first();
omg.get('People', '_ax4e390x', 'Weapons').last();
```## To Do later
- Rename collections
```javascript
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.)