Regarding queries as compared to SQL

I’m coming from PHP/SQL, so I’m used to statements such as:
SELECT name FROM authors WHERE alive = true;

Is there something like this available on this system? I know that a “variable start” is needed in the form of:
(xid: Isaac Asimov) { alive }

So how would I get all authors that have alive set to true?
If the answer is to set the xid to “alive”, how would I add that as an external id? Is that even possible?
So something like:
(xid: alive) { name }

Would I then have to have all of my mutations use the subject of “alive” rather than “name”? Or can I somehow add “alive” as an index (again, coming from SQL, so not sure of the proper naming conventions).

I believe I was thinking about this in the wrong way. If I write:
mutation {set { “Alice” }}
then is the XID. So I guess my question is: how do I work with “tables” in Dgraph? I think they’re called “nodes”.

For example, if I had a relational database with the tables “users” and “tickets” and wanted to add a user and some tickets and relate the tickets to a user I would use a third table that uses unique IDs (aptly named “id”).
For a graph database it seems like I would need to set that ID manually somehow without doing a lookup of many users to see if it was already being used- fair enough for a small data set; perhaps a full name would suffice, but how would you check that against a very large database to be sure that name wasn’t already in use? I think this is where UIDs come in to play, but I’m not sure how to get that return information so I can then use it, or if I even have to. I think it’s pretty clear that I’m fumbling around in the dark.

I think Dgraph is unique enough to where these things need to be addressed for us lowly web developers that have only used relational databases in the past. Scouring the internet for resources and trying to apply the theory in Dgraph has left me almost exactly where I started, except now I have more questions.

How would you translate related tables to the graph way of doing things?

Update: Here’s a starting point that will help people understand graph:

In Graph systems, the presence of something = true. So, if you have an edge coming out of the entity with alive as the predicate, then that should be sufficient. Provided you set the data right, you could query it like so:

{ me(xid: isaac) { alive }}
If this returns any results, then he’s alive. Otherwise, not.

So, now if you want to find all authors who’re alive and you have edges like:

<author> <instance> <person> .
<person> <alive> "true" .

Then you can find all alive authors like so:

{ me(_xid_: author) { instance { alive }}}

This would give you all authors, and then have the alive bit for all the ones who’re alive.

So, for the database, user and ticket. This is how you could set it up.

<user> <name> "User Name" .
<user> <has> <ticketid0> .
<user> <has> <ticketid1> .

You haven’t mentioned the queries that you want to run. But, this seems like it should give you what you want.

Thanks, you’ve given me something to think about.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.