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
aac0e353
Commit
aac0e353
authored
3 months ago
by
Dorus
Browse files
Options
Downloads
Patches
Plain Diff
feat: made sure database connection gets closed upon exiting
parent
f659a522
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/manual_mode/manualMode.ts
+29
-21
29 additions, 21 deletions
src/manual_mode/manualMode.ts
with
29 additions
and
21 deletions
src/manual_mode/manualMode.ts
+
29
−
21
View file @
aac0e353
import
neo4j
from
'
neo4j-driver
'
;
import
neo4j
,
{
Session
}
from
'
neo4j-driver
'
;
import
{
Neo4jConnection
}
from
'
ts-common
'
;
import
{
queryService
}
from
'
../queryService
'
;
import
*
as
fs
from
'
fs
'
;
...
...
@@ -6,56 +6,64 @@ import path from 'path';
import
argv
from
"
process
"
import
{
createInterface
}
from
'
readline
'
;
const
rl
=
createInterface
({
input
:
process
.
stdin
,
output
:
process
.
stdout
,
});
function
manualQuery
(
cypherQuery
:
string
,
outputFile
:
string
)
{
return
`
${
cypherQuery
}
${
outputFile
}
`
}
function
connectToDataBase
(
uri
:
string
,
username
:
string
,
password
:
string
){
return
`
${
uri
}
${
username
}
${
password
}
`
function
connectToDataBase
(
uri
:
string
,
username
:
string
,
password
:
string
):
neo4j
.
Session
|
null
{
try
{
console
.
log
(
`Connecting to:
${
uri
}
`
);
const
driver
=
neo4j
.
driver
(
uri
,
neo4j
.
auth
.
basic
(
username
,
password
));
const
session
=
driver
.
session
();
// Create session here
console
.
log
(
`Connected successfully`
);
return
session
;
}
catch
(
error
)
{
console
.
error
(
`Error connecting to Neo4j:
${
error
}
`
);
return
null
;
}
}
if
(
require
.
main
===
module
)
{
// Command-line args:
// 1st uri,
// 2nd username
// 3rd password
// 4th output file name
const
uri
:
string
=
process
.
argv
[
2
]
||
"
bolt://localhost:7687
"
;
// default neo4j port
const
username
:
string
=
process
.
argv
[
3
]
||
"
neo4j
"
;
const
password
:
string
=
process
.
argv
[
4
]
||
"
password
"
;
const
outputFile
:
string
=
process
.
argv
[
5
]
||
'
output.json
'
;
// Default output file if none provided
const
session
:
Session
=
connectToDataBase
(
uri
,
username
,
password
)
// connect to neo4j
try
{
console
.
log
(
`Connecting to:
${
uri
}
`
);
const
driver
=
neo4j
.
driver
(
uri
,
neo4j
.
auth
.
basic
(
username
,
password
));
const
session
=
driver
.
session
();
}
catch
(
error
)
{
console
.
log
(
`Error connecting to neo4j:
${
error
}
`
)
}
console
.
log
(
`Connected succesfully`
);
console
.
log
(
"
Type a cypher query to query or type 'exit' in order to exit
"
)
// reccursive function that executes queries
const
promptQuery
=
()
=>
{
rl
.
question
(
'
query:
'
,
async
(
cypherQuery
)
=>
{
if
(
cypherQuery
==
"
exit
"
)
{
// todo: close database connections
if
(
session
)
{
await
session
.
close
();
console
.
log
(
"
Connection closed. Exiting...
"
)
}
rl
.
close
();
process
.
exit
()
}
try
{
// todo: Perform query
console
.
log
(
`Query
${
cypherQuery
}
written to
${
outputFile
}
`
);
}
catch
(
err
)
{
console
.
error
(
'
Error executing query:
'
,
err
);
...
...
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