Skip to content

Commit

Permalink
Updating documentation and README examples using mostly async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
diego Dupin committed Nov 22, 2021
1 parent bc9f6c7 commit 0ec7eea
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 279 deletions.
30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,7 @@ The MariaDB Connector is available through the Node.js repositories. You can in
```
$ npm install mariadb
```

Using ECMAScript < 2017:

```js
const mariadb = require('mariadb');
const pool = mariadb.createPool({host: process.env.DB_HOST, user: process.env.DB_USER, connectionLimit: 5});
pool.getConnection()
.then(conn => {

conn.query("SELECT 1 as val")
.then(rows => { // rows: [ {val: 1}, meta: ... ]
return conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
})
.then(res => { // res: { affectedRows: 1, insertId: 1, warningStatus: 0 }
conn.release(); // release to pool
})
.catch(err => {
conn.release(); // release to pool
})

}).catch(err => {
//not connected
});
```

Using ECMAScript 2017:

example:
```js
const mariadb = require('mariadb');
const pool = mariadb.createPool({host: process.env.DB_HOST, user: process.env.DB_USER, connectionLimit: 5});
Expand All @@ -129,8 +103,6 @@ async function asyncFunction() {
const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
// res: { affectedRows: 1, insertId: 1, warningStatus: 0 }

} catch (err) {
throw err;
} finally {
if (conn) conn.release(); //release to pool
}
Expand Down
Loading

0 comments on commit 0ec7eea

Please sign in to comment.