memgraph / gqlalchemy

GQLAlchemy is a library developed with the purpose of assisting in writing and running queries on Memgraph. GQLAlchemy supports high-level connection to Memgraph as well as modular query builder.
https://pypi.org/project/gqlalchemy/
Apache License 2.0
227 stars 32 forks source link

Unique Constaints on multiple fields #248

Open ilyatbn opened 1 year ago

ilyatbn commented 1 year ago

considering the following Node class:

class DataSet(Node):
    id: str = Field(exists=True, db=connection)
    item_type: str = Field(exists=True, db=connection)
    ...

How do I make a unique constaint for both fields using the Node class?

I can achieve this manually by adding the following outside of the class:

connection.create_constraint(MemgraphConstraintUnique(label='DataSet', property=('id', 'item_type')))

If I set each field with a unique=True property the constraint is created separately for each field and I only want them to both be the same to be considered unique.

katarinasupe commented 1 year ago

Hi @ilyatbn, thank you for reporting this. It is impossible to specify multiple properties when creating uniqueness constraints by extending Node class. But I can see you managed to find the workaround! Thank you for pointing this out! I will leave this issue open so we can plan to add it as a feature. You are also more than welcome to contribute!

What are you working on?