Module: Sequel::Postgres::PgLocation
- Defined in:
- lib/sequel/extensions/pg_location.rb
Instance Method Summary collapse
- #add_extension(name) ⇒ Object
- #add_location_trigger(table, op = {}) ⇒ Object
- #drop_extension(name) ⇒ Object
- #drop_location_trigger(table) ⇒ Object
Instance Method Details
#add_extension(name) ⇒ Object
4 5 6 7 |
# File 'lib/sequel/extensions/pg_location.rb', line 4 def add_extension(name) quoted_name = quote_identifier(name) if name run("CREATE EXTENSION IF NOT EXISTS #{quoted_name}") end |
#add_location_trigger(table, op = {}) ⇒ Object
14 15 16 17 |
# File 'lib/sequel/extensions/pg_location.rb', line 14 def add_location_trigger(table, op={}) self.run("CREATE FUNCTION update_#{table.to_s}_ll_point() RETURNS TRIGGER AS 'BEGIN NEW.#{op[:earth_point] || "ll_point"}=ll_to_earth(NEW.#{op[:latitude] || "latitude"}, NEW.#{op[:longitude] || "longitude"}); return NEW; END;' LANGUAGE plpgsql;") self.run("CREATE TRIGGER trigger_#{table.to_s}_ll_point BEFORE INSERT OR UPDATE ON #{table.to_s} FOR ROW EXECUTE PROCEDURE update_#{table.to_s}_ll_point();") end |
#drop_extension(name) ⇒ Object
9 10 11 12 |
# File 'lib/sequel/extensions/pg_location.rb', line 9 def drop_extension(name) quoted_name = quote_identifier(name) if name run("DROP EXTENSION IF EXISTS #{quoted_name}") end |
#drop_location_trigger(table) ⇒ Object
19 20 21 22 |
# File 'lib/sequel/extensions/pg_location.rb', line 19 def drop_location_trigger(table) self.run("DROP TRIGGER trigger_#{table.to_s}_ll_point ON #{table.to_s};") self.run("DROP FUNCTION update_#{table.to_s}_ll_point();") end |