Skip to content

Conversation

@stevepolitodesign
Copy link
Contributor

@stevepolitodesign stevepolitodesign commented Jun 26, 2024

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.

export = 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.

2 participants