Skip to content

Instantly share code, notes, and snippets.

@knowtheory
Created September 6, 2010 22:08
Show Gist options
  • Select an option

  • Save knowtheory/567567 to your computer and use it in GitHub Desktop.

Select an option

Save knowtheory/567567 to your computer and use it in GitHub Desktop.
require 'dm-core'
require 'dm-migrations'
require 'dm-timestamps'
require 'dm-sweatshop'
DataMapper.setup(:default, "[insert_path_here]")
class Widget
include DataMapper::Resource
property :id, Serial
property :nom, String
timestamps :at
end
DataMapper.auto_migrate!
Widget.fixture{{
:nom => /\w+/.gen,
:created_at => (DateTime.send(:today))
}}
(0..50).each{ |i| Widget.gen(:created_at=>(DateTime.send(:today) - i)) }
select * from widgets as t1 join widgets as t2 on
(date(t1.created_at) < date(t2.created_at) and
date(t2.created_at) <= (date(t1.created_at) + 10)) order by t2.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment