-
Notifications
You must be signed in to change notification settings - Fork 122
added return_fields function, attempting to optionally limit fields r… #633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Please add also exclude keyword, it'll be convenient |
Are u going to finish it guys? |
I tried to do it, and I found two main problems here:
|
- Move RETURN clause from query string to args list (fixes RediSearch syntax) - Rename internal parameter from return_fields to projected_fields to avoid conflict with method name - Return dictionaries instead of model instances when using field projection - Add proper parsing for projected results that returns flat key-value pairs - Add tests for both HashModel and JsonModel field projection - Update validation to use model_fields instead of deprecated __fields__ This addresses all review comments from PR #633 and implements field projection correctly.
3de85c9
to
8fc78fc
Compare
- Move RETURN clause from query string to args list (fixes RediSearch syntax) - Rename internal parameter from return_fields to projected_fields to avoid conflict with method name - Return dictionaries instead of model instances when using field projection - Add proper parsing for projected results that returns flat key-value pairs - Add tests for both HashModel and JsonModel field projection - Update validation to use model_fields instead of deprecated __fields__ This addresses all review comments from PR #633 and implements field projection correctly.
8fc78fc
to
5b91067
Compare
- Move RETURN clause from query string to args list (fixes RediSearch syntax) - Rename internal parameter from return_fields to projected_fields to avoid conflict with method name - Return dictionaries instead of model instances when using field projection - Add proper parsing for projected results that returns flat key-value pairs - Add tests for both HashModel and JsonModel field projection - Update validation to use model_fields instead of deprecated __fields__ This addresses all review comments from PR #633 and implements field projection correctly.
5b91067
to
b997389
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me... now 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Add Django-style .values() method to return query results as dictionaries: - .values() returns all fields as dicts - .values('field1', 'field2') returns specific fields as dicts - Uses Redis RETURN clause for efficient field projection - Extensible design supports future .only() method for partial models 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Refactored this feature to become a new |
Summary
Implements field projection capabilities for Redis OM queries, allowing users to retrieve only specific fields from models instead of
loading complete objects. This feature improves performance and reduces memory usage when working with large models or when only subset
of fields are needed.
New Features
.values()
Method - Dictionary ResultsReturns query results as dictionaries containing only the specified fields:
.only() Method - Partial Model Instances
Returns partial model instances that contain only the specified fields:
Advanced Features
Nested Field Access
Both methods support accessing nested fields using double underscore notation:
Type Conversion
Performance Optimizations
Implementation Details
Core Changes
Query Builder Integration
Both methods integrate seamlessly with existing query operations:
Customer.find(Customer.age > 25).sort_by("name").values("name", "email").all()
Customer.find().only("first_name").first()
Error Handling
Breaking Changes
None - this is an additive feature that maintains full backward compatibility.
Documentation
Fixes #568