npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular_record_store

v3.0.19

Published

An ActiveRecord-like ORM built ontop of Loki-js

Downloads

194

Readme

travis build badge

RecordStore

A Rails/ActiveRecord like ORM for your AngularJS project

Have you heard of LokiJS? It's a javascript database library that behaves a lot like MongoDB. It's built with a focus on performance and has great querying and indexing features. I reckon it's really neat.

Have you heard of Active Model Serializers? It's a Rails JSON library for serializing your ActiveRecord models to Javascript. It makes it easy to specify how to serialize a record and it's relationships into JSON. It's a bit of a weirdo library in that the 0.8 branch was really good, the 0.9 branch was terrible and it's not super clear if the 1.0 branch is ready to use yet.. I've not tried it yet because 0.8 does the job.

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:

class DogModel extends BaseModel
  @singular: 'dog'        # term for single (required)
  @plural: 'dogs'         # term for many (required)
  @indices: ['ownerId']   # index these columns for fast lookup

  defaultValues: ->       # fn returning attributes for new records
    name: null
    age: 0
    isFluffy: true

  relationships: ->       # 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 in
      with: 'dogId'       # foreign key
      of: 'id'            # source key
      sortBy: '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 collection
      by: 'ownerId'       # by: 'ownerId', of: 'id' are the defaults
      of: 'id'            # in this case. only specified here as example

  ownerName: ->           # add any model methods you wish
    @owner.name()         # this gives you dog.ownerName()

  scratchSelf: ->
    _.each _.sample(@fleas(), 5), (flea) -> # lodash is available for you
      flea.awaken()

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