Last active
April 22, 2021 09:07
-
-
Save timlrx/78f65f0a1ae7811d46dac390a0692cc6 to your computer and use it in GitHub Desktop.
Connect Neo4j Database
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
import { createDriver } from 'use-neo4j'; | |
const DEFAULT_DB_SETTINGS = { | |
neo4jHost: 'localhost', | |
neo4jPort: '7687', | |
neo4jUsername: '', | |
neo4jPassword: '', | |
}; | |
const ConnectDatabase = ({ driver, setDriver, nextStep }) => { | |
const [dbSettings, setDbSettings] = useState(DEFAULT_DB_SETTINGS); | |
const onConnectDb = () => { | |
const connectionDriver = createDriver( | |
'bolt', | |
dbSettings.neo4jHost, | |
dbSettings.neo4jPort, | |
dbSettings.neo4jUsername, | |
dbSettings.neo4jPassword, | |
); | |
connectionDriver | |
.verifyConnectivity() | |
.then(() => { | |
setDriver(connectionDriver); | |
}) | |
.catch((err) => { | |
// handle wrong connection settings | |
}) | |
}; | |
return ( | |
<form onSubmit={onConnectDb}> | |
/* Form component for host, username, port, password */ | |
</form> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment