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

related-nested-set

v2.1.2

Published

Nested set implementation for the ee-orm package

Downloads

3

Readme

Related ORM Nested Set Extension

Nested Sets for the Related ORM.

  • Inserts, updates, deletes nested set nodes
  • Support for multiple root nodes and multiple trees per table
  • Works on any property names
  • Prevents nodes with child nodes from being deleted

npm Travis node

API

Importing and loading

Import

var   ORM 		= require('related')
	, NestedSet = require('related-nested-set');

Load the ORM

var orm = new ORM(dbConfig);

Load the extension using the default settings, the columns have the name left and right. The table contains one tree only.

orm.use(new NestedSet());

Load using custom column names

orm.use(new NestedSet({
	  left: 'lft'
	, right: 'rgt'
}));

Load for a table containing multiple tree grouped by a column

// myDB is the name of the db containing nested set table
// myTable is the table containing the nested set
orm.use(new NestedSet({
	myDB: {
		myTable: 'groupingColumn'
	}
}));

You may also set the grouping key afterwards

var nestedSet = new NestedSet();

// add to orm
orm.use(nestedSet);

// when the orm is loaded everything should be ready
orm.load(function(err) {

	// add grouping
	nestedSet.setGroupKey(databaseName, modelName, keyName);
});

loadTree method

Load a tree from a table which has only one tree stored in it

orm.myDB.myTable().loadTree(function(err, tree){});

Load a tree with the id 234 from a table which has multiple trees stored in it

orm.myDB.myTable().loadTree(234, function(err, tree){});

querybuilder.loadTree(callback);

setParent method

model.setParent([primary key value | model instance | query builder], [as last child]);

This method can be called on any model instance of a nested set. It sets a new parentnode for the current node.

// load a node from the table
orm.tree({id:4}).findOne(function(err, node){

	// set as a new root node
	node.setParent();


	// set as child of another parent, using its the parent nodes id as reference
	node.setParent(45);


	// set as child of another model instance
	node.setParent(modelInstance);


	// set as last child of a node found using a query, set as last child
	node.setParent(orm.db.tree({name: 'charlie'}), true);


	// save changes
	node.save(function(err) {

	});
});

after method

model.after(primary key value | model instance | query builder);

Positions this model after another model on the same level

// load a node from the table
orm.tree({id:4}).findOne(function(err, node){

	// store after the node with the id 45
	node.after(45);


	// store after the modelInstance
	node.after(modelInstance);


	// store after the node with the name «charlie»
	node.after(orm.db.tree({name: 'charlie'}), true);


	// save changes
	node.save(function(err) {

	});
});

before method

model.before(primary key value | model instance | query builder);

Positions this model before another model on the same level

// load a node from the table
orm.tree({id:4}).findOne(function(err, node){

	// store before the node with the id 45
	node.before(45);


	// store before the modelInstanc

e node.before(modelInstance);

	// store before the node with the name «charlie»
	node.before(orm.db.tree({name: 'charlie'}), true);


	// save changes
	node.save(function(err) {

	});
});