Skip to content
Snippets Groups Projects
Commit c845dfcc authored by Dorus's avatar Dorus
Browse files

feat: added command line parsing using commander

parent 3188f102
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -16,6 +16,7 @@
"typescript": "^5.0.0"
},
"dependencies": {
"commander": "^12.1.0",
"neo4j-driver": "^5.26.0",
"ts-common": "link:ts-common"
}
......
# run a neo4j db container locally
# run a neo4j database locally
## Using docker
```
```bash
docker run --rm --name neo4j -p 7687:7687 -p 7474:7474 -d --env NEO4J_AUTH=neo4j/password neo4j:latest
```
To access the neo4j container
```
```bash
docker exec -it neo4j bin/cypher-shell -u neo4j -p password
```
## Using Neo4j Desktop
# Use the query service
Download Neo4j from the [Neo4j Download Page](https://neo4j.com/download/) and follow their instructions.
Ensure your service is configured to connect to `bolt://localhost:7687` using the username `neo4j` and the password you set in Neo4j Desktop.
From `query-service`
# Use the Manual Query Service
The manual query service allows you to run Cypher queries against a Neo4j database and save the results to a json-file.
From the `query-service` directory:
### Command Syntax
```bash
bun run src/manual_mode/manualMode.ts [options]
```
bun run src/manual_mode/manual_mode.ts [uri] [username] [password] [output filename]
```
| Option | Short | Default | Description |
|----------------------|-------|--------------------|---------------------------------|
| `--host <string>` | `-h` | `localhost` | The database host address |
| `--port <number>` | `-p` | `7687` | The database port |
| `--username <string>`| `-u` | `neo4j` | The database username |
| `--password <string>`| `-P` | `password` | The database password |
| `--output <string>` | `-o` | `output.json` | Name of the output JSON file |
`uri` will default to `localhost:7687`
`username` will default to `neo4j`
`password` will default to `password`
`output filename` will default to `output.json`
......@@ -3,6 +3,23 @@ import { queryService } from "../readers/queryService";
import * as fs from "fs";
import path from "path";
import { createInterface } from "readline";
import { Command } from "commander";
const program = new Command();
// Define CLI options
program
.name("manualMode")
.description("Run manual Cypher queries against a Neo4j database")
.option("-h, --host <string>", "Database host", "localhost")
.option("-p, --port <number>", "Database port", "7687")
.option("-u, --username <string>", "Database username", "neo4j")
.option("-P, --password <string>", "Database password", "password")
.option("-o, --output <string>", "Output file name", "output.json");
program.parse(process.argv);
const options = program.opts();
const rl = createInterface({
input: process.stdin,
......@@ -23,22 +40,15 @@ async function manualQuery(
}
if (require.main === module) {
const uri: string = process.argv[2] || "bolt://localhost:7687";
const username: string = process.argv[3] || "neo4j";
const password: string = process.argv[4] || "password";
const outputFile: string = process.argv[5] || "output.json";
const [protocol, ...rest] = uri.split("://");
const url = `://${rest.join("://")}`;
const dbConfig: DbConnection = {
id: 1,
internalDatabaseName: "neo4j",
url: url,
protocol: protocol,
port: 7687,
username,
password,
url: `://${options.host}`,
protocol: "bolt",
port: parseInt(options.port),
username: options.username,
password: options.password,
type: "neo4j",
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment