Storing single record app state

I am trying to store app state in my schema. By app state, I mean a type that has one record that is global state data for the app.

This is pretty simple to do, but since you cannot use a custom field as a UID, it means I have to either hard code an arbitrary UID number in the app, or keep doing upserts to find the UID when I want to update the state. I wanted to know if there is a better way to handle it. I suspect not, but it just feels janky.

That’s the only way. Do you have any examples in other DBs? I’m just curious about it.

Cheers.

1 Like

In other db, I’d just select * from the table, or just select PK = 1. But here we got randomized UID and can’t use our own field as a UID, so it makes it less direct and more arbitrary.

So, this global state is for a single user or for all?

For the entire app, covering all users. Just meta data to maintain the global state of the app (aka parameters, configuration).

Why not select a single UID, e.g 0x1, and force the use? that’s what I do. I start the cluster guaranteeing this UID for that purpose.

So every time you need to update it, you can use some(func: uid(0x1)) in an upsert mutation. Or just send an RDF mutation for that UID and it will be overwritten.

1 Like

Oh you mean update uid 0x1 forcing it to be the one chosen? That’s a good idea. That makes a lot more sense than making a new node and having 0x345h53 and having to put that in the app to look for.

1 Like

You can use another one. To not make it so obvious. Only you need to know that one is the one. And guarantee that no one has direct access to the DB. But using the raw UID is the fastest way of doing it.

2 Likes