@@ -146,16 +146,18 @@ def find(
146146 filters : 'FilterType' | None = None ,
147147 order_by : 'OrderByType' | None = None ,
148148 limit : int | None = None ,
149+ offset : int | None = None ,
149150 ) -> list [EntityType ]:
150151 """Find collection entries matching the filter criteria.
151152
152153 :param filters: the keyword value pair filters to match
153154 :param order_by: a list of (key, direction) pairs specifying the sort order
154155 :param limit: the maximum number of results to return
156+ :param offset: number of initial results to be skipped
155157
156158 :return: a list of resulting matches
157159 """
158- query = self .query (filters = filters , order_by = order_by , limit = limit )
160+ query = self .query (filters = filters , order_by = order_by , limit = limit , offset = offset )
159161 return query .all (flat = True )
160162
161163 def all (self ) -> list [EntityType ]:
@@ -227,7 +229,7 @@ def model_to_orm_field_values(cls, model: Model) -> dict[str, Any]:
227229
228230 return fields
229231
230- def _to_model (self , repository_path : Path | None = None ) -> Model :
232+ def to_model (self , repository_path : Path | None = None ) -> Model :
231233 """Return the entity instance as an instance of its model."""
232234 fields = {}
233235
@@ -240,16 +242,17 @@ def _to_model(self, repository_path: Path | None = None) -> Model:
240242 return self .Model (** fields )
241243
242244 @classmethod
243- def _from_model (cls : type [EntityType ], model : Model ) -> EntityType :
245+ def from_model (cls : type [EntityType ], model : Model ) -> EntityType :
244246 """Return an entity instance from an instance of its model."""
245247 fields = cls .model_to_orm_field_values (model )
246248 return cls (** fields )
247249
248- def serialize (self , repository_path : Path | None = None ) -> dict [str , Any ]:
250+ def serialize (self , repository_path : Path | None = None , serialize_files : bool = False ) -> dict [str , Any ]:
249251 """Serialize the entity instance to JSON.
250252
251253 :param repository_path: If the orm node has files in the repository, this path is used to dump the repository
252254 files to. If no path is specified a temporary path is created using the entities pk.
255+ :param serialize_files: Whether to include files in the serialization. If False, only metadata is serialized.
253256 """
254257 self .logger .warning (
255258 'Serialization through pydantic is still an experimental feature and might break in future releases.'
@@ -264,15 +267,19 @@ def serialize(self, repository_path: Path | None = None) -> dict[str, Any]:
264267 raise ValueError (f'The repository_path `{ repository_path } ` does not exist.' )
265268 if not repository_path .is_dir ():
266269 raise ValueError (f'The repository_path `{ repository_path } ` is not a directory.' )
267- return self ._to_model (repository_path ).model_dump ()
270+
271+ exclude = set ()
272+ if not serialize_files :
273+ exclude .add ('repository_content' )
274+ return self .to_model (repository_path ).model_dump (exclude = exclude )
268275
269276 @classmethod
270277 def from_serialized (cls : type [EntityType ], ** kwargs : dict [str , Any ]) -> EntityType :
271278 """Construct an entity instance from JSON serialized data."""
272279 cls ._logger .warning (
273280 'Serialization through pydantic is still an experimental feature and might break in future releases.'
274281 )
275- return cls ._from_model (cls .Model (** kwargs )) # type: ignore[arg-type]
282+ return cls .from_model (cls .Model (** kwargs )) # type: ignore[arg-type]
276283
277284 @classproperty
278285 def objects (cls : type [EntityType ]) -> CollectionType : # noqa: N805
0 commit comments