説明
pdsql は PowerDNS ジェネリック SQL をバックエンドを使用します。
Gorm のデータベースドライバーを使用し、Gorm と同じ数のデータベースをサポートします。
構文
pdsql <dialect> <arg> {
// enable debug mode
debug [db]
// create table for test
auto-migrate
}
ドライバをインストールする
pdsql では方言に対応するデータベースドライバが必要になります。ドライバをインストールするには、plugin.cfg
にインポートを追加します。例:
pdsql_mysql:github.com/jinzhu/gorm/dialects/mysql
pdsql_sqlite:github.com/jinzhu/gorm/dialects/sqlite
pdsql_mysql と pdsql_sqlite は意味がありません。重複を避けるように指定します。
例
ポート 1053
でサーバを起動し、test.db
をバックエンドとして使用します。
test.:1053 {
pdsql sqlite3 ./test.db {
debug db
auto-migrate
}
}
テストのためのデータを用意します。
# Insert records for wener.test
sqlite3 ./test.db 'insert into records(name,type,content,ttl,disabled)values("wener.test","A","192.168.1.1",3600,0)'
sqlite3 ./test.db 'insert into records(name,type,content,ttl,disabled)values("wener.test","TXT","TXT Here",3600,0)'
CoreDNS に「wener.test. A」をクエリすると、以下の応答が返ります。
;; QUESTION SECTION:
;wener.test. IN A
;; ANSWER SECTION:
wener.test. 3600 IN A 192.168.1.1
CoreDNS に「wener.test. ANY」をクエリすると、以下の応答が返ります。
;; QUESTION SECTION:
;wener.test. IN ANY
;; ANSWER SECTION:
wener.test. 3600 IN A 192.168.1.1
wener.test. 3600 IN TXT "TXT Here"
ワイルドカード
# domain id 1
sqlite3 ./test.db 'insert into domains(name,type)values("example.test","NATIVE")'
sqlite3 ./test.db 'insert into records(domain_id,name,type,content,ttl,disabled)values(1,"*.example.test","A","192.168.1.1",3600,0)'
CoreDNS に「first.example.test. A」をクエリすると、以下の応答が返ります。
;; QUESTION SECTION:
;first.example.test. IN A
;; ANSWER SECTION:
first.example.test. 3600 IN A 192.168.1.1