-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with multi-database libs: sequelize #345
Comments
Without using a multi-db manager, it seems to work great: const { Database } = require('sqlite3')
const db = new Database(process.env.DATABASE_URI.replace(/^sqlite:\/\//, ''))
const query = q => new Promise((resolve, reject) => db.all(q, (err, rows) => err ? reject(err) : resolve(rows)))
const run = async () => {
const r = await query('SELECT 1+1 AS result')
console.log(r[0].result)
}
run() and creates a atomic dist folder that looks like this:
While this is great, I'd really like the flexibility of using multiple databases. |
Hi @konsumer thanks for the bug report! There is a lot here so maybe we can isolate it to one specific issue.
What is a multi-db manager? You might also be interested in these related issues to DBs: https://github.com/zeit/now-builders/issues/331#issuecomment-479034684 https://github.com/zeit/now-builders/issues/335#issuecomment-480009057 |
I tested with sequelize and any-db. What I mean is a lib that lets you use multiple databases with the same code. I would call it an ORM, but any-db isn't an ORM, just a lib that lets you talk to multiple SQL databases with the same code. For further testing I tried knex, and it seemed to work ok, so for my use-case I might just use that.
Thanks! Link 1: Since the code works fine compiled in ncc, directly, as long as it's in the same dir that has node_modules, but not if not, I think it's a problem with ncc or how now is bundling node_modules. The linked issue is about setting up other things (AWS credentials for RDS) but my example literally just opens a sqlite file in /tmp and does Link 2: This is getting closer to my issue, I think, in that the mongodb-person is saying "mark it as an external module" which ncc is definitely doing automatically with sqlite3 (again, compiled code works fine in same project that has sqlite installed in node_modules, but not if you take the compiled dir out of that folder.) Again, this points to now's method of dealing with node_modules or how ncc bundles the deps. Since someone from the now team said to report it here, I am doing that. |
Have you tried adding See my comment here: https://github.com/zeit/now-builders/issues/331#issuecomment-478679523 |
Yeh, this was my first idea, to prime the dependency-tree. I get
I combined both suggestions, and got the same error. |
Also, you might try creating separate |
That works. Awesome! If you want to test out more ideas, feel free to use my demo repo as it has a few permutations that illustrate the problem.
A big part of my reason for wanting to use now in my situation, is that it simplifies a single host with multiple lambda mount-points. If I can't have that sort of setup, I see little advantage over serverless. I mean, I can even do that with serverless, it just takes a little more configuration. up also does separate individual endpoints simply, and doesn't have this problem. This node-server solution seems like an OK middleground, even though I'm not getting the improved bundle-sizes, or the other advantages of @now/node, but I can mix the one service that needs a database in with others that don't need it, so I can totally live with that. Thanks! |
Just had a quick look at this one, and it seems the untraceable dynamic require is in https://github.com/sequelize/sequelize/blob/7445423b9effc212e125d76d58e02713e808ffc6/lib/dialects/abstract/connection-manager.js#L69. Configuring |
@guybedford thanks for taking a look. That's a great tip for working around dynamic modules in ncc. I ended up just using knex on now, which seems to work great with |
@guybedford Can we implement a workaround to get There are other reports of a similar issue when using |
The workaround here is to pass the dialect to the Sequelize initialization itself. So instead of having: let db = new Sequelize({
dialect: 'pg'
}); You would do: let db = new Sequelize({
dialect: 'pg',
dialectModule: require('pg')
}); where that then avoids the internal dynamic require which would just do |
I can confirm this is still issue with the current version and sequelize v5. Adding |
Similarly, I can confirm that adding dialectModule: require('sqlite3') worked for me. |
I'm having the same issue, but my dialect has always been |
@aecorredor you should be able to do it with this: const db = new Sequelize({
dialect: 'postgres',
dialectModule: require('pg-native')
}); |
And |
need to import also library |
what does this mean? i tried adding
or
neither seems to fix the issue |
I am having trouble using any multi-database wrappers (tried sequelize and any-db) with ncc.
Let's take, for example, a URI like
sqlite:///tmp/demo.sqlite
, which works fine locally in an express service. If I compile with ncc, it runs fine if the output is in the same dir (where sqlite3 is installed.)Here is me troubleshooting with now.sh.
Here is a demo-repo that illustrates the problem. If I deploy or build locally but move the folder out of the project that has sqlite3 installed, it exhibits the problems above.
To reproduce:
Might be related to #74
The text was updated successfully, but these errors were encountered: