Skip to main content

How To Connect

Here is a sample code in different languages to connect with MekaDB and insert records to it.

var mekadb = require('@hypi/mekadb');

let client = new mekadb.Client("", "<db>", "<username>", "<password>");

async function main() {
let createTableRes = await client.query('CREATE TABLE IF NOT EXISTS user(username VARCHAR, pass VARCHAR, PRIMARY KEY (username))');
console.log('Creat table res', createTableRes);
let insertRes = await client.query("INSERT INTO user(username,pass) VALUES('courtney','pass1'),('damion','pass2')")
console.log('Inserted data into table', insertRes);
let rows = await client.query("SELECT * FROM user");
console.log('ROWS:', rows)

let _ = main();

First, the code connects you to database after entering database id, username and password. Copy the credentials from the MekaDB Database screen.

Then in the subsequent lines of code, it creates a table, insert two rows, and then select those two rows using SQL queries.

Click on the below links to check the code repositories for different languages.

Check this SQL guide to frame your own SQL queries!