Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
query-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GraphPolaris
Microservices
query-service
Commits
4cd45512
Commit
4cd45512
authored
3 months ago
by
Dorus
Browse files
Options
Downloads
Patches
Plain Diff
feat: added version of the script that is able to interface wth a json input
parent
4179a0cd
No related branches found
Branches containing commit
Tags
v1.18.0
Tags containing commit
No related merge requests found
Pipeline
#143364
passed
3 months ago
Stage: tag-release
Stage: get-release-tag
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/manual_mode/json_interface.ts
+75
-0
75 additions, 0 deletions
src/manual_mode/json_interface.ts
with
75 additions
and
0 deletions
src/manual_mode/json_interface.ts
0 → 100644
+
75
−
0
View file @
4cd45512
import
{
Neo4jConnection
,
type
DbConnection
}
from
"
ts-common
"
;
import
{
queryService
}
from
"
../readers/queryService
"
;
import
*
as
fs
from
"
fs
"
;
import
path
from
"
path
"
;
import
{
Command
}
from
"
commander
"
;
const
program
=
new
Command
();
// Define CLI options
program
.
name
(
"
manualMode
"
)
.
description
(
"
Run Cypher queries against a Neo4j database from a JSON input
"
)
.
option
(
"
-i, --input <string>
"
,
"
Input JSON file
"
,
"
query_input.json
"
)
.
option
(
"
-o, --output <string>
"
,
"
Output file name
"
,
"
output.json
"
);
program
.
parse
(
process
.
argv
);
const
options
=
program
.
opts
();
interface
QueryInput
{
database
:
{
host
?:
string
;
port
?:
number
;
username
?:
string
;
password
?:
string
;
};
query
:
string
;
}
async
function
executeQuery
(
inputFile
:
string
,
outputFile
:
string
)
{
// Read input JSON file
const
inputPath
=
path
.
join
(
__dirname
,
inputFile
);
let
inputData
:
QueryInput
;
try
{
inputData
=
JSON
.
parse
(
fs
.
readFileSync
(
inputPath
,
'
utf8
'
));
}
catch
(
err
)
{
console
.
error
(
`Error reading input file:
${
err
}
`
);
process
.
exit
(
1
);
}
// Construct database connection configuration
const
dbConfig
:
DbConnection
=
{
id
:
1
,
internalDatabaseName
:
"
neo4j
"
,
url
:
`://
${
inputData
.
database
?.
host
||
'
localhost
'
}
`
,
protocol
:
"
bolt
"
,
port
:
inputData
.
database
?.
port
?
parseInt
(
inputData
.
database
.
port
.
toString
())
:
7687
,
username
:
inputData
.
database
?.
username
||
'
neo4j
'
,
password
:
inputData
.
database
?.
password
||
'
password
'
,
type
:
"
neo4j
"
,
};
// Execute query
try
{
const
result
=
await
queryService
(
dbConfig
,
inputData
.
query
);
// Write output to file
const
outputPath
=
path
.
join
(
__dirname
,
outputFile
);
fs
.
writeFileSync
(
outputPath
,
JSON
.
stringify
(
result
,
null
,
2
));
console
.
log
(
`Query results written to
${
outputPath
}
`
);
return
result
;
}
catch
(
err
)
{
console
.
error
(
'
Error executing query:
'
,
err
);
process
.
exit
(
1
);
}
}
// Only run if directly executed (not imported)
if
(
require
.
main
===
module
)
{
executeQuery
(
options
.
input
,
options
.
output
);
}
export
{
executeQuery
};
// Allow importing for testing or other uses
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment