Skip to content

Latest commit

 

History

History

mariadb

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Connecting JavaScript and MariaDB with ADBC

Instructions

Tip

If you already have a MariaDB instance running, skip the steps to install MariaDB, start it, load data, and stop it.

Prerequisites

  1. Install Node.js (version 22 or later)

    • Alternatively, you can use Bun or Deno
  2. Install dbc

Set up MariaDB

  1. Install Docker

  2. Start a MariaDB instance:

    docker run -d --rm --name some-mariadb -e MARIADB_ROOT_PASSWORD=my-secret-pw -p 3306:3306 mariadb
  3. Create a table in MariaDB and load data into it:

    cat games.sql | docker exec -i some-mariadb mariadb --user=root --password=my-secret-pw

Connect to MariaDB

  1. Install the MariaDB ADBC driver:

    dbc install mariadb
  2. Install dependencies:

    npm --prefix .. install
  3. Customize the script main.js as needed

    • Change the connection arguments in databaseOptions
      • Format uri according to the driver documentation, or keep it as is to use the data included with this example
    • If you changed which database you're connecting to, also change the SQL SELECT statement in conn.query()
  4. Run the script:

    Node.js:

    node main.js

    Bun:

    bun run main.js

    Deno:

    deno run --allow-ffi --allow-env main.js

Clean up

Stop the Docker container running MariaDB:

docker stop some-mariadb