Skip to content
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

Adds basic support for queries generated by #find_by_sql #33

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stevepolitodesign
Copy link
Contributor

Relates to #32

Allows exporting data that was generated by find_by_sql. This can be desirable when the caller is required to export a calculated field that is not stored directly on the table as demonstrated below.

User.find_by_sql("SELECT id, 'custom_value' AS custom_field FROM users")
ArtVandelay::Export.new(export).csv

As such, this feature does not support the in_batches_of option, since
that would be the responsibility of the query.

This feature also does not (yet) support the attributes option.

Relates to #32

Allows exporting data that was generated by [find_by_sql][]. This can be desirable when the caller is required to export a calculated field that is not stored directly on the table as demonstrated below.

```ruby
User.find_by_sql("SELECT id, 'custom_value' AS custom_field FROM users")
ArtVandelay::Export.new(export).csv
```

As such, this feature does not support the `in_batches_of` option, since
that would be the responsibility of the query.

This feature also does not (yet) support the `attributes` option.

[find_by_sql]: https://api.rubyonrails.org/classes/ActiveRecord/Querying.html#method-i-find_by_sql
The previous commit failed to account for the case where `#find_by_sql`
returns no results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant