@@ -152,16 +152,18 @@ def find(
152152 filters : 'FilterType' | None = None ,
153153 order_by : 'OrderByType' | None = None ,
154154 limit : int | None = None ,
155+ offset : int | None = None ,
155156 ) -> list [EntityType ]:
156157 """Find collection entries matching the filter criteria.
157158
158159 :param filters: the keyword value pair filters to match
159160 :param order_by: a list of (key, direction) pairs specifying the sort order
160161 :param limit: the maximum number of results to return
162+ :param offset: number of initial results to be skipped
161163
162164 :return: a list of resulting matches
163165 """
164- query = self .query (filters = filters , order_by = order_by , limit = limit )
166+ query = self .query (filters = filters , order_by = order_by , limit = limit , offset = offset )
165167 return query .all (flat = True )
166168
167169 def all (self ) -> list [EntityType ]:
@@ -233,7 +235,7 @@ def model_to_orm_field_values(cls, model: Model) -> dict[str, Any]:
233235
234236 return fields
235237
236- def _to_model (self , repository_path : Path | None = None ) -> Model :
238+ def to_model (self , repository_path : Path | None = None ) -> Model :
237239 """Return the entity instance as an instance of its model."""
238240 fields = {}
239241
@@ -246,16 +248,17 @@ def _to_model(self, repository_path: Path | None = None) -> Model:
246248 return self .Model (** fields )
247249
248250 @classmethod
249- def _from_model (cls : type [EntityType ], model : Model ) -> EntityType :
251+ def from_model (cls : type [EntityType ], model : Model ) -> EntityType :
250252 """Return an entity instance from an instance of its model."""
251253 fields = cls .model_to_orm_field_values (model )
252254 return cls (** fields )
253255
254- def serialize (self , repository_path : Path | None = None ) -> dict [str , Any ]:
256+ def serialize (self , repository_path : Path | None = None , serialize_files : bool = False ) -> dict [str , Any ]:
255257 """Serialize the entity instance to JSON.
256258
257259 :param repository_path: If the orm node has files in the repository, this path is used to dump the repository
258260 files to. If no path is specified a temporary path is created using the entities pk.
261+ :param serialize_files: Whether to include files in the serialization. If False, only metadata is serialized.
259262 """
260263 self .logger .warning (
261264 'Serialization through pydantic is still an experimental feature and might break in future releases.'
@@ -270,15 +273,19 @@ def serialize(self, repository_path: Path | None = None) -> dict[str, Any]:
270273 raise ValueError (f'The repository_path `{ repository_path } ` does not exist.' )
271274 if not repository_path .is_dir ():
272275 raise ValueError (f'The repository_path `{ repository_path } ` is not a directory.' )
273- return self ._to_model (repository_path ).model_dump ()
276+
277+ exclude = set ()
278+ if not serialize_files :
279+ exclude .add ('repository_content' )
280+ return self .to_model (repository_path ).model_dump (exclude = exclude )
274281
275282 @classmethod
276283 def from_serialized (cls : type [EntityType ], ** kwargs : dict [str , Any ]) -> EntityType :
277284 """Construct an entity instance from JSON serialized data."""
278285 cls ._logger .warning (
279286 'Serialization through pydantic is still an experimental feature and might break in future releases.'
280287 )
281- return cls ._from_model (cls .Model (** kwargs )) # type: ignore[arg-type]
288+ return cls .from_model (cls .Model (** kwargs )) # type: ignore[arg-type]
282289
283290 @classproperty
284291 def objects (cls : type [EntityType ]) -> CollectionType : # noqa: N805
0 commit comments