18 lines
542 B
Ruby
18 lines
542 B
Ruby
module JamRuby
|
|
class GeoIpBlocks < ActiveRecord::Base
|
|
|
|
self.table_name = 'geoipblocks'
|
|
|
|
def self.lookup(ipnum)
|
|
GeoIpBlocks.where('geom && ST_MakePoint(?, 0) AND ? BETWEEN beginip AND endip', ipnum, ipnum)
|
|
.limit(1)
|
|
.first
|
|
end
|
|
|
|
def self.createx(beginip, endip, locid)
|
|
c = connection.raw_connection
|
|
c.exec_params('insert into geoipblocks (beginip, endip, locid, geom) values($1::bigint, $2::bigint, $3, ST_MakeEnvelope($1::bigint, -1, $2::bigint, 1))', [beginip, endip, locid])
|
|
end
|
|
end
|
|
end
|