index.js
function make_query_maker(connection_string, connection_opts) {
	connection_string = connection_string || "http://localhost:7474";
	connection_opts = connection_opts || {};
	var client_cache = null;

	return {
		query: query,
		multi: multi
	};

	/**
	 * Makes a cypher query and resolves to the result
	 * @param  {String}  cypher_query The CQL code to execute
	 * @param  {Object}  [parameters] The parameters to pass to the query
	 * @return {Promise}              Resolves to the result of the query
	 */
	function query(cypher_query, parameters) {
		return get_client()
			.then(rpar(query_with, cypher_query, parameters));
	}

	/**
	 * Make a new object for batching queries. Call multi.query multiple times,
	 * and then call multi.exec() to get a promise of whether everything succeeded
	 * or not.
	 * @return {Multi} Returns a multi object with `query` and `exec` methods
	 */
	function multi() {
		var multi = get_client().then(function (client) {
			return client.multi();
		});

		return {
			query: query,
			exec: exec
		};

		function query(cypher_query, parameters) {
			return multi.then(function (multi) {
				return query_with(multi, cypher_query, parameters);
			});
		}

		function exec() {
			return multi.then(function (multi) {
				return make_promise(multi.exec.bind(multi));
			});
		}
	}

	// Makes a query with a given client and returns a promise
	function query_with(client, cypher_query, parameters) {
		parameters = parameters || {};
		return make_promise(client.query.bind(client, cypher_query, parameters));
	}

	// Creates a new client or returns a cached one
	function get_client() {
		if (client_cache) return Promise.resolve(client_cache);
		return make_promise(
			cypher.createClient.bind(cypher, connection_string, connection_opts)
		).then(cache_client);
	}

	// Caches a client for later use
	function cache_client(client) {
		client_cache = client;
		return client;
	}
}
function make_query_maker(connection_string, connection_opts) {
	connection_string = connection_string || "http://localhost:7474";
	connection_opts = connection_opts || {};
	var client_cache = null;

	return {
		query: query,
		multi: multi
	};

	/**
	 * Makes a cypher query and resolves to the result
	 * @param  {String}  cypher_query The CQL code to execute
	 * @param  {Object}  [parameters] The parameters to pass to the query
	 * @return {Promise}              Resolves to the result of the query
	 */
	function query(cypher_query, parameters) {
		return get_client()
			.then(rpar(query_with, cypher_query, parameters));
	}

	/**
	 * Make a new object for batching queries. Call multi.query multiple times,
	 * and then call multi.exec() to get a promise of whether everything succeeded
	 * or not.
	 * @return {Multi} Returns a multi object with `query` and `exec` methods
	 */
	function multi() {
		var multi = get_client().then(function (client) {
			return client.multi();
		});

		return {
			query: query,
			exec: exec
		};

		function query(cypher_query, parameters) {
			return multi.then(function (multi) {
				return query_with(multi, cypher_query, parameters);
			});
		}

		function exec() {
			return multi.then(function (multi) {
				return make_promise(multi.exec.bind(multi));
			});
		}
	}

	// Makes a query with a given client and returns a promise
	function query_with(client, cypher_query, parameters) {
		parameters = parameters || {};
		return make_promise(client.query.bind(client, cypher_query, parameters));
	}

	// Creates a new client or returns a cached one
	function get_client() {
		if (client_cache) return Promise.resolve(client_cache);
		return make_promise(
			cypher.createClient.bind(cypher, connection_string, connection_opts)
		).then(cache_client);
	}

	// Caches a client for later use
	function cache_client(client) {
		client_cache = client;
		return client;
	}
}
function make_query_maker ( connection_string , connection_opts ) { connection_string = connection_string || "http://localhost:7474" ; connection_opts = connection_opts || { } ; var client_cache = null ; return { query : query , multi : multi } ; /**
	 * Makes a cypher query and resolves to the result
	 * @param  {String}  cypher_query The CQL code to execute
	 * @param  {Object}  [parameters] The parameters to pass to the query
	 * @return {Promise}              Resolves to the result of the query
	 */ function query ( cypher_query , parameters ) { return get_client ( ) . then ( rpar ( query_with , cypher_query , parameters ) ) ; } /**
	 * Make a new object for batching queries. Call multi.query multiple times,
	 * and then call multi.exec() to get a promise of whether everything succeeded
	 * or not.
	 * @return {Multi} Returns a multi object with `query` and `exec` methods
	 */ function multi ( ) { var multi = get_client ( ) . then ( function ( client ) { return client . multi ( ) ; } ) ; return { query : query , exec : exec } ; function query ( cypher_query , parameters ) { return multi . then ( function ( multi ) { return query_with ( multi , cypher_query , parameters ) ; } ) ; } function exec ( ) { return multi . then ( function ( multi ) { return make_promise ( multi . exec . bind ( multi ) ) ; } ) ; } } // Makes a query with a given client and returns a promise function query_with ( client , cypher_query , parameters ) { parameters = parameters || { } ; return make_promise ( client . query . bind ( client , cypher_query , parameters ) ) ; } // Creates a new client or returns a cached one function get_client ( ) { if ( client_cache ) return Promise . resolve ( client_cache ) ; return make_promise ( cypher . createClient . bind ( cypher , connection_string , connection_opts ) ) . then ( cache_client ) ; } // Caches a client for later use function cache_client ( client ) { client_cache = client ; return client ; } }
Creates a new client for making cypher queries
@param  {String}  connection_string The url of the Neo4j server
@param  {Object}  [connection_opts] Options for node-cypher
@return {Cypher}                    Returns a new Cypher client
Creates a new client for making cypher queries