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.
You should create a python file called social_network.py
, and a folder called helixdb-cfg
with
a query helix file called queries.hx
, and a schema helix file called schema.hx
.
The helix queries go in helixdb-cfg/queries.hx
and the python code goes in social_network.py
.
Step 0: Import HelixDB
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 a 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.