Skip to content

v0.2.5 - API Enhancement: Documents Getter

Choose a tag to compare

@pillowsoft pillowsoft released this 10 Sep 00:17
· 13 commits to main since this release

🎯 API Enhancement: Documents Getter for Better Developer Experience

Added Convenience API

  • βœ… Added documents getter to QueryResult - Provides direct access to query results using familiar API pattern
  • βœ… Enhanced developer experience - Developers can now use result.documents.length as expected
  • βœ… Backward compatibility - Existing result.data?['collection'] API continues to work unchanged
  • βœ… Smart collection detection - Automatically returns documents from the first collection in query result

Technical Implementation

  • βœ… First collection fallback - Returns documents from the first collection when multiple collections exist
  • βœ… Safe empty list handling - Returns empty list for loading, error, or null data states
  • βœ… Type safety - Ensures all returned items are properly typed as Map<String, dynamic>

Impact

This release solves an API discrepancy where developers expected a documents field on QueryResult but had to use the more verbose result.data?['collection'] pattern. Now both approaches work:

New convenient API:

final result = db.query({'conversations': {}}).value;
print('Returned ${result.documents.length} documents');

Existing API (still works):

final conversations = result.data?['conversations'] as List? ?? [];
print('Returned ${conversations.length} conversations');

For Developers

If you were accessing a non-existent documents field and getting 0 results, update to v0.2.5 and your code will work as expected!

Installation:

dependencies:
  instantdb_flutter: ^0.2.5