项目作者: cleishm

项目描述 :
neo4j-client -- Neo4j Command Line Interface (CLI)
高级语言: C
项目地址: git://github.com/cleishm/libneo4j-client.git
创建时间: 2015-10-28T20:48:47Z
项目社区:https://github.com/cleishm/libneo4j-client

开源协议:Apache License 2.0

下载


neo4j-client

About

neo4j-client is a command shell (CLI) for Neo4j. It supports secure connections
to Neo4j server, sending of statements (including multiline statements),
persistent command history, and rendering of results to tables or CSV.

neo4j-client utilizes the Bolt Network Protocol, and
will work with any server that supports Bolt.

For more details, see the project page and
the FAQ.

Requirements

neo4j-client is known to work on GNU/Linux, Mac OS X and FreeBSD. It
requires neo4j 3.0.0 or later.

Getting Started

If you’re using Mac OS X, neo4j-client can be installed using homebrew:

  1. $ brew install cleishm/neo4j/neo4j-client

If you’re using Ubuntu, neo4j-client can be install using APT:

  1. $ sudo add-apt-repository ppa:cleishm/neo4j
  2. $ sudo apt-get update
  3. $ sudo apt-get install neo4j-client libneo4j-client-dev

There are also packages available for other platforms, including
Debian,
Fedora,
CentOS and
openSUSE.

Otherwise, please see Building below.

neo4j-client Usage

Example interactive usage:

  1. $ neo4j-client -u neo4j localhost
  2. The authenticity of host 'localhost:7687' could not be established.
  3. TLS certificate fingerprint is ded0fd2e893cd0b579f47f7798e10cb68dfa2fd3bc9b3c973157da81bab451d74f9452ba99a9c5f66dadb8a360959e5ebd8abb2d7c81230841e60531a96d268.
  4. Would you like to trust this host (NO/yes/once)? yes
  5. Password: *****
  6. neo4j> :help
  7. Enter commands or cypher statements at the prompt.
  8. Commands always begin with a colon (:) and conclude at the end of the line,
  9. for example `:help`. Statements do not begin with a colon (:), may span
  10. multiple lines, are terminated with a semi-colon (;) and will be sent to
  11. the Neo4j server for evaluation.
  12. Available commands:
  13. :quit Exit the shell
  14. :connect '<url>' Connect to the specified URL
  15. :connect host [port] Connect to the specified host (and optional port)
  16. :disconnect Disconnect the client from the server
  17. :export Display currently exported parameters
  18. :export name=val ... Export parameters for queries
  19. :unexport name ... Unexport parameters for queries
  20. :reset Reset the session with the server
  21. :set Display current option values
  22. :set option=value ... Set shell options
  23. :unset option ... Unset shell options
  24. :status Show the client connection status
  25. :help Show usage information
  26. :format (table|csv) Set the output format
  27. :width (<n>|auto) Set the number of columns in the table output
  28. For more information, see the neo4j-client(1) manpage.
  29. neo4j>
  30. neo4j> :status
  31. Connected to 'neo4j://neo4j@localhost:7687'
  32. neo4j>
  33. neo4j> MATCH (n:Person) RETURN n LIMIT 3;
  34. +----------------------------------------------------------------------------+
  35. | n |
  36. +----------------------------------------------------------------------------+
  37. | (:Person{born:1964,name:"Keanu Reeves"}) |
  38. | (:Person{born:1967,name:"Carrie-Anne Moss"}) |
  39. | (:Person{born:1961,name:"Laurence Fishburne"}) |
  40. +----------------------------------------------------------------------------+
  41. neo4j>
  42. neo4j> :set
  43. echo=off // echo non-interactive commands before rendering results
  44. insecure=no // do not attempt to establish secure connections
  45. format=table // set the output format (`table` or `csv`).
  46. outfile= // redirect output to a file
  47. username="neo4j" // the default username for connections
  48. width=auto // the width to render tables (`auto` for term width)
  49. neo4j>
  50. neo4j> :quit
  51. $

Example non-interactive usage:

  1. $ echo "MATCH (n:Person) RETURN n.name AS name, n.born AS born LIMIT 3" | \
  2. neo4j-client -u neo4j -P localhost > result.csv
  3. Password: *****
  4. $
  5. $ cat result.csv
  6. "name","born"
  7. "Keanu Reeves",1964
  8. "Carrie-Anne Moss",1967
  9. "Laurence Fishburne",1961
  10. $

Evaluating source files, e.g.:

  1. $ cat query.cyp
  2. :set echo
  3. :export name='Emil'
  4. // Create a person node if it doesn't exist
  5. begin;
  6. MERGE (:Person {name: {name}});
  7. commit;
  8. // return the total number of people
  9. MATCH (n:Person)
  10. RETURN count(n);
  11. $
  12. $ neo4j-client -u neo4j -p pass -o result.out -i query.cyp
  13. $ cat result.out
  14. +:export name='Emil'
  15. +begin;
  16. +MERGE (:Person {name: {name}});
  17. Nodes created: 1
  18. Properties set: 1
  19. Labels added: 1
  20. +commit;
  21. +MATCH (n:Person)
  22. RETURN count(n);
  23. "count(n)"
  24. 137
  25. $

