{"id":15011258,"url":"https://github.com/fremail/sequelize-nested-set","last_synced_at":"2025-04-09T19:04:46.095Z","repository":{"id":45387322,"uuid":"162041087","full_name":"fremail/sequelize-nested-set","owner":"fremail","description":"Library to store and manage nested set trees using Sequelize","archived":false,"fork":false,"pushed_at":"2023-01-30T13:51:06.000Z","size":111,"stargazers_count":40,"open_issues_count":10,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T21:01:42.347Z","etag":null,"topics":["multi-root-tree","sequelize","tree","trees"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fremail.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-16T21:07:58.000Z","updated_at":"2024-10-29T14:09:29.000Z","dependencies_parsed_at":"2023-02-16T08:01:50.211Z","dependency_job_id":null,"html_url":"https://github.com/fremail/sequelize-nested-set","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fremail%2Fsequelize-nested-set","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fremail%2Fsequelize-nested-set/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fremail%2Fsequelize-nested-set/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fremail%2Fsequelize-nested-set/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fremail","download_url":"https://codeload.github.com/fremail/sequelize-nested-set/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094985,"owners_count":21046770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["multi-root-tree","sequelize","tree","trees"],"created_at":"2024-09-24T19:39:58.212Z","updated_at":"2025-04-09T19:04:46.062Z","avatar_url":"https://github.com/fremail.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sequelize Nested Set\n\n[![NPM Version](https://img.shields.io/npm/v/sequelize-nested-set.svg?style=flat)](https://www.npmjs.com/package/sequelize-nested-set)\n![Min Node Version](https://img.shields.io/node/v/sequelize-nested-set.svg?style=flat)\n[![Build Status](https://travis-ci.com/fremail/sequelize-nested-set.svg?branch=master)](https://travis-ci.com/fremail/sequelize-nested-set)\n[![Code Coverage](https://img.shields.io/codecov/c/github/fremail/sequelize-nested-set.svg?style=flat)](https://codecov.io/gh/fremail/sequelize-nested-set)\n![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/fremail/sequelize-nested-set/package.json.svg?style=flat)\n![License](https://img.shields.io/github/license/fremail/sequelize-nested-set.svg)\n\nLibrary to store and manage nested set trees using [Sequelize](https://github.com/sequelize/sequelize) version 4, 5 or 6! It supports multi-root trees.\n\nFeel free to create an issue or PR if you have a bug or idea.\n\nP.S. Don't forget to star this library. It stimulates me to support [the library](https://github.com/fremail/sequelize-nested-set)! ⭐️\n\nP.P.S. If you feel like you could help me with the library (writing docs, adding new features, testing, fixing bugs or anything else) - you are welcome! If you need any info or have a question, just email me at fremail@yandex.com\n\n## Quick links\n\n* [Installation](#installation)\n* [Getting started](#getting-started)\n* [DB Table structure](#db-table-structure)\n* [Nested Set Options](#nested-set-options)\n* [Docs](https://github.com/fremail/sequelize-nested-set/wiki)\n* [Docs: All functions](https://github.com/fremail/sequelize-nested-set/wiki/All-Methods)\n* [Changelog](CHANGELOG.md)\n* [License (MIT)](LICENSE)\n\n## Installation\n\n```bash\nnpm install --save sequelize-nested-set\n```\n\nPlease note, you have to install [Sequelize](https://github.com/sequelize/sequelize) yourself.\n\n## Getting started\n\nThis library works as a wrapper for `sequelize.define`, it has the same params: model name, attributes (aka table fields), options, but the first 2 params are sequelize connection and DataTypes object.\n\n```javascript\nconst ns = require('sequelize-nested-set');\n\nmodule.exports = (sequelize, DataTypes) =\u003e {\n    const Tag = ns(sequelize, DataTypes, 'Tag', {\n        label: DataTypes.STRING,\n    }, {\n        tableName: 'tag',\n        timestamps: false,\n        hasManyRoots: true,\n    });\n    \n    // add additional methods, associations to the model\n    \n    return Tag;\n};\n```\n\n## DB Table structure\n\nYes, it requires a basic structure of table where you want to keep your tree.\n\nHere are the required fields:\n* `lft` - int, not null. You can use another column name using `lftColumnName` option.\n* `rgt` - int, not null. Use `rgtColumnName` option for custom column name.\n\nIf you want to store a multi-root tree (several trees in other words), you need to set `hasManyRoots` option to `true` and have one more column:\n* `rootId` - column type must be the same with `id` column (default: int, but you can change it using `rootColumnType` option), not null. Default field name is `root_id`, but you can also use your own with `rootColumnName` option.\n\n[Some methods](https://github.com/fremail/sequelize-nested-set/wiki/Heavy-load-methods) of this library require `level` or `parentId` field. If you don't have any of the fields, they will be generated on the fly which may result in high load and slow work. A simple way to optimize this issue is to add one of columns or both:\n* `level` - int, not null. For its name you can also use `levelColumnName` option.\n* `parentId` - primary key column type, nullable. You can use another column name using `parentIdColumnName` option. Don't forget to set correct `parentIdColumnType` if your Primary Key is not an integer.\n\n## Nested Set Options\n\nThere are the options to customize your nested set. All these options are optional.\n* `hasManyRoots` (boolean, default: `false`) - for cases when you want to store several trees in one table.\n* `lftColumnName` (string, default: `lft`) - a column name for lft.\n* `rgtColumnName` (string, default: `rgt`) - a column name for rgt.\n* `levelColumnName` (string, default: `false`) - a column name for level (optional column).\n* `rootColumnName` (string, default: `root_id`) - a column name for rootId. Value of this option makes sense only if `hasManyRoots` is `true`.\n* `rootColumnType` (one of DataTypes.*, default: `DataTypes.INTEGER`) - a column type for rootId. It must be the same column type as the id column. Value of this option makes sense only if `hasManyRoots` is `true`.\n* `parentIdColumnName` (string, default: `false`) - a column type for parentId (optional column).\n* `parentIdColumnType` (one of DataTypes.*, default: `DataTypes.VIRTUAL`) - a column type for parentId. It must be the same column type as the id column.\n\n## API docs\n\nI'm trying to keep all functions good-documented, but if you want more info about the functions with examples etc., please visit API docs in [wiki](https://github.com/fremail/sequelize-nested-set/wiki/All-Methods).\n\n## Upgrading\n\nSee [CHANGELOG.md](CHANGELOG.md) for list of changes and [UPGRADING.md](UPGRADING.md) for guide how to upgrade your code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffremail%2Fsequelize-nested-set","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffremail%2Fsequelize-nested-set","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffremail%2Fsequelize-nested-set/lists"}