Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

database-js

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

database-js - npm Package Compare versions

Comparing version 3.0.7 to 3.0.8

4

lib/quoteString.js

@@ -13,2 +13,4 @@ /**

return string.toString();
} else if (string === null) {
return 'null';
}

@@ -24,2 +26,2 @@ string = string.toString();

module.exports = QuoteString;
module.exports = QuoteString;
{
"name": "database-js",
"version": "3.0.7",
"version": "3.0.8",
"description": "Common Database Interface",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,13 +0,9 @@

# Database-js
# database-js
[![Build Status](https://travis-ci.org/mlaanderson/database-js.svg?branch=master)](https://travis-ci.org/mlaanderson/database-js)
[![Build Status](https://travis-ci.org/mlaanderson/database-js.svg?branch=master)](https://travis-ci.org/mlaanderson/database-js)
[![npm version](https://badge.fury.io/js/database-js.svg)](https://badge.fury.io/js/database-js)
[![Mentioned in Awesome Node.js](https://awesome.re/mentioned-badge.svg)](https://github.com/sindresorhus/awesome-nodejs)
* [Install](#install)
* [API](//github.com/mlaanderson/database-js/wiki/API)
* [Examples](//github.com/mlaanderson/database-js/wiki/Examples)
* [Drivers](//github.com/mlaanderson/database-js/wiki/Drivers)
* [In the Browser](//github.com/mlaanderson/database-js/wiki/Browsers)
> Wrapper for multiple databases with a JDBC-like connection
## 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.

@@ -19,17 +15,11 @@

## Drivers
## Contents
Currently available drivers:
- [MySQL](//github.com/mlaanderson/database-js-mysql)
- [PostgreSQL](//github.com/mlaanderson/database-js-postgres)
- [SQLite](//github.com/mlaanderson/database-js-sqlite)
- [ActiveX Data Objects](//github.com/mlaanderson/database-js-adodb)
- [Firebase](//github.com/mlaanderson/database-js-firebase)
- [INI files](//github.com/mlaanderson/database-js-ini)
- [Excel files](//github.com/mlaanderson/database-js-xlsx)
- [CSV files](//github.com/mlaanderson/database-js-csv)
- [JSON files](//github.com/thiagodp/database-js-json)
* [Install](#install)
* [Usage](#usage)
* [Examples](//github.com/mlaanderson/database-js/wiki/Examples)
* [API](//github.com/mlaanderson/database-js/wiki/API)
* [Drivers](//github.com/mlaanderson/database-js/wiki/Drivers)
* [In the Browser](//github.com/mlaanderson/database-js/wiki/Browsers)
[See here](https://github.com/mlaanderson/database-js/wiki/Drivers#implementing-a-new-driver) how to add a new driver.
## Install

@@ -41,86 +31,56 @@

## Usage
## Drivers
### SQLite
```javascript
var Connection = require('database-js').Connection;
Currently available drivers:
- [ActiveX Data Objects](//github.com/mlaanderson/database-js-adodb) - *Windows only*
- [CSV files](//github.com/mlaanderson/database-js-csv)
- [Excel files](//github.com/mlaanderson/database-js-xlsx)
- [Firebase](//github.com/mlaanderson/database-js-firebase)
- [INI files](//github.com/mlaanderson/database-js-ini)
- [JSON files](//github.com/thiagodp/database-js-json)
- [MySQL](//github.com/mlaanderson/database-js-mysql)
- [MS SQL Server](https://github.com/thiagodp/database-js-mssql)
- [PostgreSQL](//github.com/mlaanderson/database-js-postgres)
- [SQLite](//github.com/mlaanderson/database-js-sqlite)
var conn = new Connection("sqlite:///path/to/test.sqlite");
[See here](//github.com/mlaanderson/database-js/wiki/Drivers#implementing-a-new-driver) how to add a new driver.
var statement = conn.prepareStatement("SELECT * FROM states WHERE state = ?");
statement.query("South Dakota").then((results) => {
console.log(results);
conn.close().then(() => {
process.exit(0);
}).catch((reason) => {
console.log(reason);
process.exit(1);
});
}).catch((reason) => {
console.log(reaons);
conn.close().then(() => {
process.exit(0);
}).catch((reason) => {
console.log(reason);
process.exit(1);
});
});
```
## Usage
### MySQL
```javascript
var Connection = require('database-js').Connection;
var conn = new Connection("mysql://user:password@localhost/test");
// 👉 Change the connection URL according to the database you need to connect
var conn =
new Connection("sqlite:///path/to/test.sqlite"); // SQLite
// new Connection("mysql://user:password@localhost/test"); // MySQL
// new Connection("postgres://user:password@localhost/test"); // PostgreSQL
// new Connection( < ANOTHER URL HERE > ); // see the drivers
var statement = conn.prepareStatement("SELECT * FROM states WHERE state = ?");
statement.query("South Dakota").then((results) => {
console.log(results);
conn.close().then(() => {
process.exit(0);
}).catch((reason) => {
console.log(reason);
process.exit(1);
});
}).catch((reason) => {
console.log(reaons);
conn.close().then(() => {
process.exit(0);
}).catch((reason) => {
console.log(reason);
process.exit(1);
});
});
statement.query("South Dakota")
.then((results) => {
console.log(results); // Display the results
conn.close() // Close the database connection
.then(() => {
process.exit(0); // Success!
}).catch((reason) => {
console.log(reason); // Some problem when closing the connection
process.exit(1);
});
}).catch((reason) => {
console.log(reason); // Some problem while performing the query
conn.close() // Close the connection
.then(() => {
process.exit(0); // Success!
}).catch((reason) => {
console.log(reason); // Some problem when closing the connection
process.exit(1);
});
});
```
### PostgreSQL
```javascript
var Connection = require('database-js').Connection;
### Async / await
var conn = new Connection("postgres://user:password@localhost/test");
var statement = conn.prepareStatement("SELECT * FROM states WHERE state = ?");
statement.query("South Dakota").then((results) => {
console.log(results);
conn.close().then(() => {
process.exit(0);
}).catch((reason) => {
console.log(reason);
process.exit(1);
});
}).catch((reason) => {
console.log(reaons);
conn.close().then(() => {
process.exit(0);
}).catch((reason) => {
console.log(reason);
process.exit(1);
});
});
```
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.
Because **database-js** is built on Promises, it works very well with [async/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/async_function). Compare the following code to the code from above. They accomplish the same thing.
```javascript

@@ -131,5 +91,4 @@ var Connection = require('database-js').Connection;

let conn, statement, results;
try {
conn = new Connection("sqlite:///path/to/test.sqlite");
conn = new Connection("sqlite:///path/to/test.sqlite"); // Just change the connection URL for a different database
statement = conn.prepareStatement("SELECT * FROM states WHERE state = ?");

@@ -149,4 +108,8 @@ results = await statement.query("South Dakota");

## See also
[codeceptjs-dbhelper](https://github.com/thiagodp/codeceptjs-dbhelper) - Allows to use [database-js](https://github.com/mlaanderson/database-js) inside [CodeceptJS](https://github.com/codeception/codeceptjs/) to setup tests that access databases.
## License
[MIT](https://github.com/mlaanderson/database-js/blob/master/LICENSE) (c) [mlaanderson](https://github.com/mlaanderson)
[MIT](LICENSE)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc