This repository will walk you through the process of quickly getting started with Node.js and MariaDB using the MariaDB Node.js connector.
- Node.js
- MariaDB - to get started with MariaDB check out this guide!
You can easily run a MariaDB Server using Docker:
docker run --name mariadb --detach --publish 3306:3306 --env MARIADB_ROOT_PASSWORD='RootPassword123!' mariadb
The javascript folder provides simple examples using MariaDB Connector/Node.js with JavaScript.
-
- 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.
-
Examples that utilize a shared database module to perform various SQL operations. Change the connection parameters (host, port, user, password) in the database module file before running the examples.
- Create a database and table - required before executing any other script
- Drop a database
- Insert records into a table
- Read records from a table
- Update a record in a table
- Delete a record from a table
- Bulk insert - uses the Connection object Batch function
- Bulk insert - uses the Connection Pool object Batch function
First, clone this repo.
$ git clone https://github.com/mariadb-developers/nodejs-quickstart.git
Next, from within the nodejs-quickstart
directory (that you just pulled down), install the MariaDB Node.js driver (connector) using npm.
$ npm install mariadb
Finally, to execute the sample JavaScript files using the node
CLI command.
Note: Be sure to update the connection configuration to point to your database in the JavaScript sample files. For example, here.
$ node javascript/connect/connection.js
$ node javascript/query/create.js
$ node javascript/query/insert.js
$ node javascript/query/select.js
... check additional scripts in the javascript/query/ directory ...
Please feel free to submit PR's, issues or requests to this project directly.
If you have any other questions, comments, or looking for more information on MariaDB please check out:
Or reach out to us directly via: