How to use neo4j-driver - 10 common examples

To help you get started, we’ve selected a few neo4j-driver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neo4j-contrib / neovis.js / __tests__ / neovis.tests.js View on Github external
it('should call sizeCypher and save return value to data set value', async () => {
			const node = testUtils.makeNode([label1]);
			testUtils.mockFullRunSubscribe({
				[initial_cypher]: {
					default: [testUtils.makeRecord([node])]
				},
				[sizeCypher]: {
					[node.identity.toInt()]: [testUtils.makeRecord([Neo4j.int(1)])]
				}
			});

			neovis.render();
			await testUtils.neovisRenderDonePromise(neovis);
			expect(Neo4jMock.mockSessionRun).toHaveBeenCalledTimes(1 + 1); // once for initial cypher and once for the sizeCypher
			expect(neovis._data.nodes.get(1)).toHaveProperty('value', 1);
		});
	});
github neo4j-contrib / neovis.js / __tests__ / neovis.tests.js View on Github external
it('should call sizeCypher and save return value to data set value', async () => {
			const node = testUtils.makeNode([label1]);
			testUtils.mockFullRunSubscribe({
				[initial_cypher]: {
					default: [testUtils.makeRecord([node])]
				},
				[sizeCypher]: {
					[node.identity.toInt()]: [testUtils.makeRecord([Neo4j.int(1)])]
				}
			});

			neovis.render();
			await testUtils.neovisRenderDonePromise(neovis);
			expect(Neo4jMock.mockSessionRun).toHaveBeenCalledTimes(1 + 1); // once for initial cypher and once for the sizeCypher
			expect(neovis._data.nodes.get(1)).toHaveProperty('value', 1);
		});
	});
github thedevs-network / kutt / server / migration / 04_links.ts View on Github external
require("dotenv").config();
import { v1 as NEO4J } from "neo4j-driver";
import knex from "knex";
import PQueue from "p-queue";
import { startOfHour } from "date-fns";

let count = 0;
const queue = new PQueue({ concurrency: 5 });

queue.on("active", () => (count % 1000 === 0 ? console.log(count++) : count++));

// 1. Connect to Neo4j database
const neo4j = NEO4J.driver(
  process.env.NEO4J_DB_URI,
  NEO4J.auth.basic(process.env.NEO4J_DB_USERNAME, process.env.NEO4J_DB_PASSWORD)
);

// 2. Connect to Postgres database
const postgres = knex({
  client: "postgres",
  connection: {
    host: process.env.DB_HOST,
    database: process.env.DB_NAME,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD
  }
});

