Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/active_record/postgresql_cursors/cursors.rb,
lib/active_record/postgresql_cursors/cursors_2.rb
Class Method Summary collapse
- .cursor(*args) ⇒ Object
-
.find_with_cursors(*args) ⇒ Object
Override ActiveRecord::Base#find to allow for cursors in PostgreSQL.
Class Method Details
.cursor(*args) ⇒ Object
29 30 31 |
# File 'lib/active_record/postgresql_cursors/cursors_2.rb', line 29 def cursor(*args) find(:cursor, *args) end |
.find_with_cursors(*args) ⇒ Object
Override ActiveRecord::Base#find to allow for cursors in PostgreSQL. To use a cursor, set the first argument of find to :cursor. A PostgreSQLCursor object will be returned, which can then be used as an Enumerable to loop through the results.
By default, cursor names are generated automatically using “cursor_#rand”, where rand is a big ol’ random number that is pretty unlikely to clash if you’re using nested cursors. Alternatively, you can supply a specific cursor name by supplying a :cursor_name option.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_record/postgresql_cursors/cursors_2.rb', line 16 def find_with_cursors *args if args.first.to_s == 'cursor' = args. cursor_name = .delete(:cursor_name) () set_readonly_option!() find_cursor(cursor_name, ) else find_without_cursors(*args) end end |