--- title: Itembase keywords: fastai sidebar: home_sidebar nb_path: "nbs/itembase.ipynb" ---
Any data class in pymemri inherits from Item
. It is a base class for items with some handy functionalities to create new items and edges, retrieve all edges to other items, and sync with the pod.
ITEMBASE_PROPERTIES = ["dateAccessed", "dateCreated", "dateModified", "deleted", "externalId", "itemDescription",
"starred", "version", "id", "importJson", "name", "repository", "icon", "bundleImage",
"runDestination", "pluginClass"]
With the Item
and Edge
classes we can create an item and its surrounding graph. The schema is defined in schema.py, in general we want to use the from_data staticmethod to generate new items, because it ensures that edges are linked from both the source and the target object. Let's make a new item and add it to the pod.
class MyItem(Item):
properties = Item.properties + ["name", "age"]
edges = Item.edges + ["friend"]
def __init__(self, name=None, age=None,friend=None, **kwargs):
super().__init__(**kwargs)
self.name = name
self.age = age
self.friend = fried if friend is not None else []
from pymemri.pod.client import PodClient
client = PodClient()
assert client.add_to_schema(MyItem(name="abc", age=1))
x = MyItem(name="me", age=30)
x.add_edge("friend", MyItem(name="my friend", age=31))
x.add_edge("friend", MyItem(name="my friend2", age=32))
We can now create our MyItem
, as a side-effect of creating it, it will receive an id
print(x.id)
assert client.create(x)
print(x.id)
y = client.get(x.id)
assert len(y.friend) > 0
y.friend[0].name