Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aichholzer/modellr
Database connection manager for Sequelize.
https://github.com/aichholzer/modellr
database-connection database-management database-schemas manager models sequelize
Last synced: 25 days ago
JSON representation
Database connection manager for Sequelize.
- Host: GitHub
- URL: https://github.com/aichholzer/modellr
- Owner: aichholzer
- License: mit
- Created: 2017-10-30T04:06:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-25T01:00:18.000Z (over 2 years ago)
- Last Synced: 2024-03-25T22:46:26.228Z (8 months ago)
- Topics: database-connection, database-management, database-schemas, manager, models, sequelize
- Language: JavaScript
- Size: 195 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - aichholzer/modellr - Database connection manager for Sequelize. (JavaScript)
README
# modellr
[![Greenkeeper badge](https://badges.greenkeeper.io/aichholzer/modellr.svg)](https://greenkeeper.io/)
[![npm version](https://badge.fury.io/js/modellr.svg)](https://badge.fury.io/js/modellr)
[![Build Status](https://travis-ci.org/aichholzer/modellr.svg?branch=master)](https://travis-ci.org/aichholzer/modellr)
[![Downloads](https://img.shields.io/npm/dt/modellr.svg)](https://www.npmjs.com/package/modellr)> Database connection manager for Sequelize.
`modellr` will also load your models and map them to the DB instance, making them available throughout your application.#### Install
```
$> npm i modellr
```#### Basic example
```
const m = require('modellr');
const config = {
database: 'database',
username: 'username',
password: 'password',
dialect: 'postgres',
logging: false
}m.load(config, './models/').then(() => {
// Start your application.
// You have a persisted DB connection.
});
```Have a look at the models in `test/models` to see how they should be defined.
#### Usage
You models are available throughout your application, simply require `modellr` and access whatever model you need.
If, for example, you have a model named `User`, you may use it like so:
```
const m = require('modellr');m.User.findById(123).then((user) => {
// "user" is your record.
});
```All models export the basic Sequelize usage/functionality as documented [here](http://docs.sequelizejs.com/manual/tutorial/models-usage.html).
#### API
`.load(config, models)` : Prepare the DB connections (as Sequelize instance) and load all model definitions. Note that this method will read all model definitions files, thus it should only be called once, at application launch.
`.instance(alias || null)` : Use a particular instance. If the argument is `null` then the first valid instance will be used.
`.close(alias || null)` : Close DB connections and terminate the corresponding Sequelize instance. If the argument is `null` then all open connections will be terminated.
#### Test
```
$> npm test
```#### Contribute
```
fork https://github.com/aichholzer/modellr
```#### License
[MIT](https://github.com/aichholzer/modellr/blob/master/LICENSE)