You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[In the Browser](//github.com/mlaanderson/database-js/wiki/Browsers)
12
-
13
-
## About
7
+
> Wrapper for multiple databases with a JDBC-like connection
14
8
15
9
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.
16
10
17
11
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.
18
12
19
13
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.
// new Connection("mysql://user:password@localhost/test"); // MySQL
51
54
// new Connection("postgres://user:password@localhost/test"); // PostgreSQL
52
-
//another database here (see the drivers)
55
+
//new Connection( < ANOTHER URL HERE > ); // see the drivers
53
56
54
57
var statement =conn.prepareStatement("SELECT * FROM states WHERE state = ?");
55
58
statement.query("South Dakota")
@@ -77,6 +80,7 @@ statement.query("South Dakota")
77
80
```
78
81
79
82
### Async / await
83
+
80
84
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.
81
85
```javascript
82
86
var Connection =require('database-js').Connection;
0 commit comments