libneo4j-client

libneo4j-client is a client library for Neo4j, written in C, and intended as a
foundation on which basic tools and drivers for various languages may be built.
libneo4j-client takes care of all the detail of establishing a session with a
Neo4j server, sending statements for evaluation, and retrieving results.

libneo4j-client provides a single C header file, neo4j-client.h, for
inclusion in source code using the libneo4j-client API. The API is described in
the API Documentation.

libneo4j-client can be included in your project by linking the library at
compile time, typically using the linking flags
-lneo4j-client -lssl -lcrypto -lm. Alternatively, libneo4j-client ships with
a pkg-config
description file, enabling you to obtain the required flags using
pkg-config --libs libneo4j-client.

API Documentation

API documentation for the latest release is available at
https://neo4j-client.net/doc/latest/neo4j-client_8h.html.

Documentation can be built using make doc, which will use doxygen to generate
documentation and output it into the doc/ directory of the libneo4j-client
source tree. See Building below.

Example

  1. #include <neo4j-client.h>
  2. #include <errno.h>
  3. #include <stdio.h>
  4. int main(int argc, char *argv[])
  5. {
  6. neo4j_client_init();
  7. /* use NEO4J_INSECURE when connecting to disable TLS */
  8. neo4j_connection_t *connection =
  9. neo4j_connect("neo4j://user:pass@localhost:7687", NULL, NEO4J_INSECURE);
  10. if (connection == NULL)
  11. {
  12. neo4j_perror(stderr, errno, "Connection failed");
  13. return EXIT_FAILURE;
  14. }
  15. neo4j_result_stream_t *results =
  16. neo4j_run(connection, "RETURN 'hello world'", neo4j_null);
  17. if (results == NULL)
  18. {
  19. neo4j_perror(stderr, errno, "Failed to run statement");
  20. return EXIT_FAILURE;
  21. }
  22. neo4j_result_t *result = neo4j_fetch_next(results);
  23. if (result == NULL)
  24. {
  25. neo4j_perror(stderr, errno, "Failed to fetch result");
  26. return EXIT_FAILURE;
  27. }
  28. neo4j_value_t value = neo4j_result_field(result, 0);
  29. char buf[128];
  30. printf("%s\n", neo4j_tostring(value, buf, sizeof(buf)));
  31. neo4j_close_results(results);
  32. neo4j_close(connection);
  33. neo4j_client_cleanup();
  34. return EXIT_SUCCESS;
  35. }

Building

To use neo4j-client or libneo4j-client, consider installation using the package
management system for your operating system (currently
Mac OS X,
Debian,
Ubuntu,
Fedora,
CentOS and
openSUSE).

If neo4j-client is not available via your package management system,
please download the latest release, unpack and then:

  1. $ ./configure
  2. $ make clean check
  3. $ sudo make install

libneo4j-client requires OpenSSL, although this can be disabled by invoking
configure with --without-tls.

neo4j-client also requires some dependencies to build, including
libedit and
libcypher-parser. If these are not available,
just the library can be built (without neo4j-client), by invoking configure
with --disable-tools.

Building from the GitHub repository requires a few extra steps. Firstly, some
additional tooling is required, including autoconf, automake and libtool.
Assuming these are available, to checkout from GitHub and build:

  1. $ git clone https://github.com/cleishm/libneo4j-client.git
  2. $ cd libneo4j-client
  3. $ ./autogen.sh
  4. $ ./configure
  5. $ make clean check
  6. $ sudo make install

If you encounter warnings or errors during the build, please report them at
https://github.com/cleishm/libneo4j-client/issues. If you wish to proceed
dispite warnings, please invoke configure with the --disable-werror.

NOTE: Recent versions of Mac OS X ship without the OpenSSL header files, and
autoconf doesn’t pick this up (yet). If you used the homebrew install method,
this will resolve the issue. If you’re using Mac OS X, want to build manually
instead of using homebrew, and you get a build failure related to missing
openssl headers, try the following:

  1. $ brew install openssl
  2. $ ./configure --with-libs=/usr/local/opt/openssl
  3. $ make clean check
  4. $ sudo make install

More detail about this workaround can be found via brew info openssl.

Support

Having trouble with neo4j-client? Please raise any issues with usage on
StackOverflow. If
you’ve found a bug in the code, please raise an issue on
GitHub and include details of how
to reproduce the bug.

Contributing

Contributions to neo4j-client are encouraged and should be made via pull
requests made to the GitHub repository. Please include test cases where
possible, and use a style and approach consistent with the rest of the library.

It may be worthwhile raising an issue on github for the contribution you
intend to make before developing the code, to allow for discussion and feedback
on the requirements.

License

neo4j-client is licensed under the Apache License, Version 2.0.

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.