This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
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 #9 from factorialco/adding-repl
Adding an interactive repl to run queries
- Loading branch information
Showing
12 changed files
with
397 additions
and
85 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 |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import yargs from 'yargs/yargs' | ||
#!/usr/bin/env node | ||
|
||
import { Command } from 'commander' | ||
import executor from './src/executor' | ||
import startRpl from './src/repl' | ||
|
||
const program = new Command() | ||
|
||
const argv = yargs(process.argv.slice(2)).options({ | ||
query: { type: 'string', demandOption: true } | ||
}).argv | ||
program | ||
.command('query') | ||
.argument('<sql>') | ||
.action((sql: string) => { | ||
const headers = { Cookie: `${process.env.COOKIE}` } | ||
|
||
if (argv.query) { | ||
const headers = { Cookie: `${process.env.COOKIE}` } | ||
executor( | ||
sql, | ||
[], | ||
headers | ||
).then(result => { | ||
console.log(result) | ||
}).catch(error => { | ||
console.log(error) | ||
}) | ||
}) | ||
|
||
executor( | ||
argv.query, | ||
[], | ||
headers | ||
).then(result => { | ||
console.log(result) | ||
}).catch(error => { | ||
console.log(error) | ||
program | ||
.command('interactive') | ||
.action(() => { | ||
console.log('interactive mode') | ||
startRpl() | ||
}) | ||
} | ||
|
||
program.parse() |
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,26 +1,34 @@ | ||
{ | ||
"name": "tentaclesql", | ||
"name": "@factorialco/tentaclesql", | ||
"version": "0.2.3", | ||
"description": "SQL engine from multiple sources", | ||
"bin": { | ||
"tentaclesql": "dist/cli.js" | ||
}, | ||
"main": "dist/src/executor/index.js", | ||
"dependencies": { | ||
"better-sqlite3": "^7.1.5", | ||
"cli-table": "^0.3.6", | ||
"commander": "^8.1.0", | ||
"dd-trace": "^1.1.2", | ||
"fastify": "^3.14.2", | ||
"node-fetch": "^2.6.1", | ||
"pino": "^6.11.3", | ||
"pino-pretty": "^4.7.1", | ||
"sqlite-parser": "^1.0.1", | ||
"yargs": "^16.2.0" | ||
"vorpal": "^1.12.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.13.16", | ||
"@babel/preset-env": "^7.13.15", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@types/better-sqlite3": "^5.4.1", | ||
"@types/cli-table": "^0.3.0", | ||
"@types/jest": "^26.0.23", | ||
"@types/node": "^14.14.41", | ||
"@types/node-fetch": "^2.5.10", | ||
"@types/yargs": "^16.0.1", | ||
"@types/pino": "^6.3.11", | ||
"@types/vorpal": "^1.12.2", | ||
"@typescript-eslint/eslint-plugin": "^4.22.0", | ||
"@typescript-eslint/parser": "^4.22.0", | ||
"eslint": "^7.25.0", | ||
|
@@ -36,14 +44,27 @@ | |
"typescript": "^4.2.4" | ||
}, | ||
"scripts": { | ||
"build": "rimraf dist && tsup server.ts --format cjs,esm --dts", | ||
"build": "rimraf dist && tsup server.ts src/executor/index.ts cli.ts --format cjs,esm --dts", | ||
"cli": "LOG_LEVEL='debug' esno cli.ts", | ||
"lint": "eslint . --ext .ts", | ||
"start": "esno server.ts", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"watch": "yarn build -- --watch" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
"author": "Factorial <[email protected]>", | ||
"license": "ISC", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/factorialco/tentaclesql.git" | ||
}, | ||
"keywords": [ | ||
"sqlite", | ||
"rest-api", | ||
"cli" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/factorialco/tentaclesql/issues" | ||
}, | ||
"homepage": "https://github.com/factorialco/tentaclesql#readme" | ||
} |
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
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
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,32 @@ | ||
import Vorpal from 'vorpal' | ||
import Table from 'cli-table' | ||
|
||
import executor from '../executor' | ||
|
||
const startRpl = () => { | ||
const vorpal = new Vorpal() | ||
vorpal | ||
.command('sql <query>', 'Executes arbitrary sql.') | ||
.action(async (args: any) => { | ||
console.log('query args', args) | ||
const results = await executor(args.query, [], {}) | ||
|
||
console.log('results: ', results) | ||
|
||
const table = new Table({ | ||
head: Object.values(results[0]) | ||
}) | ||
|
||
results.forEach((result) => { | ||
table.push(Object.values(result)) | ||
}) | ||
|
||
table.toString() | ||
}) | ||
|
||
vorpal | ||
.delimiter('tentaclesql >') | ||
.show() | ||
} | ||
|
||
export default startRpl |
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 @@ | ||
declare module 'sqlite-parser'; |
Oops, something went wrong.