-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (37 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const readline = require('readline');
const executeQuery = require('./src/wrapper');
// Create readline interface
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function promptInput() {
rl.question('> ', input => {
if (input) {
if (input === null || input.trim() === ''){
console.log("Please provide a valid input");
promptInput();
}
else{
let query = input.trim();
executeQuery(query).then(_ => promptInput()).catch( err => {
if (typeof err === 'string') console.log(`Error: ${err}`);
else console.log("Error: Invalid query");
promptInput();
});
}
} else {
// Exit if no input is provided (Ctrl+D)
console.log('Exiting...');
rl.close();
}
});
}
// Listen for escape key
rl.on('SIGINT', () => {
console.log('Exiting...');
rl.close();
});
console.log("Kaizer-db Copyright 2024 (MIT License)\nDeveloped by Saptarshi Dey\nEnter input (Press Ctrl+D to exit):");
// Driver Code
promptInput();