Database-js
DEPRECATED: Database-js2 has claimed the Database-js package name on NPM. This package will continue to get bug fixes, but will not get new features. All new development will be published to the Database-js package.
About
Database-js was started to implement a common, promise-based interface for SQL database access. The concept is to copy the Java pattern of using connection strings to identify the driver. Then provide wrappers around the implemented functionality to commonize the syntax and results.
Thus if SQLite, MySQL and PostgreSQL all have a database named test with a table named states we can access the data the same way.
Database-js has built-in prepared statements, even if the underlying driver does not support them. It is built on Promises, so it works well with ES7 async code.
Drivers
Currently available drivers:
See here how to add a new driver.
Install
npm install database-js2
Usage
SQLite
var Connection = Connection; var conn = "sqlite:///path/to/test.sqlite"; var statement = conn;statement;
MySQL
var Connection = Connection; var conn = "mysql://user:password@localhost/test"; var statement = conn;statement;
PostgreSQL
var Connection = Connection; var conn = "postgres://user:password@localhost/test"; var statement = conn;statement;
Notice that in all three examples, the only difference is the connection URL.
ES7 Compatibility: async
Because database-js is built on Promises, it works very well with ES7 async functions. Compare the following ES7 code to the SQLite code from above. They accomplish the same thing.
var Connection = Connection; { let conn statement results; try conn = "sqlite:///path/to/test.sqlite"; statement = conn; results = await statement; console; catch reason console; finally if conn await conn; process; };
License
MIT (c) mlaanderson