# sequelize-router

> A restful route generator for Sequelize.

Latest version **1.0.6** (published 2017-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install sequelize-router
pnpm add sequelize-router
yarn add sequelize-router
bun add sequelize-router
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2017-04-13 |
| First published | 2017-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Christian Eckenrode |
| Maintainers | chriseckenrode |
| Keywords | sequelize, router, mysql, express, rest, middleware |

## Links

- npm: https://www.npmjs.com/package/sequelize-router
- Repository: https://github.com/ceckenrode/sequelize-router
- Homepage: https://github.com/ceckenrode/sequelize-router#readme
- Issues: https://github.com/ceckenrode/sequelize-router/issues
- npm.io page: https://npm.io/package/sequelize-router

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2017-04-13
- 1.0.5 — 2017-04-01
- 1.0.2 — 2017-03-20
- 1.0.1 — 2017-03-17
- 1.0.0 — 2017-03-17

## README

# Sequelize Router :sunglasses:

## An easy to use, RESTful route generator designed to work with Sequelize.

[![NPM](https://nodei.co/npm/sequelize-router.png)](https://nodei.co/npm/sequelize-router/)

## Why use Sequelize Router?

* It's tiny (2kb unminified)

* It's easy to use! You can get up and running in about a minute with almost zero configuration.

* It's customizable and extensible. Easily override any of the default route controllers.

## Installation

Available on [npm](https://npmjs.com/package/sequelize-router):

```sh
npm install sequelize-router
```

## Prerequisites

* **sequelize-router** is middleware that runs on top of [sequelize](https://www.npmjs.com/package/sequelize), a popular ORM for node.js applications. Therefore, make sure that you have configured a database prior to use.

* (Optional) Consider using [sequelize-cli](https://github.com/sequelize/cli) to quickly scaffold models of your database to be used for even quicker deployement:
```sh
$ npm install --save-dev sequelize-cli
$ npm install --save sequelize
$ sequelize init:config init:models
```

## Usage

```js
var express = require('express');
// Require the sequelize-router middleware and any models to be used
var sequelizeRouter = require('sequelize-router');
var db = require('./models');

var app = express();
// Use the sequelize-router middleware as shown below
app.use('/api', sequelizeRouter(db.Inventory)); 
app.use('/api', sequelizeRouter(db.Store));
app.use('/api', sequelizeRouter(db.Transaction));
```

### That's literally it. :boom: Restful API Routes are now created for three models.

* In the example above, RESTful API routes are being created for the `Inventory`, `Store` and `Transaction` models. Model names are lowercased and used to construct endpoints.

### API Documentation 

| HTTP method         | URL                                                         | Description                     |
| :-------------:     | -------------------------------------------                 | ------------------------------- |
| **`GET`**           |  `/api/inventory`                                           | Runs a `findAll` query on the inventory table, additionally filterable with optional query parameters. <br> *e.g. `/api/inventory?stock%5Blte%5D=50` **or** `/api/inventory?category=home_improvement` |
| **`GET`**           |  `/api/inventory/:id`                                           | Runs a `findOne` query on the inventory table and retrieves one record with the id specified in `req.params.id`. |
| **`POST`**          |  `/api/inventory/`                                          | Runs a `create` query on the inventory table, using data passed in req.body to construct the new record. |
| **`PUT`**           | `/api/inventory/:id`                                        | Runs an `update` query on the inventory table, using data passed in `req.body` to update the record with the `id` specified in `req.params.id`. By default, query parameters are ignored.|
|**`DELETE`**            | `/api/inventory/:id`                                        | Runs an `destroy` query on the inventory table, using data passed in `req.body` to update the record with the `id` specified in `req.params.id`. By default, query parameters are ignored. |

  ## Defaults

  * By default, each endpoint responds with the data retrieved from the Sequelize query, or from the error returned.

  * Defaults are can be easily overridden for any model's methods by passing a configuration object into the `sequelize-router` middleware. Further documentation on this to come.

  ## Authors

  Christian Eckenrode

  ## Contributors
  
  * [Alan Chu](https://github.com/thechutrain)
  
  * [Ray McCann](https://github.com/rmcc3)

---
_Source: https://npm.io/package/sequelize-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
