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

genus

v0.2.0

Published

Genus is a simple library for creating Mongo models in Node. It's original inspiration is Sails` modeling, where models are defined in a folder (/models) with a simple JSON syntax. Genus takes the concept further by emphasizing extendability a great deal

Downloads

8

Readme

genus

Genus is a simple library for creating Mongo models in Node. It's original inspiration is Sails` modeling, where models are defined in a folder (/models) with a simple JSON syntax. Genus takes the concept further by emphasizing extendability a great deal more than the original Sails modeling would allow.

Install

Somewhere in your server start

require('genus').init(previouslyEstablishedMongoConnection);

Usage

Register models

module.exports = genus.model('Person', {
	attributes: { // the attributes of the model
		name: {
			type: 'string', // tring, integer, or array
			required: true // is the field required?
		},
		email: {
		  type: 'string'
		},
		age: {
		  type: 'integer',
	  }
	},
	
	// by default every model has count, find, findOne, 
	// save, remove, validate, and clean methods
	
	// you can overwrite one of the default methods
	findOne: function (criteria) {
		return this.super.findOne.call(this, (criteria)).then(function() {
		  // Do something special
		});
	},
	
	// or add a new method
	findOneWithName: function (name) {
		return this.super.find.call(this, {name: name});
	}
});

Assuming I named that model file Person.js, I would now be able to access my model via

var Person = require('models/Person.js');
Person.findOneWithName('john')
  .then(function(personNamedJohn) {
  	personNamedJohn.name = 'Kelly';
  	return Person.save(req.session.userId, personNamedJohn);
  })
  .then(function(personFormerlyKnownAsJohn) {
	// etc
  });

Model default methods

  1. count(criteria) - mongo's count
  2. findOne(id or criteria) - mongo's findOne
  3. find(id or criteria) - mongo's find
  4. save(requestorId, itemToBeSaved) - mongo's update (with upsert true if the model is new)
  5. remove(criteria) - mongo's remove
  6. validate(itemToBeValidated) - validate that a given item fits the model defintion
  7. clean(itemToBeCleaned) - return a new item that contains only defined attributes