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
Copy file name to clipboardExpand all lines: docs/how-to-guides/ogm.md
+41-3Lines changed: 41 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -395,19 +395,57 @@ To check which constraints have been created, run:
395
395
print(db.get_constraints())
396
396
```
397
397
398
+
## Using enums
399
+
400
+
Memgraph's built-in [enum data type](https://memgraph.com/docs/fundamentals/data-types#enum) can be utilized on your GQLAlchemy OGM models. GQLAlchemy's enum implementation extends Python's [enum support](https://docs.python.org/3.11/library/enum.html).
401
+
402
+
First, create an enum.
403
+
404
+
```python
405
+
from enum import Enum
406
+
407
+
classSubscriptionType(Enum):
408
+
FREE=1
409
+
BASIC=2
410
+
EXTENDED=3
411
+
```
412
+
413
+
Then, use the defined enum class in your model definition. Using the `Field` class, set the `enum` attribute to `True`. This will indicate that GQLAlchemy should treat the property value stored as a Memgraph enum. If the enum does not exist in the database, it will be created.
Enum types may be defined for properties on Nodes and Relationships.
423
+
424
+
!!! info
425
+
If the `Field` class specification on the property isn't specified, or if `enum` is explicitly set to `False`, GQLAlchemy will use the `value` of the enum member when serializing to a Cypher query. A corresponding enum will not be created in the database.
426
+
427
+
This functionality allows for flexiblity when using the Python `Enum` class, and would, for instance, respect an overridden `__getattribute__` method to customize the value passed to Cypher.
428
+
398
429
## Full code example
399
430
400
431
The above mentioned examples can be merged into a working code example which you can run. Here is the code:
401
432
402
433
```python
403
434
from gqlalchemy import Memgraph, Node, Relationship, Field
0 commit comments