Data access is something Node.js is very well known for. When it comes to drivers, there’s support for nearly every database under the sun. These days however, in most cases you use an ORM library instead of a plain driver. It saves you time and you don’t have to write every single thing youself.
There are database specific ORM libraries such as Mongoose for MongoDB and Sequelize for MySQL and PostgreSQL. The downside to this approach is that you have to learn a whole new API when you have to go from one database to another. I’m not suggesting it’s a good idea to switch or use different databases during a lifecycle of a single project (eg SQLite for development and MySQL for production). But going from project to project, client to client, your requirements might change and you will have to use a different database and then learn a whole new API. Fun? Yes! But if you have to delivery features quickly, this might be a setback.
JugglingDB by Anatoliy Chakkaev is a young ORM library that tries to provide a single API for a vast array of databases. All adapters come in a form of separate modules and there are quite a few already available:
Lets check it out!
Here’s the cool part, if you want to use a different database, all you have to do is change how your schema connects:
What’s even cooler, is that you can have multiple schemas connecting to multiple databases at the same time. This could be very handy if for example you want to keep some cached data in Redis, which storing your loosly defined documents in MongoDB and your accounting stuff in MySQL. You could do all that with a single API.
1602/jugglingdb is not as well known as Mongoose, but it’s been in development since 2011 and has a pretty strong following on GitHub. Documentation is pretty extensive and roadmap gives you a glimpse of where the project is headed and what is currently considered missing. Finally, check out source code for this article on GitHub and an interactive example on Runnable. I’ve included MongoDB, Redis and Memory examples.