Your First Query

Docs: query

Write your queries like normal:

q = Order.
  completed.
  where("order_date > ?", 30.days.ago).
  order("order_date DESC")

But run them with OccamsRecord:

orders = OccamsRecord.
  query(q).
  to_a

Now instead of bloated ActiveRecord objects, orders is an array of fast, small structs!

You may use any Enumerable method to run your query and iterate results:

OccamsRecord.query(q).each { |order| ... }
OccamsRecord.query(q).map { |order| ... }
OccamsRecord.query(q).reduce([]) { |acc, order| ... }

Batching

OccamsRecord provides find_each and find_in_batches methods that work similarly to their ActiveRecord counterparts.

OccamsRecord.query(q).find_each { |order|
  ...
}

OccamsRecord.query(q).find_in_batches { |orders|
  orders.each { |order|
    ...
  }
}

Using PostgreSQL? Consider using find_each_with_cursor or find_in_batches_with_cursor for a performance boost. See Cursors for more info.