Closed atif089 closed 6 years ago
You should only execute the exported function once per cluster. The rethinkdbdash
instance creates a connection pool for each server in the cluster.
https://github.com/neumino/rethinkdbdash/blob/master/lib/index.js#L556 https://github.com/neumino/rethinkdbdash/blob/master/lib/index.js#L88
If you're only using a single cluster, feel free to set global.r
instead of importing a singleton module every time you need to do a query.
It's better to share the same instance. You want all your modules to share the same pool - it's a bit more stable
Is it a good practice to require a DB driver directly on any module that I want to use or should I create my own module with a singleton connection and keep passing it around.
For example, let's say I have express routes defined in 5 different files. If I run
var r = require('rethinkdbdash')(config.db);
in every file does it mean it will be creating a new pool of connections in each file or does it internally reuse the same connections.