A Rails/ActiveRecord like ORM for your AngularJS project
That's where this ORM comes in. If you have a Rails app that serializes it's records with AMS then this allows you to define your models on your client so you can use them kind of like you did on the server side.
Here is a Coffeescript example of a client side model definition:
@singular: 'dog' # term for single (required)@plural: 'dogs' # term for many (required)@indices: 'ownerId'# index these columns for fast lookup: -> # fn returning attributes for new recordsname: nullage: 0isFluffy: true: -> # describe the relationships with other records@hasMany 'fleas'# creates method dog.fleas() so you can retrieve associated flea records.# optional arguments available (defaults shown)from: 'fleas' # collection that the associated records live inwith: 'dogId' # foreign keyof: 'id' # source keysortBy: 'letter' # optional sorting (not default acutally)sortDesc: true # But wait there's more! Chain anything from http://lokijs.org/#/docs#views@belongsTo 'owner'# creates dog.owner()from: 'people' # owner is a person record in the people collectionby: 'ownerId' # by: 'ownerId', of: 'id' are the defaultsof: 'id' # in this case. only specified here as example: -> # add any model methods you wish@ownername # this gives you dog.ownerName(): ->_each _sample@fleas5 # lodash is available for youfleaawaken
Other things I really like about my library:
- Built specifically to work with Active Model Serializer with rails snake_case -> camel case
- withs with active model serializers - highlight embed_ids
- only ever one version of a record.. single source of truth
- rails/ActiveRecord like relationship declarations: hasMany, belongsTo
- makes relationships and computed attributes and generally being a model really easy.
- restfulClient makes http requests easy
To maybe do:
- automatically add index columns when specifying relationships
To find out how to use this for real, you should read the files in /test
To compile files from src to dist: npm run build To run the tests: npm test
to publish a new version (eg: 5.4.2) update package.json with the new version. git commit -m "update with my new stuff and version" git tag 5.4.2 git push origin master --tags