Skip to content

Commit 4a096a2

Browse files
authored
Merge pull request #12 from BoolJS/develop
Major refactoring
2 parents e5bbb0f + c5cbca3 commit 4a096a2

File tree

3 files changed

+62
-39
lines changed

3 files changed

+62
-39
lines changed

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,56 @@
1-
# Bool.js - Sequelize Driver
1+
<p align="center"><img src="https://cdn.rawgit.com/BoolJS/booljs/master/logo.svg" width="50%"></p>
22

3-
[![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)
3+
<p align="center">
4+
<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>
5+
<a href="LICENSE.md"><img src="https://img.shields.io/badge/License-GPL%20v3-green.svg?style=flat-square" alt="License"></a>
6+
<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>
7+
<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>
8+
<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>
9+
<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>
10+
<a href="https://codeclimate.com/github/BoolJS/booljs-sequelize/maintainability"><img src="https://api.codeclimate.com/v1/badges/102e5750974935be2b3b/maintainability" /></a>
11+
<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>
12+
<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>
13+
<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>
14+
</p>
415

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

7-
[![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)
20+
`@booljs/sequelize` is a database loader intended to enable developers to use Sequelize in the [BoolJS Framework](http://bool.js.org/).
821

9-
## FAQ
22+
## Install
1023

11-
### What is bool.js?
12-
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.
24+
Install the package using
1325

14-
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.
26+
```
27+
npm install @booljs/sequelize
28+
```
1529

16-
### Can I migrate my projects to bool.js?
17-
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.
30+
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.
1831

19-
### What is this?
20-
`booljs.sequelize` is a driver to enable MySQL users to use `sequelize` library in bool.js
32+
```
33+
npm install sequelize@latest
34+
```
35+
36+
Finally, you might need to get some documentation on the usage of Sequelize. Find it on [their](http://www.sequelize.org) website.
37+
38+
39+
## Usage
40+
41+
First, register the `@booljs/sequelize` module in your BoolJS application. Then, add it to the [database drivers](https://)
42+
43+
In `index.js`, declare:
44+
45+
```js
46+
const Bool = require('booljs');
47+
48+
async function main () {
49+
const API = new Bool('com.example.api', [ '@booljs/sequelize' ]);
50+
.setDatabaseDrivers('booljs.sequelize');
51+
52+
return API.run();
53+
}
54+
55+
module.exports = main();
56+
```

index.js

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

33
const Sequelize = require('sequelize');
4-
const MySQLModel = require('./model');
5-
const { Schema } = MySQLModel;
4+
const SequelizeModel = require('./model');
5+
const { Schema } = SequelizeModel;
66

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

11-
module.exports = class BoolJSMySQL extends DatabaseLoader {
11+
module.exports = class BoolJSSequelize extends DatabaseLoader {
1212
constructor ({ connectionSettingsStoreName = 'sequelize' } = {}) {
1313
super('booljs.sequelize', connectionSettingsStoreName);
1414
}
@@ -69,31 +69,18 @@ module.exports = class BoolJSMySQL extends DatabaseLoader {
6969
this.__associations.push(Component.associations);
7070
}
7171

72-
const readOnly = [ 'constructor', 'name', 'length', 'prototype' ];
72+
BoolJSSequelize.injectProperties(Component, schema);
73+
BoolJSSequelize.injectProperties(Component.prototype, schema.prototype);
7374

74-
const staticsKeys = Object
75-
.getOwnPropertyNames(Component)
76-
.filter(key => Component[key] !== Component.associations &&
77-
!readOnly.includes(key));
78-
79-
for (let key of staticsKeys) {
80-
schema[key] = function (...args) {
81-
return Component[key].apply(this, args);
82-
};
83-
}
84-
85-
const methodsKeys = Object
86-
.getOwnPropertyNames(Component.prototype)
87-
.filter(key => typeof Component.prototype[key] === 'function' &&
88-
!readOnly.includes(key));
75+
return schema;
76+
}
8977

90-
for (let key of methodsKeys) {
91-
schema.prototype[key] = function (...args) {
92-
return Component.prototype[key].apply(this, args);
93-
};
94-
}
78+
static injectProperties (Component, schema) {
79+
const readOnly = [ 'associations', 'constructor', 'name', 'length', 'prototype' ];
9580

96-
return schema;
81+
Object.entries(Object.getOwnPropertyDescriptors(Component))
82+
.filter(([ key ]) => !readOnly.includes(key))
83+
.map(([ key, descriptor ]) => Object.defineProperty(schema, key, descriptor));
9784
}
9885

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

10592
modelClass () {
106-
return MySQLModel;
93+
return SequelizeModel;
10794
}
10895

10996
modelTemplate () {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@booljs/sequelize",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "Sequelize driver for BoolJS",
55
"main": "index.js",
66
"license": "GPL-3.0",

0 commit comments

Comments
 (0)