You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This class represents a node with the labels `Beverage` and `Hot`. Notice that the labels
90
-
of this model are explicitly defined in the `Settings` class.
89
+
This class represents a node with the labels `Beverage` and `Hot`. Notice
90
+
that the labels of this model are explicitly defined in the `Settings` class.
91
91
"""
92
92
flavor: str
93
93
sugar: bool
@@ -106,12 +106,13 @@ class Coffee(NodeModel):
106
106
107
107
classConsumed(RelationshipModel):
108
108
"""
109
-
Unlike the models above, this class represents a relationship between two nodes. In this case,
110
-
it represents the relationship between the `Developer` and `Coffee` models. Like with node-models,
111
-
the `Settings` class allows us to define some settings for this relationship.
109
+
Unlike the models above, this class represents a relationship between two
110
+
nodes. In this case, it represents the relationship between the `Developer`
111
+
and `Coffee` models. Like with node-models, the `Settings` class allows us to
112
+
define some settings for this relationship.
112
113
113
-
Note that the relationship itself does not define it's start- and end-nodes, making it reusable
114
-
for other models as well.
114
+
Note that the relationship itself does not define it's start- and end-nodes,
115
+
making it reusable for other models as well.
115
116
"""
116
117
liked: bool
117
118
@@ -122,7 +123,7 @@ class Consumed(RelationshipModel):
122
123
The models above are pretty straight forward. They are basically just `Pydantic` models with some sugar on top, though there are some special things to note:
123
124
124
125
- We are defining some model-specific settings inside the `Settings` class. These settings are used by `pyneo4j-ogm` to determine how to handle the model. For example, the `labels` setting of the `Coffee` model tells `pyneo4j-ogm` that this model should have the labels `Beverage` and `Hot` inside the graph. The `type` setting of the `Consumed` model tells `pyneo4j-ogm` that this relationship should have the type `CHUGGED` inside the graph.
125
-
- We are defining a `post_hook` for the `coffee` relationship of the `Developer` model. This hook will be called whenever a `Coffee` node is connected to a `Developer` node via the `coffee` relationship.
126
+
- We are defining a `post_hook` for the `coffee` relationship of the `Developer` model. This hook will be called whenever a `Coffee` node is connected to a `Developer` node via the `coffee` relationship-property.
126
127
- We are defining a `uniqueness constraint` for the `uid` field of the `Developer` model. This will create a uniqueness constraint inside the graph for the `uid` field of the `Developer` model. This means that there can only be one `Developer` node with a specific `uid` inside the graph.
127
128
128
129
Now that we have our models defined, we can initialize a `Pyneo4jClient` instance that will be used to interact with the database. The client will handle most of the heavy lifting for us and our models, so let's initialize a new one and connect to the database:
@@ -133,14 +134,13 @@ from pyneo4j_ogm import Pyneo4jClient
133
134
asyncdefmain():
134
135
# We initialize a new `Pyneo4jClient` instance and connect to the database.
You can control the log level and whether to log to the console ornot by setting the `PYNEO4J_OGM_LOG_LEVEL`and`PYNEO4J_OGM_ENABLE_LOGGING`as environment variables. The available levels are the same as provided by the build-in`logging` module. The default log level is`WARNING`and logging to the console is enabled by default.
0 commit comments