Skip to content

Instantly share code, notes, and snippets.

@stravid
Created June 3, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stravid/f6e8c648df1284c82e94 to your computer and use it in GitHub Desktop.
Save stravid/f6e8c648df1284c82e94 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'bundler/setup'
require 'rom'
require 'rom-sql'
ROM.setup(:sql, 'postgres://localhost/datsu_development')
class Players < ROM::Relation[:sql]
register_as :players
dataset :players
def with_throws
inner_join(:throws, player_id: :id)
end
end
class Matches < ROM::Relation[:sql]
register_as :matches
dataset :matches
end
class Throws < ROM::Relation[:sql]
register_as :throws
dataset :throws
def for_users(users)
where(player_id: users.map { |user| user[:id] })
end
end
ROM.finalize
rom = ROM.env
puts rom.relation(:players).to_a
puts '---'
puts rom.relation(:players).combine(rom.relation(:throws).for_users).to_a
puts '---'
puts rom.relation(:players).with_throws.to_a
puts '---'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment