-
Notifications
You must be signed in to change notification settings - Fork 13
/
cli.js
executable file
·43 lines (36 loc) · 1.22 KB
/
cli.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
42
43
#!/usr/bin/env node
const readline = require('readline');
const { executeSELECTQuery, executeINSERTQuery, executeDELETEQuery } = require('./queryExecuter');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.setPrompt('SQL> ');
console.log('SQL Query Engine CLI. Enter your SQL commands, or type "exit" to quit.');
rl.prompt();
rl.on('line', async (line) => {
if (line.toLowerCase() === 'exit') {
rl.close();
return;
}
try {
if (line.toLowerCase().startsWith('select')) {
const result = await executeSELECTQuery(line);
console.log('Result:', result);
} else if (line.toLowerCase().startsWith('insert into')) {
const result = await executeINSERTQuery(line);
console.log(result.message);
} else if (line.toLowerCase().startsWith('delete from')) {
const result = await executeDELETEQuery(line);
console.log(result.message);
} else {
console.log('Unsupported command');
}
} catch (error) {
console.error('Error:', error.message);
}
rl.prompt();
}).on('close', () => {
console.log('Exiting SQL CLI');
process.exit(0);
});