forked from status-20X/stylusdb-sql-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from status-20X/main
Feedback
- Loading branch information
Showing
30 changed files
with
2,770 additions
and
609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
student_id,course | ||
1,Mathematics | ||
1,Physics | ||
2,Chemistry | ||
3,Mathematics | ||
5,Biology | ||
5,Physics |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env node | ||
|
||
const readline = require('readline'); | ||
const { executeSELECTQuery, executeINSERTQuery, executeDELETEQuery } = require('./queryExecutor'); | ||
|
||
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 { | ||
// Execute the query - do your own implementation | ||
|
||
switch (true) { | ||
case line.toLowerCase().startsWith('select'): | ||
executeSELECTQuery(line) | ||
.then(result => console.log('Result:', result)) | ||
.catch(err => console.error(err)); | ||
break; | ||
case line.toLowerCase().startsWith('insert into'): | ||
executeINSERTQuery(line) | ||
.then(result => console.log(result.message)) | ||
.catch(err => console.error(err)); | ||
break; | ||
case line.toLowerCase().startsWith('delete from'): | ||
executeDELETEQuery(line) | ||
.then(result => console.log(result.message)) | ||
.catch(err => console.error(err)); | ||
break; | ||
default: | ||
console.log('Unsupported command'); | ||
} | ||
} catch (error) { | ||
console.error('Error:', error.message); | ||
} | ||
|
||
rl.prompt(); | ||
}).on('close', () => { | ||
console.log('Exiting SQL CLI'); | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const fs = require('fs'); | ||
const csv = require('csv-parser'); | ||
const { parse } = require('json2csv'); | ||
|
||
function readCSV(filePath) { | ||
const results = []; | ||
|
||
return new Promise((resolve, reject) => { | ||
fs.createReadStream(filePath) | ||
.pipe(csv()) | ||
.on('data', (data) => results.push(data)) | ||
.on('end', () => { | ||
resolve(results); | ||
}) | ||
.on('error', (error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
async function writeCSV(filename, data) { | ||
const csv = parse(data); | ||
fs.writeFileSync(filename, csv); | ||
} | ||
|
||
module.exports = {readCSV,writeCSV}; |
Oops, something went wrong.