Neo4j - 入门学习

1. 简介

Neo4j is a highly scalable, robust native graph database.


Neo4j Sample Datasets

2. 启动测试

启动neo4j

docker run \
    --publish=7474:7474 --publish=7687:7687 \
    --volume=$HOME/neo4j/data:/data \
    neo4j

测试

地址:http://localhost:7474
账号:neo4j
密码:neo4j
点击Jump into code,完成入门学习

hello neo4j

3. Neo4j Desktop

一个Neo4j Instance,在同一时间只能激活一个Graph,不过,我们可以启动多个Instance。
通过Neo4j Desktop可以创建Local Instance,也可以管理多个Instance,包含Local和Remote。

  • Neo4j Desktop


    Neo4j Desktop
  • Neo4j Desktop Management for Local Instance


    Neo4j Desktop Management for Local Instance
  • Neo4j Browser


    Neo4j Browser

4. Neo4j Client

$ sudo add-apt-repository ppa:cleishm/neo4j
$ sudo apt-get update
$ sudo apt-get install neo4j-client libneo4j-client-dev
  • Neo4j Client


    Neo4j Client
  • Neo4j for C Language

#include <neo4j-client.h>
#include <errno.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    neo4j_client_init();

    /* use NEO4J_INSECURE when connecting to disable TLS */
    neo4j_connection_t *connection =
            neo4j_connect("neo4j://user:pass@localhost:7687", NULL, NEO4J_INSECURE);
    if (connection == NULL)
    {
        neo4j_perror(stderr, errno, "Connection failed");
        return EXIT_FAILURE;
    }

    neo4j_result_stream_t *results =
            neo4j_run(connection, "RETURN 'hello world'", neo4j_null);
    if (results == NULL)
    {
        neo4j_perror(stderr, errno, "Failed to run statement");
        return EXIT_FAILURE;
    }

    neo4j_result_t *result = neo4j_fetch_next(results);
    if (result == NULL)
    {
        neo4j_perror(stderr, errno, "Failed to fetch result");
        return EXIT_FAILURE;
    }

    neo4j_value_t value = neo4j_result_field(result, 0);
    char buf[128];
    printf("%s\n", neo4j_tostring(value, buf, sizeof(buf)));

    neo4j_close_results(results);
    neo4j_close(connection);
    neo4j_client_cleanup();
    return EXIT_SUCCESS;
}

5. Neo4j for Python

  • install package
$ pip3.6 install neo4j
  • hello.py
from neo4j.v1 import GraphDatabase

neo4j_uri = "bolt://localhost:7687"
auth_user = 'neo4j'
auth_psd = 'root'


class HelloWorldExample(object):

    def __init__(self, uri, user, password):
        self._driver = GraphDatabase.driver(uri, auth=(user, password))

    def close(self):
        self._driver.close()

    def print_greeting(self, message):
        with self._driver.session() as session:
            greeting = session.write_transaction(self._create_and_return_greeting, message)
            print(greeting)
            # session.run()

    @staticmethod
    def _create_and_return_greeting(tx, message):
        result = tx.run("CREATE (a:Greeting) "
                        "SET a.message = $message "
                        "RETURN a.message + ', from node ' + id(a)", message=message)
        return result.single()[0]


if __name__ == '__main__':
    print('run in main...')
    example = HelloWorldExample(neo4j_uri, auth_user, auth_psd)
    example.print_greeting('Hello Neo4j')
    example.close()
  • run hello.py
$ python3.6 hello.py
run in main...
Hello Neo4j, from node 179

6. Reference

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007阅读 2,243评论 0 3
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,611评论 2 45
  • 道可道、非常道! 道生一、一生二、二生三、三生万物! 天地,万物之盗;万物,人之盗;人,万物之盗! 老子曰:一曰慈...
    8b92483773c6阅读 383评论 0 0
  • 我的家庭教育理念有两个重要的基石,一个是相信孩子都是向上的,或者说都有上进心;另一个是相信孩子都是想和父母好的,都...
    66f7eee7a750阅读 233评论 0 1
  • 2017年12月21日 安静日第三次 阳光明媚的玄武湖,迎来了我们第三次安静日,温暖,舒适。 上午10:00,我们...
    徐云阅读 275评论 0 4