Repository navigation
v0.2.5 - API Enhancement: Documents Getter
π― API Enhancement: Documents Getter for Better Developer Experience
Added Convenience API
- β
Added
documentsgetter to QueryResult - Provides direct access to query results using familiar API pattern - β
Enhanced developer experience - Developers can now use
result.documents.lengthas 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