README.md

couch-ar is a thin active record implementation for couchDB

Motivation

The idea behind couch-ar is to provide an easy to use active record
implementation while keeping the speed of node.js. For this reason
couch-ar does not add a lot of abstraction. My aim is to provide an
easy way to have full domain constructors while writing only the
required information to the db document.

Domain constructors are defined in advance with couch-ar
in a simple format that includes a list of properties to write to the DB.

Constructor

Domain definitions can contain a constructor function as an argument. 'this' in constructor functions points to the instantiated object itself so that you can
use the constructor function to modify the instantiated object or the provided 'that' argument.

I am using Douglas Crockford's parasitic inheritance and power constructors.
To understand my code it is best to understand this style.

After running init() the domain constructors are available from the couch-ar object.

Associations

couch-ar now supports hasMany associations. To define a hasMany association pass a hasMany in the config as shown above.
The value 'PhoneNumber' and 'Child' is a previously defined model.

When you only supply a string then the singular names will be converted by chopping the 's' off the end.
The result is three new methods.

Assuming the hasMany definition above the result will be 6 methods:

addPhoneNumber(pn)

getPhoneNumbers(callback)

removePhoneNumber(pn)

addChild(c)

getChildren(callback)

removeChild(c)

the add and remove can take a phone number directly. However, getters requires a callback which will be passed the result.
The items passed to add and remove must be persisted before trying to add or remove them.

License

Provided under the MIT license. In other words, do what you want with it.