db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package db prvoides a unified interface to add, modify, and delete newly obsereved domains from any database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// Domain name
	Domain string `json:"domain"`
	// Date of first observation
	RegistrationDate time.Time `json:"registration_date"`
}

Entry represents a single domain entry in the database

type NodDB

type NodDB interface {
	// Open opens a connection to the database
	Open() error
	// Close closes the connection to the database
	Close() error
	// Add adds a new domain to the database
	Add(Entry) error
	// AddMany adds multiple new domains to the database
	AddMany([]Entry) error
	// Delete removes a domain from the database
	Delete(string) error
	// DeleteMany removes multiple domains from the database
	DeleteMany([]string) error
	// Query returns the date of first observation for a given domain
	Query(string) (Entry, error)
	// QueryMany returns the date of first observation for multiple domains
	QueryMany([]string) ([]Entry, error)
}

NodDB is the interface that must be implemented by any database that is to be used

type PebbleDB

type PebbleDB struct {
	Path string
	DB   *pebble.DB
}

PebbleDB is a wrapper around a Pebble database.

func NewPebbleDB

func NewPebbleDB(path string) *PebbleDB

NewPebbleDB creates a new PebbleDB instance. Note that the database is not opened until Open() is called.

func (*PebbleDB) Add

func (db *PebbleDB) Add(entry Entry) error

Add adds an entry to the database.

func (*PebbleDB) AddMany

func (db *PebbleDB) AddMany(entries []Entry) error

AddMany adds many entries to the database.

func (*PebbleDB) Close

func (db *PebbleDB) Close() error

Close closes the database.

func (*PebbleDB) Delete

func (db *PebbleDB) Delete(domain string) error

Delete deletes an entry from the database.

func (*PebbleDB) DeleteMany

func (db *PebbleDB) DeleteMany(domains []string) error

DeleteMany deletes many entries from the database.

func (*PebbleDB) Open

func (db *PebbleDB) Open() error

Open opens the database located at path.

func (*PebbleDB) Query

func (db *PebbleDB) Query(domain string) (Entry, error)

Query queries the database for entries matching the given query.

func (*PebbleDB) QueryMany

func (db *PebbleDB) QueryMany(domains []string) ([]Entry, error)

QueryMany queries the database for entries matching the given query.

type Value

type Value struct {
	FirstObserved int64 `json:"first_observed"`
	TimeAdded     int64 `json:"now"`
}

Value is what gets saved inside the K/V store. The key is the FQDN

Jump to

Keyboard shortcuts

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