Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load() doesn't work without default or Optional #79

Closed
katarinasupe opened this issue Jan 20, 2022 · 2 comments · Fixed by #103
Closed

Load() doesn't work without default or Optional #79

katarinasupe opened this issue Jan 20, 2022 · 2 comments · Fixed by #103

Comments

@katarinasupe
Copy link
Contributor

It would be great that the load() method works if we add only one property upon which object in Memgraph is found.

For example, let's say we have defined Stream class like this:

class Stream(Node, labels={"User", "Stream"}):
    name: str = Field(index=True, unique=True, db=memgraph, label="User")
    id: str = Field(index=True, unique=True, db=memgraph)
    url: str = Field()
    followers: int = Field()
    createdAt: str = Field()
    totalViewCount: int = Field()
    description: str = Field()

Now, let's suppose I want to find a streamer based on its id (which is unique). I expect that stream = Stream(id="7").load(db=memgraph) returns Stream whose id is "7". That does not work, because it's expected that I give value for all properties of class Stream. This can be solved by adding default value ("") to each property, or by using Optional for now.

@MasterMedo
Copy link
Contributor

I'm thinking we could create a class PartialNode and PartialRelationship that would be used for this purpose: loading real data into a user defined class.

@MasterMedo
Copy link
Contributor

MasterMedo commented Jan 26, 2022

Hm, after giving it some thought, we don't need to create anything. The class Node should work for this purpose.

stream = memgraph.load_node(Node(
    id="7",
    _label="Stream"
))

This will return an instance of Stream. If you were to do a Node(...).load(db=memgraph) you would have gotten an instance of Node.

I think this is plenty good for this use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants