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.
- Loading branch information
1 parent
8ccd37d
commit 157da93
Showing
31 changed files
with
2,126 additions
and
1,199 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"githubPullRequests.ignoredPullRequestBranches": [ | ||
"main" | ||
] | ||
} |
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,6 @@ | ||
student_id,course | ||
1,Mathematics | ||
1,Physics | ||
2,Chemistry | ||
3,Mathematics | ||
5,Biology |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
id,name,age | ||
1,John,30 | ||
2,Jane,25 | ||
3,Bob,22 | ||
3,Bob,22 |
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,46 @@ | ||
#!/usr/bin/env node | ||
|
||
const readline = require("readline"); | ||
const { executeSELECTQuery, executeINSERTQuery,executeDELETEQuery, | ||
} = require("./index"); | ||
|
||
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); | ||
}); |
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 |
---|---|---|
@@ -1,20 +1,33 @@ | ||
|
||
const fs = require("fs"); | ||
const csv = require("csv-parser"); | ||
const { parse } = require("json2csv"); | ||
|
||
function readCSV(filePath) { | ||
const results = []; | ||
|
||
async function readCSV(filePath) { | ||
return new Promise((resolve, reject) => { | ||
const data = []; | ||
fs.createReadStream(filePath) | ||
.pipe(csv()) | ||
.on('data', (data) => results.push(data)) | ||
.on('data', (row) => { | ||
data.push(row); | ||
}) | ||
.on('end', () => { | ||
resolve(results); | ||
resolve(data); | ||
}) | ||
.on('error', (error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
async function writeCSV(filename, data) { | ||
try { | ||
const csvData = parse(data); | ||
fs.writeFileSync(filename, csvData); | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
module.exports = { readCSV, writeCSV }; | ||
|
||
|
||
|
||
module.exports = readCSV; |
Oops, something went wrong.