Skip to content

db parameter in constraints Field is unergonomic #371

@ratzrattillo

Description

@ratzrattillo

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions