It can be great to have a feature in Dgraph like in Postgre of unique indexes, so it looks something like this <node_iud> <edge_name> <unique_identifier> a great example can be the blog url slugs that acts like an identifier for the blog and is unique in the database
I think it can be possible since Dgraph now support transactions
Could be nice but no rush I think since one could use UID which are by definition unique... Otherwise, I do that with XID and implement de verification of uniqueness in my application layer.
This doesn't make much sense right now, given all the interaction with Dgraph is transactional. Once we support Cypher or other languages, where the query runs transactions implicitly, we could reconsider this.
+1 for this feature. I keep coming back to the conversation Here. As our app grows in complexity, and we load data from one dgraph instance into another, we need a check at the database level that certain predicate values are unique globally in the Dgraph instance. Currently, we check this with application logic, but in order to prevent data corruption and ensure product stability independent of any application bugs or ETL mistakes, we need the database to reject any transaction that violates uniqueness (specifically for us, it is uniqueness of an ExternalID predicate).
Same here. Each entity in the domain has a unique UUID. I wish dgraph to restrict uniqueness on the UUID term.
It might be even better if I could assign the external UUID to the internal UID. Maybe dgraph should be more agnostic to the format of the UID?
Is there a good example of doing this with transactions using the Go client?
https://github.com/ping40/dgraph-bench/tree/master/cmd/crud
this test case use : implement verification of uniqueness in my application layer.
but the result is not ok.
I want the name is uniqueness.
any suggest is appreciated , thanks
This sounds like an upsert directive, where we can use an index and txn conflicts to ensure that there'd only be one value in the predicate, for e.g. Login system, using uniqueness of email ids to identify users.
https://docs.dgraph.io/query-language/#upsert-directive
https://docs.dgraph.io/howto/#a-simple-login-system
This would work across almost all data types supported by Dgraph, string, int, float, etc. Closing this issue. If @upsert directive does not solve your needs, feel free to create a new issue, explaining what you are trying to do and why it doesn't work.
then this should be updated:
@danielmai ^
Most helpful comment
+1 for this feature. I keep coming back to the conversation Here. As our app grows in complexity, and we load data from one dgraph instance into another, we need a check at the database level that certain predicate values are unique globally in the Dgraph instance. Currently, we check this with application logic, but in order to prevent data corruption and ensure product stability independent of any application bugs or ETL mistakes, we need the database to reject any transaction that violates uniqueness (specifically for us, it is uniqueness of an ExternalID predicate).