@@ -384,7 +384,7 @@ func (c *Client) AllKeys(ctx context.Context, q *Query) ([]*Key, error) {
384384}
385385
386386// GetAll retrieves all entities matching the query and stores them in dst.
387- // dst must be a pointer to a slice of structs.
387+ // dst must be a pointer to a slice of structs, or nil for KeysOnly queries .
388388// Returns the keys of the retrieved entities and any error.
389389// This matches the API of cloud.google.com/go/datastore.
390390func (c * Client ) GetAll (ctx context.Context , query * Query , dst any ) ([]* Key , error ) {
@@ -431,6 +431,21 @@ func (c *Client) GetAll(ctx context.Context, query *Query, dst any) ([]*Key, err
431431 return nil , fmt .Errorf ("failed to parse response: %w" , err )
432432 }
433433
434+ // For KeysOnly queries, dst can be nil - just return keys
435+ if query .keysOnly && dst == nil {
436+ keys := make ([]* Key , 0 , len (result .Batch .EntityResults ))
437+ for _ , er := range result .Batch .EntityResults {
438+ key , err := keyFromJSON (er .Entity ["key" ])
439+ if err != nil {
440+ c .logger .ErrorContext (ctx , "failed to parse key from response" , "error" , err )
441+ return nil , err
442+ }
443+ keys = append (keys , key )
444+ }
445+ c .logger .DebugContext (ctx , "keys-only query completed successfully" , "kind" , query .kind , "keys_found" , len (keys ))
446+ return keys , nil
447+ }
448+
434449 // Verify dst is a pointer to slice
435450 v := reflect .ValueOf (dst )
436451 if v .Kind () != reflect .Ptr || v .Elem ().Kind () != reflect .Slice {
0 commit comments