Skip to content

Commit befbad2

Browse files
committed
Clean up
1 parent 94638c9 commit befbad2

File tree

7 files changed

+27
-52
lines changed

7 files changed

+27
-52
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ This repository will walk you through the process of quickly getting started wit
77
* [Node.js](https://nodejs.org/en/download/)
88
* [MariaDB](https://mariadb.com) - to get started with MariaDB check out [this guide](https://github.com/mariadb-developers/mariadb-getting-started)!
99

10+
You can easily run a MariaDB Server using Docker:
11+
12+
```Shell
13+
docker run --name mariadb --detach --publish 3306:3306 --env MARIADB_ROOT_PASSWORD='RootPassword123!' mariadb
14+
```
15+
1016
## Samples
1117

1218
### JavaScript
1319

1420
The [javascript](javascript) folder provides simple examples using MariaDB Connector/Node.js with JavaScript.
1521

1622
* [Connecting to MariaDB](javascript/connect)
17-
* [connection.js](javascript/connect/connection.js) - a simple example of connecting to a MariaDB database instance.
18-
* [connection_skysql.js](javascript/connect/connection_skysql.js) - a simple example of how to connect to [MariaDB SkySQL](https://mariadb/com/skyview)
23+
* [connection.js](javascript/connect/connection.js) - a simple example of connecting to a MariaDB database instance. Change the connection parameters (host, port, user, password) in the same file before running the example.
1924

2025
* [Execute querying operations](javascript/query)
2126

22-
Examples that utilize a shared [database module](javascript/query/db.js) to perform various SQL operations.
27+
Examples that utilize a shared [database module](javascript/query/db.js) to perform various SQL operations. Change the connection parameters (host, port, user, password) in the database module file before running the examples.
2328

2429
* [Create a database and table](javascript/query/create.js) - **required** before executing any other script
2530
* [Drop a database](javascript/query/drop.js)

javascript/connect/connection.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ async function asyncFunction() {
55
try {
66
// Create a new connection
77
conn = await mariadb.createConnection({
8-
host: '<insert_host_address_here>',
9-
port: '<insert_port_number_here>',
10-
user: '<insert_user_here>',
11-
password: '<insert_password_here>',
8+
host: '127.0.0.1',
9+
port: '3306',
10+
user: 'user',
11+
password: 'Password123!',
1212
});
1313

1414
// Print connection thread

javascript/connect/connection_skysql.js

-35
This file was deleted.

javascript/query/create.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ async function asyncFunction() {
77
conn = await db.pool.getConnection();
88

99
// Execute query to create a new database
10-
await conn.query("CREATE DATABASE demo");
10+
await conn.query("CREATE DATABASE IF NOT EXISTS demo");
1111
console.log("Demo database created.");
1212

1313
// Execute query to create a new table
14-
await conn.query("CREATE TABLE demo.contacts ( \
14+
await conn.query("CREATE TABLE IF NOT EXISTS demo.contacts ( \
1515
id INT(11) unsigned NOT NULL AUTO_INCREMENT, \
1616
first_name VARCHAR(50) NOT NULL, \
1717
last_name VARCHAR(50) NOT NULL, \
@@ -24,6 +24,7 @@ async function asyncFunction() {
2424
} finally {
2525
// Release the connection back into the connection pool
2626
if (conn) await conn.release();
27+
db.pool.end();
2728
}
2829
}
2930

javascript/query/db.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const mariadb = require('mariadb');
22

33
// Expose the Pool object within this module
44
module.exports = Object.freeze({
5-
pool: mariadb.createPool({
6-
host: '<insert_host_address_here>',
7-
port: '<insert_port_number_here>',
8-
user: '<insert_user_here>',
9-
password: '<insert_password_here>'
10-
})
5+
pool: mariadb.createPool({
6+
host: '127.0.0.1',
7+
port: '3306',
8+
user: 'user',
9+
password: 'Password123!'
10+
})
1111
});

javascript/query/insert.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ async function asyncFunction() {
1818
} catch (err) {
1919
// Print errors
2020
console.log(err);
21-
}
21+
} finally {
22+
db.pool.end();
23+
}
2224
}
2325

2426
asyncFunction();

javascript/query/select.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ async function asyncFunction() {
1212
} catch (err) {
1313
// Print errors
1414
console.log(err);
15-
}
15+
} finally {
16+
db.pool.end();
17+
}
1618
}
1719

1820
asyncFunction();

0 commit comments

Comments
 (0)