def find_cursor(cursor_name, options)
        unless connection.is_a? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
          raise CursorsNotSupported, "#{connection.class} doesn't support cursors"
        end

        relation = merge(options.slice(:readonly, :references, :order, :limit, :joins, :group, :having, :offset, :select, :uniq))
        including = (relation.eager_load_values + relation.includes_values).uniq

        if including.present?
          join_dependency = construct_join_dependency(joins_values)

          aliases = join_dependency.aliases
          join_relation = select(aliases.columns)
          join_relation = apply_join_dependency(join_relation, join_dependency)

          ActiveRecord::PostgreSQLCursor.new(self, cursor_name, join_relation, join_dependency)
        else
          ActiveRecord::PostgreSQLCursor.new(self, cursor_name, relation)
        end
      end
def find_cursor(cursor_name, options)
        unless connection.is_a? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
          raise CursorsNotSupported, "#{connection.class} doesn't support cursors"
        end

        relation = merge(options.slice(:readonly, :references, :order, :limit, :joins, :group, :having, :offset, :select, :uniq))
        including = (relation.eager_load_values + relation.includes_values).uniq

        if including.present?
          join_dependency = construct_join_dependency(joins_values)

          aliases = join_dependency.aliases
          join_relation = select(aliases.columns)
          join_relation = apply_join_dependency(join_relation, join_dependency)

          ActiveRecord::PostgreSQLCursor.new(self, cursor_name, join_relation, join_dependency)
        else
          ActiveRecord::PostgreSQLCursor.new(self, cursor_name, relation)
        end
      end
Find method for using cursors. This works just like the regular
 ActiveRecord::Base#find_every method, except it returns a
 PostgreSQLCursor object that can be used to loop through records.