The documentation for setting constraints at https://memgraph.github.io/gqlalchemy/how-to-guides/ogm/#create-constraints shows, that a constraint has to be defined with a db parameter:
class Language(Node):
name: str = Field(unique=True, db=db)
This is not very ergonomic, as it requires all models to be defined in the same place, where the db connection is established.
It would be preferable to supply the db parameter in methods like save(db=db) or load(db=db) and not in the model definition itself.
Example:
# file model_definitions.py
class Language(Node):
name: str = Field(unique=True)
# file main.py
from model_definitions import Language
db = Memgraph()
Language(name="English").save(db=db)
The documentation for setting constraints at https://memgraph.github.io/gqlalchemy/how-to-guides/ogm/#create-constraints shows, that a constraint has to be defined with a db parameter:
This is not very ergonomic, as it requires all models to be defined in the same place, where the db connection is established.
It would be preferable to supply the db parameter in methods like
save(db=db)orload(db=db)and not in the model definition itself.Example: