Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

A simple collection wrapper for the FeedHenry Database API

Notifications You must be signed in to change notification settings

feedhenry-staff/fhdb-collection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fh-db Collection

Simple wrapper around the $fh.db API to allow the creation of Collection wrappers with high level methods attached.

Example Usage

Create a Collection wrapper.

var Collection = require('fhdb-collection'),
	util = require('util');

function People () {
	Collection.call(this, 'People');
}
util.inherits(People, Collection);

People.prototype.customMethod = function () {
	// Do something!
};

module.exports = new People('people');

Use it with the inherited methods!

var People = require('./People');

People.create({
	name: 'john',
	age: '23'
}, function (err, res) {
	// Receives the usual fh-db callback results
});

Class Functions

Any class that inherits from this receives the following functions. Which correspond to $fh.db functions.

  • create (data, callback)
  • update (guid, data, callback)
  • read (guid, callback)
  • remove (guid, callback)
  • truncate (callback)
  • find ([opts,] callback)
  • findOne ([opts,] callback)
  • findBy (property, value, callback)

Contributing

We could make this module more flexible to support models etc so you could do the following:

// Item.js inherits from our Model class
var Item = require('./Item.js');

var i = new Item({
	type: 'car',
	condition: 'great'
});


i.save(function(err) {
	if (err) {
		// It didn't save...
	}
});

About

A simple collection wrapper for the FeedHenry Database API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%