<commit_before>
<img src="https://github.com/flatiron/resourceful/raw/master/resourceful.png" />

# Synopsis
Isomorphic Resource engine for JavaScript. Resources are business logic wrapped in prototypical models with schema and validation. Supports several data-providers such as: Memory, CouchDB, MongoDB, REST, socket.io, and File-System.

# Status

[![Build Status](https://secure.travis-ci.org/flatiron/resourceful.png?branch=master)](http://travis-ci.org/flatiron/resourceful)

# Features
* Data Validation
* Simplified Data Model Management
* [Relationships](#relationships)
* [Data Provider Extensible](#engines)
* [Simplified Cache Control](#cache)

# Installation

``` bash 
$ [sudo] npm install resourceful
```

# Usage

## Simple case

``` js
var resourceful = require('resourceful');

var Creature = resourceful.define('creature', function () {
  //
  // Specify a storage engine
  //
  this.use('couchdb');
  
  //
  // Specify some properties with validation
  //
  this.string('diet');
  this.bool('vertebrate');
  this.array('belly');

  //
  // Specify timestamp properties
  //
  this.timestamps();
});

//
// Now that the `Creature` prototype is defined
// we can add custom logic to be available on all instances
//
Creature.prototype.feed = function (food) {
  this.belly.push(food);
};
```
<a name="engines"></a>

# Engines 

### Documentation

 * [Engine Usage](https://github.com/flatiron/resourceful/wiki/Engines-Class)
 * [Engine Class](https://github.com/flatiron/resourceful/wiki/Engines-Class)
 * [Engine Caching](https://github.com/flatiron/resourceful/wiki/Engines-Caching)

<a name="relationships"></a>
# Relational Resources

Resourceful supports a simple `Resource.parent` API, which is actually quite robust. Through this API, resourceful supports one-one, one-many, and many-many relationships.

### Documentation

 * [Relational Resources](https://github.com/flatiron/resourceful/wiki/Engines-Class)


# API

## Resource Constructor Methods
These methods are available on all user-defined resource constructors, as well as on the default `resourceful.Resource` constructor.

* `Resource.get(id, [callback])`: Fetch a resource by `id`.
* `Resource.update(id, properties, [callback])`: Update a resource with properties.
* `Resource.destroy(id, [callback])`: Destroy a resource by `id`.
* `Resource.all([callback])`: Fetches all resources of this type.
* `Resource.find(properties, [callback])`: Find all resources of this type which satisfy `obj` conditions.
* `Resource.save(inst, [callback])`: Saves the specified resource instance `inst` by overwriting all properties.
* `Resource.create(properties, [callback])`: Creates a new instance of the Resource with the specified `properties`.
* `Resource.new(properties)`: Instantiates a new instance of the Resource with the `properties`.

## Resource Instance Methods

* `Resource.prototype.save([callback])`
* `Resource.prototype.update(properties, [callback])`
* `Resource.prototype.destroy([callback])`
* `Resource.prototype.reload([callback])`

## Relationship Constructor Methods
These methods are available on all user-defined resource constructors which are in a relationship

* `Parent.children(id, [callback])`: Fetches all the children for the specified `id`.
* `Parent.createChild(id, properties, [callback])`: Create a child for `id` with the specified `properties`.<commit_msg>[docs] Fixed broken link to wiki<commit_after>
<img src="https://github.com/flatiron/resourceful/raw/master/resourceful.png" />

# Synopsis
Isomorphic Resource engine for JavaScript. Resources are business logic wrapped in prototypical models with schema and validation. Supports several data-providers such as: Memory, CouchDB, MongoDB, REST, socket.io, and File-System.

# Status

[![Build Status](https://secure.travis-ci.org/flatiron/resourceful.png?branch=master)](http://travis-ci.org/flatiron/resourceful)

# Features
* Data Validation
* Simplified Data Model Management
* [Relationships](#relationships)
* [Data Provider Extensible](#engines)
* [Simplified Cache Control](#cache)

# Installation

``` bash 
$ [sudo] npm install resourceful
```

# Usage

## Simple case

``` js
var resourceful = require('resourceful');

var Creature = resourceful.define('creature', function () {
  //
  // Specify a storage engine
  //
  this.use('couchdb');
  
  //
  // Specify some properties with validation
  //
  this.string('diet');
  this.bool('vertebrate');
  this.array('belly');

  //
  // Specify timestamp properties
  //
  this.timestamps();
});

//
// Now that the `Creature` prototype is defined
// we can add custom logic to be available on all instances
//
Creature.prototype.feed = function (food) {
  this.belly.push(food);
};
```
<a name="engines"></a>

# Engines 

### Documentation

 * [Engine Usage](https://github.com/flatiron/resourceful/wiki/Engines-Class)
 * [Engine Class](https://github.com/flatiron/resourceful/wiki/Engines-Class)
 * [Engine Caching](https://github.com/flatiron/resourceful/wiki/Engines-Caching)

<a name="relationships"></a>
# Relational Resources

Resourceful supports a simple `Resource.parent` API, which is actually quite robust. Through this API, resourceful supports one-one, one-many, and many-many relationships.

### Documentation

 * [Relational Resources](https://github.com/flatiron/resourceful/wiki/Relational-Resources)


# API

## Resource Constructor Methods
These methods are available on all user-defined resource constructors, as well as on the default `resourceful.Resource` constructor.

* `Resource.get(id, [callback])`: Fetch a resource by `id`.
* `Resource.update(id, properties, [callback])`: Update a resource with properties.
* `Resource.destroy(id, [callback])`: Destroy a resource by `id`.
* `Resource.all([callback])`: Fetches all resources of this type.
* `Resource.find(properties, [callback])`: Find all resources of this type which satisfy `obj` conditions.
* `Resource.save(inst, [callback])`: Saves the specified resource instance `inst` by overwriting all properties.
* `Resource.create(properties, [callback])`: Creates a new instance of the Resource with the specified `properties`.
* `Resource.new(properties)`: Instantiates a new instance of the Resource with the `properties`.

## Resource Instance Methods

* `Resource.prototype.save([callback])`
* `Resource.prototype.update(properties, [callback])`
* `Resource.prototype.destroy([callback])`
* `Resource.prototype.reload([callback])`

## Relationship Constructor Methods
These methods are available on all user-defined resource constructors which are in a relationship

* `Parent.children(id, [callback])`: Fetches all the children for the specified `id`.
* `Parent.createChild(id, properties, [callback])`: Create a child for `id` with the specified `properties`.
{'fraction_non_alphanumeric': 0.13492766459994096, 'fraction_numerical': 0.0, 'mean_word_length': 5.059928443649373, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3537174', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1904, 'n_words': 582}