class Proxy::Dns::Powerdns::Backend::Postgresql
Attributes
connection_str[R]
Public Class Methods
new(a_server, a_ttl, pdnssec, connection)
click to toggle source
Calls superclass method
Proxy::Dns::Powerdns::Record.new
# File lib/smart_proxy_dns_powerdns/backend/postgresql.rb, line 8 def initialize(a_server, a_ttl, pdnssec, connection) @connection_str = connection super(a_server, a_ttl, pdnssec) end
Public Instance Methods
connection()
click to toggle source
# File lib/smart_proxy_dns_powerdns/backend/postgresql.rb, line 14 def connection @connection ||= PG.connect(connection_str) end
create_record(domain_id, name, type, content)
click to toggle source
# File lib/smart_proxy_dns_powerdns/backend/postgresql.rb, line 32 def create_record domain_id, name, type, content result = connection.exec_params("INSERT INTO records (domain_id, name, ttl, content, type) VALUES ($1::int, $2, $3::int, $4, $5)", [domain_id, name, ttl, content, type]) result.cmdtuples == 1 end
delete_record(domain_id, name, type)
click to toggle source
# File lib/smart_proxy_dns_powerdns/backend/postgresql.rb, line 37 def delete_record domain_id, name, type result = connection.exec_params("DELETE FROM records WHERE domain_id=$1::int AND name=$2 AND type=$3", [domain_id, name, type]) result.cmdtuples >= 1 end
get_zone(name)
click to toggle source
# File lib/smart_proxy_dns_powerdns/backend/postgresql.rb, line 18 def get_zone name domain = nil connection.exec_params("SELECT LENGTH(name) domain_length, id, name FROM domains WHERE $1 LIKE CONCAT('%%.', name) ORDER BY domain_length DESC LIMIT 1", [name]) do |result| result.each do |row| domain = row end end raise Proxy::Dns::Error, "Unable to determine zone. Zone must exist in PowerDNS." unless domain domain end