https://github.com/mojotech/batchelor
Override find_in_batches and find_each in ActiveRecord decendant classes that do not have an integer primary key as these will not work when using PostgreSQL.
https://github.com/mojotech/batchelor
Last synced: 6 months ago
JSON representation
Override find_in_batches and find_each in ActiveRecord decendant classes that do not have an integer primary key as these will not work when using PostgreSQL.
- Host: GitHub
- URL: https://github.com/mojotech/batchelor
- Owner: mojotech
- Created: 2012-11-09T20:48:48.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-11-09T21:24:41.000Z (over 13 years ago)
- Last Synced: 2025-10-13T06:48:49.919Z (10 months ago)
- Size: 145 KB
- Stars: 1
- Watchers: 48
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Batchelor
=========
Override find\_in\_batches and find\_each in ActiveRecord decendant classes that do not have an integer primary key as these will not work when using PostgreSQL.
Usage
=====
Very simply run `gem install batchelor` or include `gem 'batchelor'` in your app's `Gemfile`. Then if you have a class that has a non-integer primary key, just add `extend Batchelor` to the class definition and you can use `find_in_batches` and `find_each` by extension.
Caveats
=======
I have been told that the reason this is **not** in Rails is because `find_in_batches` and `find_each` are expected to process any new records that are created while the block is running. This will happen for incrementing integer primary keys but is not guaranteed for strings. This is just to give you a convenient and query efficient way to iterate over all records of a model with a non integer primary key.
Sqlite (and maybe other databases) will actually let you use the `>=` operator on strings so this gem isn't necessary when using it.
Credits
==========
[](http://www.mojotech.com)
License
==========
Batchelor is Copyright © 2012 MojoTech, LLC. and is released under the MIT license.