Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/telamon/angular-florm
Frontend Localstore ORM for angular
https://github.com/telamon/angular-florm
Last synced: about 1 month ago
JSON representation
Frontend Localstore ORM for angular
- Host: GitHub
- URL: https://github.com/telamon/angular-florm
- Owner: telamon
- Created: 2013-11-09T13:11:14.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-17T08:18:07.000Z (over 9 years ago)
- Last Synced: 2024-11-09T00:58:49.532Z (about 1 month ago)
- Language: JavaScript
- Size: 210 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# angular-florm
A attempt to make a slight improvement to our santiy when
working model-ish objects persisted in localstore.## Installation
Through bower:$ bower install angular-florm
Otherwise you need to grab `angular-florm.js` from `lib/` folder
## Usage
You've probably seen this before somewhere already.angular.module('myApp', ['ngFlorm']);
var $florm = angular.injector(['myApp']).get('$florm')var Users = $florm('users');
var user = Users.new({name: 'foo', password : 'bar'});
user.potatoes = 12;
user.save(); // Persists using window.localStoreUsers.all({potatoes : 12}); // --> [{name:'foo', ...}]
Users.find(user.id); // --> {name:'foo'}
Users.find({name: 'foo'}); // --> {name:'foo'}### Relations
angular.module('myApp', ['ngFlorm']);
var $florm = angular.injector(['myApp']).get('$florm')var Gorillas = $florm('gorillas',{hasMany:'bananas'}),
Bananas = $florm('bananas',{belongsTo:'gorillas'}),
ape = Gorillas.create();
banana = Banans.create();// Associate banana to ape.
ape.bananas.push(banana);// Read relations
console.log(ape.bananas); // --> [{...}]
// -- or the reverse
console.log(banana.gorillas); --> {...}// Remove relation
ape.banans.splice(0,1);// Associating through belongsTo field.
banana.gorillas = ape; // using reference
banana.gorillas = ape.id; // using id// Removing an belongsTo association
banana.gorillas = null;
note: I'm skipping inflections for now, was about to add an inflection
dependency but figured it would just cause unecessary overhead.
So in other words, you'll have to live with `banana.gorillas` instead of
`banana.gorilla`