Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PostGis and Ruby

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

PostGis and Ruby

A lightning talk on using PostGis in a Ruby stack.

Avatar for AndyDangerous

AndyDangerous

November 19, 2015

Other Decks in Technology

Transcript

  1. The Solution • Database table/view optimization • JSONB • Basic

    spatial functionality • Compose query using Ruby
  2. MOAR Code scope :participating, lambda { |doc_groups| groups = “‘#{doc_groups.join("','")}'"

    where( "doctor_group ?| array[#{groups}] OR hospital_group ?| array[#{groups}]” ) } scope :awesome_doctors, lambda { select( "(CASE WHEN doctor_rating ?| array['awesome'] THEN 1 ELSE 2 END) as awesome” ).order("awesome") }
  3. Do you even PostGIS? scope :within, lambda { |lat, lng,

    radius| select( "ST_DWithin( the_geom, ST_GeomFromText('POINT(#{lng} #{lat})', 4326)::geography, #{radius})") }