How to store graph data in a database?

I am new to graphics and very interesting. This question may be a noob, but please post some useful material.

I am trying to create a small social network where each user is a node and has an undirected connection with his friend.

Its work is great, but now I want to save it to the database.

How to store data? How to save all connected nodes (pointer) node.

Is it better to delete memory after the user logs out and reads it from the database when logging in or when logging in and logging out, should it not affect the node?

I know its theoretical. Any links would be really helpful.

+8
database graph graph-databases
source share
2 answers

Use the actual graph database to store your data.

http://www.neo4j.org/

You can store key / value pairs in node, and you can also store edges that connect nodes.

Then you can use something like Gremlin to query / move the chart - https://github.com/tinkerpop/gremlin . See their documentation for downloading examples and performing custom queries: https://github.com/tinkerpop/gremlin/wiki/Getting-Started

The syntax idea:

gremlin> // lets only take 'knows' labeled edges gremlin> v.out('knows') ==>v[2] ==>v[4] gremlin> // lets do a traversal from the '1' marko vertex to its outgoing edges. gremlin> // in the property graph world, edges are first class citizens that can be traversed to. gremlin> v.outE ==>e[7][1-knows->2] ==>e[9][1-created->3] ==>e[8][1-knows->4] 
+8
source share

I start from the bottom.

Is it better to delete memory after a user logs out and reads it from the database, when it logs in or should log in and log out, should it not affect node?

You will need some kind of persistent storage or you will lose all the data that you received during the first crash / reboot, which can upset your users a little.

How to store data? Well, not knowing this, it’s difficult, however, assuming you have a list of users and each user can have 0 or more friends, then I would go with two tables.

  • Users - save all your user information, such as username and password.
  • UsersFriends * - store all relations in UserID β†’ UserID * mode

Example

User table

 UserID Username 1 user2511713 2 abstracthchaos 3 anotheruser 

UsersFriends

 UserID FriendUserID 1 3 2 3 1 2 

Therefore, user 2511713 is friends with friend-friends and abstracthchaos and abstracthchaos friends with another user, depending on your business logic, it may be useful to use another way as well, so that 3 1 is the same as 1 3

+2
source share

All Articles