@@ -375,16 +375,30 @@ def load_starting_with(
375375 start_after : Optional [str ] = None ,
376376 ) -> List [_T ]:
377377 load_starting_with_operation = LoadStartingWithOperation (self )
378- self .__load_starting_with_internal (
379- id_prefix , load_starting_with_operation , None , matches , start , page_size , exclude , start_after
378+ self ._load_starting_with_internal (
379+ id_prefix , load_starting_with_operation , matches , start , page_size , exclude , start_after
380380 )
381381 return load_starting_with_operation .get_documents (object_type )
382382
383- def __load_starting_with_internal (
383+ def load_starting_with_into_stream (
384+ self ,
385+ id_prefix : str ,
386+ matches : str = None ,
387+ start : int = 0 ,
388+ page_size : int = 25 ,
389+ exclude : str = None ,
390+ start_after : str = None ,
391+ ) -> bytes :
392+ if id_prefix is None :
393+ raise ValueError ("Arg 'id_prefix' is cannot be None." )
394+ return self ._load_starting_with_into_stream_internal (
395+ id_prefix , LoadStartingWithOperation (self ), matches , start , page_size , exclude , start_after
396+ )
397+
398+ def _load_starting_with_internal (
384399 self ,
385400 id_prefix : str ,
386401 operation : LoadStartingWithOperation ,
387- stream ,
388402 matches : str ,
389403 start : int ,
390404 page_size : int ,
@@ -395,12 +409,31 @@ def __load_starting_with_internal(
395409 command = operation .create_request ()
396410 if command :
397411 self ._request_executor .execute_command (command , self .session_info )
398- if stream :
399- pass # todo: stream
400- else :
401- operation .set_result (command .result )
412+ operation .set_result (command .result )
402413 return command
403414
415+ def _load_starting_with_into_stream_internal (
416+ self ,
417+ id_prefix : str ,
418+ operation : LoadStartingWithOperation ,
419+ matches : str ,
420+ start : int ,
421+ page_size : int ,
422+ exclude : str ,
423+ start_after : str ,
424+ ) -> bytes :
425+ operation .with_start_with (id_prefix , matches , start , page_size , exclude , start_after )
426+ command = operation .create_request ()
427+ bytes_result = None
428+ if command :
429+ self .request_executor .execute_command (command , self .session_info )
430+ try :
431+ result = command .result
432+ bytes_result = json .dumps (result .to_json ()).encode ("utf-8" )
433+ except Exception as e :
434+ raise RuntimeError ("Unable sto serialize returned value into stream" ) from e
435+ return bytes_result
436+
404437 def document_query_from_index_type (self , index_type : Type [_TIndex ], object_type : Type [_T ]) -> DocumentQuery [_T ]:
405438 try :
406439 index = Utils .try_get_new_instance (index_type )
@@ -456,6 +489,8 @@ def counters_for_entity(self, entity: object) -> SessionDocumentCounters:
456489 return SessionDocumentCounters (self , entity )
457490
458491 def time_series_for (self , document_id : str , name : str = None ) -> SessionDocumentTimeSeries :
492+ if not isinstance (document_id , str ):
493+ raise TypeError ("Method time_series_for expects a string. Did you want to call time_series_for_entity?" )
459494 return SessionDocumentTimeSeries (self , document_id , name )
460495
461496 def time_series_for_entity (self , entity : object , name : str = None ) -> SessionDocumentTimeSeries :
@@ -723,7 +758,7 @@ def lazily(self) -> LazySessionOperations:
723758 return self ._session ._lazily
724759
725760 def graph_query (self , object_type : type , query : str ): # -> GraphDocumentQuery:
726- pass
761+ raise NotImplementedError ( "Dropped support for graph queries" )
727762
728763 def what_changed (self ) -> Dict [str , List [DocumentsChanges ]]:
729764 return self ._session ._what_changed ()
@@ -781,32 +816,6 @@ def wait_for_indexes_after_save_changes(
781816
782817 index_options .wait_for_indexes = True
783818
784- def __load_starting_with_internal (
785- self ,
786- id_prefix : str ,
787- operation : LoadStartingWithOperation ,
788- stream : Union [None , bytes ],
789- matches : str ,
790- start : int ,
791- page_size : int ,
792- exclude : str ,
793- start_after : str ,
794- ) -> GetDocumentsCommand :
795- operation .with_start_with (id_prefix , matches , start , page_size , exclude , start_after )
796- command = operation .create_request ()
797- if command is not None :
798- self ._session ._request_executor .execute (command , self ._session .session_info )
799- if stream :
800- try :
801- result = command .result
802- stream_to_dict = json .loads (stream .decode ("utf-8" ))
803- result .__dict__ .update (stream_to_dict )
804- except IOError as e :
805- raise RuntimeError (f"Unable to serialize returned value into stream { e .args [0 ]} " , e )
806- else :
807- operation .set_result (command .result )
808- return command
809-
810819 def load_starting_with (
811820 self ,
812821 id_prefix : str ,
@@ -824,26 +833,14 @@ def load_starting_with(
824833 def load_starting_with_into_stream (
825834 self ,
826835 id_prefix : str ,
827- output : bytes ,
828836 matches : str = None ,
829837 start : int = 0 ,
830838 page_size : int = 25 ,
831839 exclude : str = None ,
832840 start_after : str = None ,
833- ):
834- if not output :
835- raise ValueError ("Output cannot be None" )
836- if not id_prefix :
837- raise ValueError ("Id prefix cannot be None" )
838- self .__load_starting_with_internal (
839- id_prefix ,
840- LoadStartingWithOperation (self ._session ),
841- output ,
842- matches ,
843- start ,
844- page_size ,
845- exclude ,
846- start_after ,
841+ ) -> bytes :
842+ return self ._session .load_starting_with_into_stream (
843+ id_prefix , matches , start , page_size , exclude , start_after
847844 )
848845
849846 def load_into_stream (self , keys : List [str ], output : bytes ) -> None :
0 commit comments