Comments (8)
That's an interesting idea. How exactly are you looking to leverage that sort of think in your project.
I'm not entirely sure if it's possible as I've never tried it but it would require multiple instantiations of the Sequelize object, and store them to be accessed later. It would also need to discover specific sets of models for each instance, which could theoretically be done.
Perhaps the connect method could be passed in a set of named connections that included discovery locations, store the sequelize instances and the models in a named hashes corresponding to each instance.
from sequelize-singleton.
Some thing like this... https://github.com/urosjarc/sequelizeRealms.js
But this really basic idea
from sequelize-singleton.
Hmmm, it might've been easier to fork this project so that I could see your work over top of it.
Something like that looks like it could work, however I don't see the need for a competing project. I think multiple DB connections could be added to this project and still be BC for people who wanted multiple. But you're welcome to maintain your own project if you want.
from sequelize-singleton.
I'm not sure if this would work at all, as I haven't tested it. But this is along the lines of what I would recommend.
from sequelize-singleton.
Yea I'm sorry I didn't know if I want to fork it or not, because I have intention to pimp this project of yours and youst in case I copy your project and add fast modification, but I have intention to contribute to your repo. Give me some days that I will find some time to fully work on it.
from sequelize-singleton.
Also, I'm moving this package to sequelize-connect.
I just released the 1.0 version which now loads models asynchronously and returns a bluebird promise. I'm going to move you're feature request into that repo.
from sequelize-singleton.
Nice move with the bluebird lib, this is the best promise lib.
Any way let me say what features that I need.
I work on api that must connect to the multiple databases with the same models. I know this is bad practice but anyway. And if the boss tell me: "Hey the models on database xxx will change." This must be easy work. And in the future the api will go to only one database so lib should support this. So my suggestion is like this.
- The current *-singletone lib is ok for one database.
- If you want to connect to multiple databases you should define models path, and on next database connection if you don't change the models path the second database should copy models from the first one. (Lib should have high performance with this). I suggest that you make variable on which file extensions you want to be models discover. The curent word is : *.models.js which should be configurable on every models path change.
- You should have access to the databases by hash map like: db["dbName"] where you define connection name. If only one database is connected it should be accessable joust like one in singletone: db.models .... And from the hash map db["main"].models. So if one is ussing multiple connections and then changes his mind he can do little changes to the code by setting key in db to main and no question is asked.
I would do this changes to my version of your lib, but hey if you want to take over we can make seq.-connect lib very sweet candy treat for other developers.
from sequelize-singleton.
Oh and one more thing... try to use ES6 on the source files (one class on file) and compile files with babel.js which will be the source of the npm package source. With this you will achive the OOP and compability with older node-es. Pls no hard feelings but your code is messy.
Demo:
http://book.mixu.net/node/ch6.html
Code:
"use strict";
class Test {
constructor(){
this.name = "Name";
}
getName(){
return this.name;
}
Static class: On require module returns same object every time.
module.exports = new Class();
Usage:
var Test = require('./test');
Test.getName();
Non static class: On require module returns same class every time.
module.exports = Class;
Usage:
var Test = require('./test');
var test = new Test();
test.getName();
from sequelize-singleton.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sequelize-singleton.