(async function() {
github thedevs-network / kutt / server / migration / 04_links.ts View on Github external
require("dotenv").config();
import { v1 as NEO4J } from "neo4j-driver";
import knex from "knex";
import PQueue from "p-queue";
import { startOfHour } from "date-fns";

let count = 0;
const queue = new PQueue({ concurrency: 5 });

queue.on("active", () => (count % 1000 === 0 ? console.log(count++) : count++));

// 1. Connect to Neo4j database
const neo4j = NEO4J.driver(
  process.env.NEO4J_DB_URI,
  NEO4J.auth.basic(process.env.NEO4J_DB_USERNAME, process.env.NEO4J_DB_PASSWORD)
);

// 2. Connect to Postgres database
const postgres = knex({
  client: "postgres",
  connection: {
    host: process.env.DB_HOST,
    database: process.env.DB_NAME,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD
  }
});

(async function() {
  const startTime = Date.now();
github AMIS-Services / code-cafe / neo4j-graphdatabase / neo4j-node.js View on Github external
const neo4j = require('neo4j-driver').v1;
const request = require('request');

// SET YOUR VALUE FOR THE PASSWORD AND THE IP ADDRESS WHERE THE NEO4J SERVER CAN BE ACCESSED!!
var user = "neo4j", password = "neo4j1", uri = "bolt://192.168.188.142:7687"

const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session(neo4j.WRITE);

var countriesDocumentURL = "https://raw.githubusercontent.com/mledoze/countries/master/countries.json"
async function addConstraints(tx) {
    console.log(`Adding Constraints`)
    return tx.run('CREATE CONSTRAINT ON (l:Language) ASSERT l.name IS UNIQUE').then(tx.run('CREATE CONSTRAINT ON (c:Country) ASSERT c.name IS UNIQUE').then(tx.run('CREATE CONSTRAINT ON (r:Region) ASSERT r.name IS UNIQUE').then(tx.run('CREATE CONSTRAINT ON (c:Country) ASSERT c.code IS UNIQUE'))));
}


async function addLanguages(tx, languages) {
github AMIS-Services / code-cafe / neo4j-graphdatabase / neo4j-node.js View on Github external
const neo4j = require('neo4j-driver').v1;
const request = require('request');

// SET YOUR VALUE FOR THE PASSWORD AND THE IP ADDRESS WHERE THE NEO4J SERVER CAN BE ACCESSED!!
var user = "neo4j", password = "neo4j1", uri = "bolt://192.168.188.142:7687"

const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session(neo4j.WRITE);

var countriesDocumentURL = "https://raw.githubusercontent.com/mledoze/countries/master/countries.json"
async function addConstraints(tx) {
    console.log(`Adding Constraints`)
    return tx.run('CREATE CONSTRAINT ON (l:Language) ASSERT l.name IS UNIQUE').then(tx.run('CREATE CONSTRAINT ON (c:Country) ASSERT c.name IS UNIQUE').then(tx.run('CREATE CONSTRAINT ON (r:Region) ASSERT r.name IS UNIQUE').then(tx.run('CREATE CONSTRAINT ON (c:Country) ASSERT c.code IS UNIQUE'))));
}


async function addLanguages(tx, languages) {
    console.log(`Adding languages`)
    var s = '';
    languages.forEach(element => s = s.concat(`CREATE (:Language {name: '${element}'})
                                             `))
    console.log("Statement " + s)
    return tx.run(s);
}
github neo4j-examples / neo4j-movies-template / api / neo4j / cypher.js View on Github external
"use strict";

// neo4j cypher helper module
var nconf = require('../config'),
  _ = require('lodash');

var neo4j = require('neo4j-driver').v1;
var driver = neo4j.driver(nconf.get('neo4j-local'), neo4j.auth.basic(nconf.get('USERNAME'), nconf.get('PASSWORD')));

if (nconf.get('neo4j') == 'remote') {
  driver = neo4j.driver(nconf.get('neo4j-remote'), neo4j.auth.basic(nconf.get('USERNAME'), nconf.get('PASSWORD')));
}

var session = driver.session();

var Cypher = function (queryFn, resultsFn, resultsOptions) {
  return function (params, options, callback) {
    queryFn(params, options, (err, query, cypher_params) => {
      if (err) {
        return callback(err, formatResponse(options, null, query, cypher_params, null, err));
      }
      else {
        var myResult = [];
        session.run(query, cypher_params)
          .then(result => {

            if (!_.isEmpty(result.records)) {
github thedevs-network / kutt / server / migration / 03_domains.ts View on Github external
require("dotenv").config();
import { v1 as NEO4J } from "neo4j-driver";
import knex from "knex";
import PQueue from "p-queue";

const queue = new PQueue({ concurrency: 1 });

// 1. Connect to Neo4j database
const neo4j = NEO4J.driver(
  process.env.NEO4J_DB_URI,
  NEO4J.auth.basic(process.env.NEO4J_DB_USERNAME, process.env.NEO4J_DB_PASSWORD)
);
// 2. Connect to Postgres database
const postgres = knex({
  client: "postgres",
  connection: {
    host: process.env.DB_HOST,
    database: process.env.DB_NAME,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD
  }
});

(async function() {
  const startTime = Date.now();
github CharlBest / nean-stack-starter / src / server / core / database.ts View on Github external
private static createDriver() {
        const driver = neo4j.driver(
            environment.database.uri,
            neo4j.auth.basic(environment.database.username, environment.database.password),
            {
                disableLosslessIntegers: true,
                logging: {
                    level: 'warn',
                    logger: (level, message) => logger.log(level, `Neo4j - ${message}`)
                }
            }
        );

        // Register a callback to know if driver creation was successful:
        driver.onCompleted = () => {
            // proceed with using the driver, it was successfully instantiated
        };

        // Register a callback to know if driver creation failed.
        // This could happen due to wrong credentials or database unavailability:
github underlay / underlay-api / graphdb.js View on Github external
/* eslint-disable global-require */
import { v1 as neo4j } from 'neo4j-driver';

if (process.env.NODE_ENV !== 'production') {
	require('./config.js');
}

const driver = neo4j.driver(
	process.env.GRAPHENEDB_BOLT_URL,
	neo4j.auth.basic(
		process.env.GRAPHENEDB_BOLT_USER,
		process.env.GRAPHENEDB_BOLT_PASSWORD
	)
);
const graphSession = driver.session();
graphSession.run(`
	CREATE INDEX ON :Thing(identifier)
	CREATE CONSTRAINT ON (t:Thing) ASSERT t.identifier IS UNIQUE
`);

export default {
	graphSession: graphSession
};