“The ability to ask nodes based on their relationship … In order to traverse direct and indirect connections … it remains a key concern for potential users.”
Developers wanted something more than just bringing nodes according to their properties. They wanted to ask elaborate questions about the data chart, such as “Find all articles written by users who are friends of” Alice “. This is a classic problem with the chart, and for a database such as Genosdb was a fascinating challenge.
In the case of P2P, a decentralized database, every byte sent by the network matters. An easy solution enabling the relationship was to “irrigate” our edges, settling full nodes in each connection. However, this would be a catastrophic choice, flatulence, network packages and a low delay performance destruction, which is the basic principle of Genosdb.
Our design philosophy is clear: the edge table in the node must remain lists of IDs IDs of Hyper-light. Nothing more.
So the challenge was established:
The answer was smarter to make our question engine. Much smarter.
Today we are excited about the announcement of a new, recursive $ EDGE operator. It is an elegant, powerful addition to our questionnaire that allows you to go through the chart During the query processEverything, while maintaining a slim and fast layer of the network.
The $ Edge operator lives completely in the question engine. He uses the chart in memory to track light references ID, performing the “Join” logic during the inquiry, not during synchronization. The result is the experience of the server side with P2P network performance on the client’s side.
Let’s see it in action. Imagine you want to find all posts written by users who have been banned.
Without $ Edge it would be a multi -stage manual process. With $ edge, this is one, declarative inquiry:
JavaScript code
Download content_copyexpand_less
// Find all Posts linked to a User with status: 'banned'
const { results } = await db.map({
query: {
// 1. Start with nodes of type 'Post'
"type": "Post",// 2. Add the relational condition
"$edge": {
// 3. Define the properties of the node at the other end of the edge
"target": {
"type": "User",
"status": "banned"
}
}
}
});
Let’s break this:
- We start searching with all nodes in which the type is post.
- The $ Edge operator says Genosdb: “Look at the knots with which it connects to each of these posts.”
- The target object defines the conditions that the connected node must meet. In this case, it must be a user with a prohibition status.
It is immaculate, intuitive and incredibly powerful.
But what about the problem of “Friends of Friends”? The recursive nature of $ edge really shines here. You can nest $ Edge operators to create queries about many hops about arbitrary depth.
Let’s find all posts written by “Alice” friends:
// Find all Posts where the author is a friend of Alice
const { results } = await db.map({
query: {
"type": "Post",
// Level 1: Follow the edge from the Post to its author
"$edge": {
"target": {
"type": "User",
// Level 2: From that author, follow the edge to their friends
"$edge": {
"target": {
"type": "User",
"name": "Alice"
}
}
}
}
}
});
This single query makes a complex, two -level displacement on the chart, solving a problem that would otherwise require a significant manual code, everything while maintaining a zero promise on the head.
We knew that this function must be solid. To prove this, we designed the extreme conditions test: a chart with a 51 knot line chain, requiring a query from 50 nested EDGE operators Travel from beginning to end.
Result?
The question engine has solved the entire 50-level deep path in Miliseconds, which proves that recursive implementation is not only correct, but also highly efficient and free from typical problems, such as stack overflow.
Listening to our community, we were forced to solve a difficult problem in a way that honors our involvement in performance and minimalism. The $ edge operator is more than a new feature; This is a testimony of our philosophy of building powerful tools that stay on your part.
It transforms the user’s key concern into one of the most powerful GenosdB functions.
We invite you to investigate modern accessories and see what you can build.
- Find us on GitHub: https://github.com/estebanrfp/gdb
- Read the documents: Check the updated documentation more examples.
- Experiment: Use our live playgrounds to test it yourself!
Happy coding
Genosendb