sql

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2023 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README


title: "sql" description: "sql use sql as backend." weight: 10 tags: [ "plugin" , "sql" ] categories: [ "plugin", "external" ] date: "2017-12-09T10:26:00+08:00" repo: "https://github.com/r6m/coredns-sql" home: "https://github.com/r6m/coredns-sql/blob/master/README.md"

sql

Use jinzhu/gorm to handle database, support many database as gorm dose.

Syntax

sql <dialect> <arg> {
    debug [db]
    auto-migrate
}

Install Driver

sql need db driver for dialect, to install a driver you need to add import in plugin.cfg, like

sql_mysql:github.com/jinzhu/gorm/dialects/mysql
sql_sqlite:github.com/jinzhu/gorm/dialects/sqlite

sql_mysql and sql_sqlite are meaningless, choose to prevent duplicated.

Examples

Start a server on the 1053 port, use test.db as backend.

test.:1053 {
    sql sqlite3 ./test.db {
        debug db
        auto-migrate
    }
}

Prepare data for test.

# 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)'

When queried for "wener.test. A", CoreDNS will respond with:

;; QUESTION SECTION:
;wener.test.			IN	A

;; ANSWER SECTION:
wener.test.		3600	IN	A	192.168.1.1

When queried for "wener.test. ANY", CoreDNS will respond with:

;; QUESTION SECTION:
;wener.test.			IN	ANY

;; ANSWER SECTION:
wener.test.		3600	IN	A	192.168.1.1
wener.test.		3600	IN	TXT	"TXT Here"

Wildcard

# 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)'

When queried for "first.example.test. A", CoreDNS will respond with:

;; QUESTION SECTION:
;first.example.test.		IN	A

;; ANSWER SECTION:
first.example.test.	3600	IN	A	192.168.1.1

TODO

  • support wildcard record

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseSOA

func ParseSOA(rr *dns.SOA, line string) bool

func WildcardMatch

func WildcardMatch(s1, s2 string) bool

Dummy wildcard match

Types

type Record

type Record struct {
	ID       uint
	ZoneID   int64
	Name     string
	Type     string
	Content  string
	TTL      int32
	Priority int
	Disabled bool
}

type SQL

type SQL struct {
	*gorm.DB
	Debug bool
	Next  plugin.Handler
}

func (*SQL) Migrate added in v0.1.2

func (sql *SQL) Migrate() error

func (*SQL) Name

func (sql *SQL) Name() string

func (*SQL) SearchWildcard

func (sql *SQL) SearchWildcard(qname string, qtype uint16) (redords []*Record, err error)

func (*SQL) ServeDNS

func (sql *SQL) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

type Zone

type Zone struct {
	ID     uint
	Name   string
	Master string
	Type   string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址