From 4fc90431cd392f1d6a400349050d7aff041f0d0b Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Tue, 27 Mar 2012 18:49:20 +0400 Subject: [PATCH] docs --- index.html | 702 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 702 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 00000000..65cd5d81 --- /dev/null +++ b/index.html @@ -0,0 +1,702 @@ + + + + AbstractClass | JugglingDB API docs + + + + + + +
+
+ +
+

AbstractClass

Abstract class - base class for all persist objects +provides common API to access any database adapter. +This class describes only abstract behavior layer, refer to lib/adapters/*.js +to learn more about specific adapter implementations

+ +

AbstractClass mixes Validatable and Hookable classes methods

+ +


constructor +
param Object data - initial object data

Source code
Class methods Instance methods Helper methods

AbstractClass.defineProperty

Declared as function (prop, params)


param String prop - property name +
param Object params - various property configuration

Source code

AbstractClass.create

Declared as function (data, callback)

Create new instance of Model class, saved in database

+ +


param data [optional] +
param callback(err, obj) +callback called with arguments:

+ +
    +
  • err (null or Error)
  • +
  • instance (null or Model)
  • +
Source code

AbstractClass.upsert

Declared as AbstractClass.updateOrCreate

Update or insert

Source code

AbstractClass.exists

Declared as function exists(id, cb)

Check whether object exitst in database

+ +


param id id - identifier of object (primary key value) +
param Function cb - callbacl called with (err, exists: Bool)

Source code

AbstractClass.find

Declared as function find(id, cb)

Find object by id

+ +


param id id - primary key value +
param Function cb - callback called with (err, instance)

Source code

AbstractClass.all

Declared as function all(params, cb)

Find all instances of Model, matched by query +make sure you have marked as index: true fields for filter or sort

+ +


param Object params (optional)

+ +
    +
  • where: Object { key: val, key2: {gt: 'val2'}}
  • +
  • order: String
  • +
  • limit: Number
  • +
  • skip: Number
  • +
+ +


param Function callback (required) called with arguments:

+ +
    +
  • err (null or Error)
  • +
  • Array of instances
  • +
Source code

AbstractClass.findOne

Declared as function findOne(params, cb)

Find one record, same as all, limited by 1 and return object, not collection

+ +


param Object params - search conditions +
param Function cb - callback called with (err, instance)

Source code

AbstractClass.destroyAll

Declared as function destroyAll(cb)

Destroy all records +
param Function cb - callback called with (err)

Source code

AbstractClass.count

Declared as function (where, cb)

Return count of matched records

+ +


param Object where - search conditions (optional) +
param Function cb - callback, called with (err, count)

Source code

AbstractClass.toString

Declared as function ()

Return string representation of class

+ +


override default toString method

Source code

AbstractClass.hasMany

Declared as function hasMany(anotherClass, params)

Declare hasMany relation

+ +


param Class anotherClass - class to has many +
param Object params - configuration {as:, foreignKey:} +
example User.hasMany(Post, {as: 'posts', foreignKey: 'authorId'});

Source code

AbstractClass.belongsTo

Declared as function (anotherClass, params)

Declare belongsTo relation

+ +


param Class anotherClass - class to belong +
param Object params - configuration {as: 'propertyName', foreignKey: 'keyName'}

Source code

AbstractClass.scope

Declared as function (name, params)

Define scope +TODO: describe behavior and usage examples

Source code

AbstractClass.prototype.save

Declared as function (options, callback)

Save instance. When instance haven't id, create method called instead. +Triggers: validate, save, update | create +
param options {validate: true, throws: false} [optional] +
param callback(err, obj)

Source code

AbstractClass.prototype._adapter

Declared as function ()

Return adapter of current record +
private

Source code

AbstractClass.prototype.toObject

Declared as function (onlySchema)

Convert instance to Object

+ +


param Boolean onlySchema - restrict properties to schema only, default false +when onlySchema == true, only properties defined in schema returned, +otherwise all enumerable properties returned +
returns Object - canonical object representation (no getters and setters)

Source code

AbstractClass.prototype.destroy

Declared as function (cb)

Delete object from persistence

+ +


triggers destroy hook (async) before and after destroying object

Source code

AbstractClass.prototype.updateAttribute

Declared as function updateAttribute(name, value, callback)

Update single attribute

+ +

equals to `updateAttributes({name: value}, cb)

+ +


param String name - name of property +
param Mixed value - value of property +
param Function callback - callback called with (err, instance)

Source code

AbstractClass.prototype.updateAttributes

Declared as function updateAttributes(data, cb)

Update set of attributes

+ +

this method performs validation before updating

+ +


trigger validation, save and update hooks +
param Object data - data to update +
param Function callback - callback called with (err, instance)

Source code

AbstractClass.prototype.propertyChanged

Declared as function propertyChanged(attr)

Checks is property changed based on current property and initial value

+ +


param String attr - property name +
return Boolean

Source code

AbstractClass.prototype.reload

Declared as function reload(callback)

Reload object from persistence

+ +


requires id member of object to be able to call find +
param Function callback - called with (err, instance) arguments

Source code

AbstractClass.prototype.reset

Declared as function ()

Reset dirty attributes

+ +

this method does not perform any database operation it just reset object to it's +initial state

Source code

isdef

Declared as function isdef(s)

Check whether s is not undefined +
param Mixed s +
return Boolean s is undefined

Source code

merge

Declared as function merge(base, update)

Merge base and update params +
param Object base - base object (updating this object) +
param Object update - object with new data to update base +
returns Object base

Source code

defineReadonlyProp

Declared as function defineReadonlyProp(obj, key, value)

Define readonly property on object

+ +


param Object obj +
param String key +
param Mixed value

Source code

addToCache

Declared as function addToCache(constr, obj)

Add object to cache

Source code

touchCache

Declared as function touchCache(constr, id)

Renew object position in LRU cache index

Source code

getCached

Declared as function getCached(constr, id)

Retrieve cached object

Source code

clearCache

Declared as function clearCache(constr)

Clear cache (fully)

+ +

removes both cache and LRU index

+ +


param Class constr - class constructor

Source code

removeFromCache

Declared as function removeFromCache(constr, id)

Remove object from cache

+ +


param Class constr +
param id id

Source code
+
+ +
+
+

© 1602 Software

+
+
+ + + + +