# sequelize-autoload

> Autoloader for SequelizeJS, inspired by PSR-0 and PSR-4.

Latest version **1.0.0** (published 2018-02-27) · MIT license · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2018-02-27 |
| First published | 2018-02-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 48 KB |
| Known vulnerabilities | 0 (+12 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Alex Fang |
| Maintainers | boxsnake |
| Keywords | sequelize, database, autoload, autoloader, models, entities |

## Links

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

## Dependencies (7)

- [pg](https://npm.io/package/pg.md) ^7.4.1
- [mysql2](https://npm.io/package/mysql2.md) ^1.5.2
- [sqlite3](https://npm.io/package/sqlite3.md) ^3.1.13
- [tedious](https://npm.io/package/tedious.md) ^2.3.1
- [pg-hstore](https://npm.io/package/pg-hstore.md) ^2.3.2
- [sequelize](https://npm.io/package/sequelize.md) ^4.34.0
- [object.pick](https://npm.io/package/object.pick.md) ^1.3.0

## Alternatives

- [@libsql/sqlite3](https://npm.io/package/@libsql/sqlite3.md) — 39.8K weekly downloads
- [@fortemi/core](https://npm.io/package/@fortemi/core.md) — 461 weekly downloads
- [cdb-converter](https://npm.io/package/cdb-converter.md) — 341 weekly downloads
- [@uplo/adapter-prisma](https://npm.io/package/@uplo/adapter-prisma.md) — 75 weekly downloads
- [typeorm-aios](https://npm.io/package/typeorm-aios.md) — 30 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-02-27

## README

[![][badge-version-npm]][npm-sequelize-autoload] [![][badge-version-node]][npm-sequelize-autoload] [![][badge-version-sequelize]][npm-sequelize] [![][badge-github-release]][github-sequelize-autoload-release] [![][badge-downloads-npm-month]][npm-sequelize-autoload] [![][badge-license]][npm-sequelize-autoload] [![][badge-commitizen-friendly]][github-commitizen] [![][badge-semantic-release]][github-semantic-release] [![][badge-gitter]][gitter]

An autoloader for [Sequelize][github-sequelize], inspired by [PSR-0][psr-0] and [PSR-4][psr-4].

## Installation
```bash
npm install --save sequelize-autoload
```

## Usage
```javascript
const db = require('sequelize-autoload');
db.load('/path/to/config');
```

To generate sequelize models files:
> See [sequelize-auto][npm-sequelize-auto] package.

To make a config file:
> See [Config File](#config-file) section.

To get a Sequelize table instance:
```javascript
db.models.model_name
```

**Notes:**

1. `db.load()` reads config, but does not load table(s) immediately.
2. Tables are loaded when they are called.
3. **Only** uninitialized table(s) will be loaded, otherwise existing table instance(s) will be returned.
4. `db.load()` can be called more than once, which will reload the config and clear all existing table instance(s).

## Config File
Generally, the config file is a JSON separate from your main JS script. It contains database, tables and Sequelize-specific configurations. It looks like:
```json
{
    "server": {
        "dialect": "mysql",
        "host": "localhost",
        "database": "test",
        "username": "username",
        "password": "password",
        "define": {}
    },
    "models": {
        "root": "../models"
    }
}
```

| Field Name        | Type   | Optional         | Description                                                           |
|-------------------|:------:|:----------------:|-----------------------------------------------------------------------|
| `server.dialect`  | String | ![no][icon-no]   | Sequelize ORM dialect, see [here][doc-sequelize-example-usage].       |
| `server.host`     | String | ![no][icon-no]   | Database host.                                                        |
| `server.database` | String | ![no][icon-no]   | Database name.                                                        |
| `server.username` | String | ![no][icon-no]   | Database connection username.                                         |
| `server.password` | String | ![no][icon-no]   | Database connection password.                                         |
| `server.define`   | Object | ![yes][icon-yes] | Sequelize global define, see [here][doc-sequelize-options].           |
| `models.root`     | String | ![yes][icon-yes] | Path where [generated scripts](#usage) (by `sequelize-auto`) located. |

**Notes:**
1. If `models.root` is a relative path, it describes the path related to the config JSON file.

## License
MIT

[badge-version-npm]: https://img.shields.io/npm/v/sequelize-autoload.svg "Sequelize Autoload"
[badge-version-node]: https://img.shields.io/node/v/sequelize-autoload.svg "Sequelize Autoload"
[badge-version-sequelize]: https://img.shields.io/badge/Sequelize-%3E%3D4.0.0-orange.svg "Sequelize"
[badge-downloads-npm-month]: https://img.shields.io/npm/dm/sequelize-autoload.svg "Sequelize Autoload downloads"
[badge-github-release]: https://img.shields.io/github/release/boxsnake-nodejs/sequelize-autoload.svg "Sequelize Autoload latest release"
[badge-license]: https://img.shields.io/npm/l/sequelize-autoload.svg "License"
[badge-commitizen-friendly]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg "Commitizen friendly"
[badge-semantic-release]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg "semantic-release"
[badge-gitter]: https://img.shields.io/gitter/room/nwjs/nw.js.svg?logo=gitter-white "gitter"

[icon-yes]: https://raw.githubusercontent.com/boxsnake-nodejs/sequelize-autoload/master/images/icon-yes.png
[icon-no]: https://raw.githubusercontent.com/boxsnake-nodejs/sequelize-autoload/master/images/icon-no.png

[psr-0]: https://www.php-fig.org/psr/psr-0/ "PSR 0: Autoloading Standard"
[psr-4]: https://www.php-fig.org/psr/psr-4/ "PSR 4: Autoloader"
[github-sequelize]: https://github.com/sequelize/sequelize "Sequelize"
[github-sequelize-autoload-release]: https://github.com/boxsnake-nodejs/sequelize-autoload/releases/latest "Sequelize-autoload Release"
[github-commitizen]: http://commitizen.github.io/cz-cli/ "Commitizen friendly"
[github-semantic-release]: https://github.com/semantic-release/semantic-release "Semantic Release"
[github-semantic-release-node-version-requirement]: https://github.com/semantic-release/semantic-release/blob/caribou/docs/support/node-version.md#node-version-requirement "Semantic Release - Node version requirement"
[npm-sequelize]: https://www.npmjs.com/package/sequelize "Sequelize"
[npm-sequelize-auto]: https://www.npmjs.com/package/sequelize-auto "Sequelize-auto"
[npm-sequelize-autoload]: https://www.npmjs.com/package/sequelize-autoload "Sequelize-autoload"
[doc-sequelize-example-usage]: http://docs.sequelizejs.com/#example-usage "Sequelize - Example Usage"
[doc-sequelize-options]: http://docs.sequelizejs.com/manual/installation/usage.html#options "Sequelize - Options"
[gitter]: https://gitter.im/boxsnake/sequelize-autoload?utm_source=share-link&utm_medium=link&utm_campaign=share-link "Gitter - boxsnake/sequelize-autoload"

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