db

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBatchSize     = 100
	DefaultFlushInterval = time.Minute
	DefaultTableName     = "results"
	DefaultDatabaseName  = "httpx"
	EnvConnectionString  = "HTTPX_DB_CONNECTION_STRING"
)

Variables

This section is empty.

Functions

func Register

func Register(dbType DatabaseType, factory databaseFactory)

Types

type Config

type Config struct {
	Type             DatabaseType  `yaml:"type"`
	ConnectionString string        `yaml:"connection-string"`
	DatabaseName     string        `yaml:"database-name"`
	TableName        string        `yaml:"table-name"`
	BatchSize        int           `yaml:"batch-size"`
	FlushInterval    time.Duration `yaml:"flush-interval"`
	OmitRaw          bool          `yaml:"omit-raw"`
}

func LoadConfigFromFile

func LoadConfigFromFile(configPath string) (*Config, error)

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

func (*Config) Validate

func (c *Config) Validate() error

type Database

type Database interface {
	Connect(ctx context.Context) error

	Close() error

	InsertBatch(ctx context.Context, results []runner.Result) error

	EnsureSchema(ctx context.Context) error

	Type() DatabaseType
}

func NewDatabase

func NewDatabase(cfg *Config) (Database, error)

type DatabaseType

type DatabaseType string
const (
	MongoDB    DatabaseType = "mongodb"
	PostgreSQL DatabaseType = "postgres"
	MySQL      DatabaseType = "mysql"
)

func SupportedDatabases

func SupportedDatabases() []DatabaseType

func (DatabaseType) IsValid

func (d DatabaseType) IsValid() bool

func (DatabaseType) String

func (d DatabaseType) String() string

type Options

type Options struct {
	Enabled          bool
	ConfigFile       string
	Type             string
	ConnectionString string
	DatabaseName     string
	TableName        string
	BatchSize        int
	OmitRaw          bool
}

func (*Options) ToConfig

func (o *Options) ToConfig() (*Config, error)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(ctx context.Context, cfg *Config) (*Writer, error)

func (*Writer) Close

func (w *Writer) Close()

func (*Writer) GetWriterCallback

func (w *Writer) GetWriterCallback() runner.OnResultCallback

func (*Writer) Stats

func (w *Writer) Stats() int64

Jump to

Keyboard shortcuts

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