A basic example
A basic example of how to use HelixDB
We’re going to create a simple social network where users can follow each other and create posts.
Step 1: Define the schema in schema.hx
We’re going to define the schema for our social network in schema.hx
.
We’re going to have User
nodes where users can Follow
other users.
We’re also going to have Post
nodes where users can Create
posts.
Step 2: Inserting data
Creating a user is done by inserting a new node into the graph.
To let users follow another user, we need to create an edge between them.
To create a post, we need to create a post node and an edge between the user and the post.
Step 3: Query the data
To get all users, we can use the following query:
To get all posts, we can use the following query:
To get all posts by a user, we can use the following query:
To get all users that a user follows, we can use the following query:
As a more complex example, we could have a query that loads an page containing the posts of users that a user follows. To do this we are going to remap the posts to have a field containing information about the user that created the post.