mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-08-03 02:58:41 -04:00
- Small UI adjustments - Only show last 2 previous IP addresses in notifications and UI - Database uses interfaces to be modular/pluggable in order to move away from sqlite - Less dependencies, it even uses a switch statement instead of httprouter - Updated golibs - Changed default logging format to `console` (zap) - Better code overall, modular updater and trigger system - Refactored readme - CI script improved
35 lines
694 B
Go
35 lines
694 B
Go
package sqlite
|
|
|
|
import (
|
|
"database/sql"
|
|
"sync"
|
|
)
|
|
|
|
type database struct {
|
|
sqlite *sql.DB
|
|
sync.Mutex
|
|
}
|
|
|
|
func (db *database) Close() error {
|
|
return db.sqlite.Close()
|
|
}
|
|
|
|
// NewDatabase opens or creates the database if necessary.
|
|
func NewDatabase(dataDir string) (*database, error) {
|
|
sqlite, err := sql.Open("sqlite3", dataDir+"/updates.db")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
_, err = sqlite.Exec(
|
|
`CREATE TABLE IF NOT EXISTS updates_ips (
|
|
domain TEXT NOT NULL,
|
|
host TEXT NOT NULL,
|
|
ip TEXT NOT NULL,
|
|
t_new DATETIME NOT NULL,
|
|
t_last DATETIME NOT NULL,
|
|
current INTEGER DEFAULT 1 NOT NULL,
|
|
PRIMARY KEY(domain, host, ip, t_new)
|
|
);`)
|
|
return &database{sqlite: sqlite}, err
|
|
}
|