Handmade Network»Forums
65 posts
Graph Database
Edited by Shastic on

I do not like the query language of SQL. I find it hard to understand, for a subject that is very dry. Then I found this webpage where instead of using tables for database they use graphs.

https://www.graphable.ai/blog/what-is-a-graph-database/

There is something about this representation that is easy for me to understand. I have a graph module that is used for path finding, and with minor modification, I turned it into a simple graph database, and do queries on it using C functions. Good enough for a single player game.

Casey covered database on twitch, but I did not see it. I am not on twitch, because their web programming is very bad. I assume Casey used tables.

Just thought I'd mention it, in case anyone didn't know about them.

Simon Anciaux
1241 posts
Graph Database

The link is missing a w in www and the end of the link might contain some id that you might want to remove (anything after the final slash can be removed).

65 posts
Graph Database
Edited by Shastic on

Thanks Simon. Fixed.

Ben Visness
106 posts / 6 projects
HMN lead.
Graph Database
Edited by Ben Visness on

I’m very annoyed by that article. A “graph database” is obviously just a relational database with a different query language. The same principles of data organization are exactly the same.

I certainly realize there are problems with SQL, but this article totally misidentifies them (e.g. “rigidly stored data”, an extremely stupid notion). It’s not really surprising given that this is just content marketing for a company cashing in on GraphQL’s hype though.

Build new query languages all you want, but don’t go parading it around like a fundamentally different thing.

(If I’m wrong about Neo4j and it actually does something interesting on the data storage side, correct me. But it sure doesn’t look like it…relational data storage is about as simple and effective as it gets.)

65 posts
Graph Database
Edited by Shastic on
Replying to bvisness (#26679)

I didn't notice they had a product. I read it like I would a tutorial without code on the net.

The data structures I copied from Buckland. I got rid of all the C++ junk, and added hashing for the nodes and edges.

I assume SQL can do a lot more, but this is all I need.

typedef struct
{
        /* Every node has an index. A valid index is >= 0 */
        uint32_t Index;

        point_int32 Pos;

        /* Node string goes here */         
        void *ExtraInfo;

        hash32_query_link HashQueryLink;
}
graph_node;

#define GRAPH_NODE_INVALID_INDEX UINT32_MAX

typedef struct
{
        /* An edge connects two nodes. */
        uint32_t From, To;

        /* Edge relationship code */
        int Relationship;

        /* The cost of traversing this edge */
        double Cost;

        /* 
         * If this edge intersects with an object,
         * such as a door or lift,
         * then this is that object's Id. 
         */
        int IdOfIntersectingEntity;

        hash32_query_link HashQueryLink;
}
graph_edge;


typedef struct
{
        /* Is this to be used as a database? */
        bool IsDatabase;

        /* Is this a directed graph? */
        bool IsDigraph;

        /* Each node gets a unique id */
        uint32_t NextNodeIndex;

        /* The nodes that comprise this graph */
        array Nodes;

        /* 
         * Nodes are hashed by Pos for pathfinding,
         * or by ExtraInfo for database.
         */
        hash32_query NodeHash;

        pool EdgePool;

        /* 
         * Each edge is hashed
         * using its parent node's From index
         */
        hash32_query EdgeHash;

        /* Stores node or edge ptrs found by hash queries. */
        array FoundArray1, FoundArray2;
}
sparse_graph;
65 posts
Graph Database
Edited by Shastic on

I just found where Casey discusses database, and it is similar to what was discussed here. I didn't think he covered database in the HMH game, so I didn't think to search there. Silly me.

https://guide.handmadehero.org/code/day445/#796