If you're used to using raw SQL to find database records, then you will generally find that there are better ways to carry out the same operations in Rails.
Active Record insulates you from the need to use SQL in most cases.
Code examples throughout this guide will refer to one or more of the following models: Active Record will perform queries on the database for you and is compatible with most database systems, including My SQL, Maria DB, Postgre SQL and SQLite.
To retrieve objects from the database, Active Record provides several finder methods.
Each finder method allows you to pass arguments into it to perform certain queries on your database without writing raw SQL.
The methods are: in a single pass, build a model object per row, and then keep the entire array of model objects in memory.
Indeed, if we have a large number of records, the entire collection may exceed the amount of memory available.
Rails provides two methods that address this problem by dividing records into memory-friendly batches for processing.
The first method, methods are intended for use in the batch processing of a large number of records that wouldn't fit in memory all at once.
If you just need to loop over a thousand records the regular find methods are the preferred option.
option allows you to configure the first ID of the sequence whenever the lowest ID is not the one you need.
This would be useful, for example, if you wanted to resume an interrupted batch process, provided you saved the last processed ID as a checkpoint.