Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,56 @@
# Bool.js - Sequelize Driver
<p align="center"><img src="https://cdn.rawgit.com/BoolJS/booljs/master/logo.svg" width="50%"></p>

[![Build Status](https://travis-ci.org/BoolJS/booljs-sequelize.svg?branch=master)](https://travis-ci.org/BoolJS/booljs-sequelize) [![Dependencies status for BoolJS](https://david-dm.org/booljs/booljs-sequelize.svg)](https://david-dm.org/booljs/booljs-sequelize) [![devDependency Status](https://david-dm.org/booljs/booljs-sequelize/dev-status.svg)](https://david-dm.org/booljs/booljs-sequelize#info=devDependencies) [![Code Climate](https://codeclimate.com/github/BoolJS/booljs-sequelize/badges/gpa.svg)](https://codeclimate.com/github/BoolJS/booljs-sequelize) [![Inline docs](http://inch-ci.org/github/booljs/booljs-sequelize.svg?branch=master)](http://inch-ci.org/github/booljs/booljs-sequelize)
<p align="center">
<a href="https://travis-ci.org/BoolJS/booljs-sequelize"><img src="https://img.shields.io/travis/BoolJS/booljs-sequelize.svg?style=flat-square" alt="Build Status"></a>
<a href="LICENSE.md"><img src="https://img.shields.io/badge/License-GPL%20v3-green.svg?style=flat-square" alt="License"></a>
<a href="https://github.com/BoolJS/booljs-sequelize/releases"><img src="https://img.shields.io/github/release/BoolJS/booljs-sequelize.svg?style=flat-square" alt="Latest Stable Version"></a>
<a href="https://david-dm.org/booljs/booljs-sequelize"><img src="https://img.shields.io/david/booljs/booljs-sequelize.svg?style=flat-square" alt="Dependency status"></a>
<a href="https://david-dm.org/booljs/booljs-sequelize?type=dev"><img src="https://img.shields.io/david/dev/booljs/booljs-sequelize.svg?style=flat-square" alt="devDependency status"></a>
<a href="https://david-dm.org/booljs/booljs-sequelize?type=peer"><img src="https://img.shields.io/david/peer/booljs/booljs-sequelize.svg?style=flat-square" alt="peerDependency status"></a>
<a href="https://codeclimate.com/github/BoolJS/booljs-sequelize/maintainability"><img src="https://api.codeclimate.com/v1/badges/102e5750974935be2b3b/maintainability" /></a>
<a href="https://codecov.io/gh/BoolJS/booljs"><img src="https://img.shields.io/codecov/c/github/booljs/booljs-sequelize.svg?style=flat-square" alt="Code Coverage"></a>
<a href="http://inch-ci.org/github/booljs/booljs-sequelize"><img src="http://inch-ci.org/github/booljs/booljs-sequelize.svg?branch=master" alt="Inline docs"></a>
<a href="https://gitter.im/BoolJS/booljs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://img.shields.io/gitter/room/booljs/booljs-sequelize.svg?style=flat-square" alt="Join the chat at https://gitter.im/BoolJS/booljs-sequelize"></a>
</p>

[![BoolJS NPM icon](https://nodei.co/npm/@booljs/sequelize.png)](https://npmjs.com/package/@booljs/sequelize)
<p align="center">
<a href="https://npmjs.com/package/@booljs/sequelize"><img src="https://nodei.co/npm/@booljs/sequelize.png" alt="NPM icon"></a>
</p>

[![Join the chat at https://gitter.im/BoolJS/booljs-sequelize](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/BoolJS/booljs-sequelize?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
`@booljs/sequelize` is a database loader intended to enable developers to use Sequelize in the [BoolJS Framework](http://bool.js.org/).

## FAQ
## Install

### What is bool.js?
Bool.js is an MVC Framework. But is not just any other framework; it gives us back the power to choose how to organize a well-designed project, so we can choose our dependencies, craft our architecture, choose our data connectors, and finally, work based on cool development structures without hesitating about learning the framework as is.
Install the package using

Bool.js also reminds the importance of having a cool workspace structure. That's why it's based on namespaces, leading us to focus on our code rather than focusing on managin complicated references to other files in our project.
```
npm install @booljs/sequelize
```

### Can I migrate my projects to bool.js?
Of course you can. Bool.js is Free Software (not as in a *free* beer, but in *free* as a bird). Just remember to update all of your dependencies, arrange your code in the right project structure (we're very tight at that) and finally, use Node LTS, and further versions.
BoolJS Sequelize uses some peerDependencies you must have in your project. We encourage using `npm 6+` in all your projects, because is strict in making you declare them in your project.

### What is this?
`booljs.sequelize` is a driver to enable MySQL users to use `sequelize` library in bool.js
```
npm install sequelize@latest
```

Finally, you might need to get some documentation on the usage of Sequelize. Find it on [their](http://www.sequelize.org) website.


## Usage

First, register the `@booljs/sequelize` module in your BoolJS application. Then, add it to the [database drivers](https://)

In `index.js`, declare:

```js
const Bool = require('booljs');

async function main () {
const API = new Bool('com.example.api', [ '@booljs/sequelize' ]);
.setDatabaseDrivers('booljs.sequelize');

return API.run();
}

module.exports = main();
```
39 changes: 13 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const Sequelize = require('sequelize');
const MySQLModel = require('./model');
const { Schema } = MySQLModel;
const SequelizeModel = require('./model');
const { Schema } = SequelizeModel;

const { DatabaseLoader } = require('@booljs/api');
const { readFileSync } = require('fs');
const { join } = require('path');

module.exports = class BoolJSMySQL extends DatabaseLoader {
module.exports = class BoolJSSequelize extends DatabaseLoader {
constructor ({ connectionSettingsStoreName = 'sequelize' } = {}) {
super('booljs.sequelize', connectionSettingsStoreName);
}
Expand Down Expand Up @@ -69,31 +69,18 @@ module.exports = class BoolJSMySQL extends DatabaseLoader {
this.__associations.push(Component.associations);
}

const readOnly = [ 'constructor', 'name', 'length', 'prototype' ];
BoolJSSequelize.injectProperties(Component, schema);
BoolJSSequelize.injectProperties(Component.prototype, schema.prototype);

const staticsKeys = Object
.getOwnPropertyNames(Component)
.filter(key => Component[key] !== Component.associations &&
!readOnly.includes(key));

for (let key of staticsKeys) {
schema[key] = function (...args) {
return Component[key].apply(this, args);
};
}

const methodsKeys = Object
.getOwnPropertyNames(Component.prototype)
.filter(key => typeof Component.prototype[key] === 'function' &&
!readOnly.includes(key));
return schema;
}

for (let key of methodsKeys) {
schema.prototype[key] = function (...args) {
return Component.prototype[key].apply(this, args);
};
}
static injectProperties (Component, schema) {
const readOnly = [ 'associations', 'constructor', 'name', 'length', 'prototype' ];

return schema;
Object.entries(Object.getOwnPropertyDescriptors(Component))
.filter(([ key ]) => !readOnly.includes(key))
.map(([ key, descriptor ]) => Object.defineProperty(schema, key, descriptor));
}

async afterFetch () {
Expand All @@ -103,7 +90,7 @@ module.exports = class BoolJSMySQL extends DatabaseLoader {
}

modelClass () {
return MySQLModel;
return SequelizeModel;
}

modelTemplate () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@booljs/sequelize",
"version": "0.2.2",
"version": "0.2.3",
"description": "Sequelize driver for BoolJS",
"main": "index.js",
"license": "GPL-3.0",
Expand Down