Skip to content

Instantly share code, notes, and snippets.

@timlrx
Last active April 22, 2021 09:07
Show Gist options
  • Save timlrx/78f65f0a1ae7811d46dac390a0692cc6 to your computer and use it in GitHub Desktop.
Save timlrx/78f65f0a1ae7811d46dac390a0692cc6 to your computer and use it in GitHub Desktop.
Connect Neo4j Database
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