描述
pdsql 使用 PowerDNS 的 通用 SQL 作為後端。
使用 jinzhu/gorm 資料庫驅動程式,支援 Gorm 支援的所有資料庫。
語法
pdsql <dialect> <arg> {
// enable debug mode
debug [db]
// create table for test
auto-migrate
}
安裝驅動程式
pdsql 需要資料庫驅動程式來處理方言 (dialect),要安裝驅動程式,您需要在 plugin.cfg
中加入一個 import,例如:
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)'
當查詢 “wener.test. A” 時,CoreDNS 將回應:
;; QUESTION SECTION:
;wener.test. IN A
;; ANSWER SECTION:
wener.test. 3600 IN A 192.168.1.1
當查詢 “wener.test. ANY” 時,CoreDNS 將回應:
;; 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)'
當查詢 “first.example.test. A” 時,CoreDNS 將回應:
;; QUESTION SECTION:
;first.example.test. IN A
;; ANSWER SECTION:
first.example.test. 3600 IN A 192.168.1.1