Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abstract layer for Node.js database

I have been looking around for simple database abstraction implementation, then i found great article http://howtonode.org/express-mongodb, which old but I still like the idea.

Well maybe the construction, could take some kind of object literal with database settings. So the main idea is that there could be different implementations of UserService-s, but locate in different directories and require only the one that's needed.

/data-layer/mongodb/user-service.js
                   /post-service.js
                   /comment-service.js

/data-layer/couchdb/user-service.js
                   /post-service.js
                   /comment-service.js

When the Database is needed, I wil get it with var UserService = require(__dirname + '/data-layer/mongodb/user-service).UserService(db); where var db = "open db object"

Would this be the correct way to do it or is there any better solutions ?

like image 776
Risto Novik Avatar asked Apr 10 '12 15:04

Risto Novik


1 Answers

There are a few solutions, available via NPM :

  • Node-DBI : "Node-DBI is a SQL database abstraction layer library, strongly inspired by the PHP Zend Framework Zend_Db API. It provides unified functions to work with multiple database engines, through Adapters classes. At this time, supported engines are mysql, mysql-libmysqlclient and sqlite3". Looks like the developpment has been paused.
  • Accessor : "A database wrapper, provide easy access to databases." Supports only MySQL and MongoDB at the moment.
  • Activerecord : "An ORM written in Coffeescript that supports multiple database systems (SQL, NoSQL, and even REST), as well as ID generation middleware. It is fully extendable to add new database systems and plugins."
like image 145
magnetik Avatar answered Sep 28 '22 18:09

magnetik