db

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package db pkg/db/interfaces.go

Package db is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatabaseNotInitialized = errors.New("database connection not initialized")
	ErrCNPGUnavailable        = errors.New("cnpg connection pool not configured")
	ErrUnknownExecutorType    = errors.New("unknown executor type")
)

Static errors for err113 compliance

View Source
var (
	// Core database errors.
	ErrFailedOpenDB = errors.New("failed to open database")

	// Netflow validation errors.
	ErrNetflowMetricNil = errors.New("netflow metric is nil")

	// CNPG configuration helpers.
	ErrCNPGConfigMissing   = errors.New("cnpg: missing configuration")
	ErrCNPGLackingTLSFiles = errors.New("cnpg tls requires cert_file, key_file, and ca_file")
	ErrCNPGTLSDisabled     = errors.New("cnpg tls configuration requires sslmode not be disable")
)

Functions

func NewCNPGPool added in v1.0.55

func NewCNPGPool(ctx context.Context, cfg *models.CNPGDatabase, log logger.Logger) (*pgxpool.Pool, error)

NewCNPGPool dials the configured CNPG cluster and returns a pgx pool that can be used for Timescale-backed reads/writes.

Types

type DB

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

DB represents the CNPG-backed database connection.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) InsertOCSFEvents added in v1.0.79

func (db *DB) InsertOCSFEvents(ctx context.Context, table string, rows []models.OCSFEventRow) error

InsertOCSFEvents persists OCSF event rows into the configured CNPG table.

func (*DB) InsertOCSFNetworkActivity added in v1.0.90

func (db *DB) InsertOCSFNetworkActivity(ctx context.Context, table string, rows []models.OCSFNetworkActivity) error

InsertOCSFNetworkActivity persists OCSF network activity rows into the configured CNPG table.

func (*DB) InsertOTELLogs added in v1.0.55

func (db *DB) InsertOTELLogs(ctx context.Context, table string, rows []models.OTELLogRow) error

InsertOTELLogs persists OTEL log rows into the configured CNPG table.

func (*DB) InsertOTELMetrics added in v1.0.55

func (db *DB) InsertOTELMetrics(ctx context.Context, table string, rows []models.OTELMetricRow) error

InsertOTELMetrics persists OTEL metric rows into the configured CNPG table.

func (*DB) InsertOTELTraces added in v1.0.55

func (db *DB) InsertOTELTraces(ctx context.Context, table string, rows []models.OTELTraceRow) error

InsertOTELTraces persists OTEL trace rows into the configured CNPG table.

func (*DB) StoreNetflowMetrics

func (db *DB) StoreNetflowMetrics(ctx context.Context, metrics []*models.NetflowMetric) error

StoreNetflowMetrics stores multiple NetFlow metrics in CNPG.

func (*DB) UseCNPGReads added in v1.0.55

func (db *DB) UseCNPGReads() bool

func (*DB) UseCNPGWrites added in v1.0.55

func (db *DB) UseCNPGWrites() bool

func (*DB) WithTx added in v1.0.65

func (db *DB) WithTx(ctx context.Context, fn func(tx Service) error) error

WithTx executes the given function within a transaction.

type MockService

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

MockService is a mock of Service interface.

func NewMockService

func NewMockService(ctrl *gomock.Controller) *MockService

NewMockService creates a new mock instance.

func (*MockService) Close

func (m *MockService) Close() error

Close mocks base method.

func (*MockService) EXPECT

func (m *MockService) EXPECT() *MockServiceMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockService) StoreNetflowMetrics

func (m *MockService) StoreNetflowMetrics(ctx context.Context, metrics []*models.NetflowMetric) error

StoreNetflowMetrics mocks base method.

type MockServiceMockRecorder

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

MockServiceMockRecorder is the mock recorder for MockService.

func (*MockServiceMockRecorder) Close

func (mr *MockServiceMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockServiceMockRecorder) StoreNetflowMetrics

func (mr *MockServiceMockRecorder) StoreNetflowMetrics(ctx, metrics any) *gomock.Call

StoreNetflowMetrics indicates an expected call of StoreNetflowMetrics.

type PgxExecutor added in v1.0.65

type PgxExecutor interface {
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
}

PgxExecutor is an interface satisfied by both *pgxpool.Pool and pgx.Tx

type Service

type Service interface {
	Close() error
	StoreNetflowMetrics(ctx context.Context, metrics []*models.NetflowMetric) error
}

Service represents the CNPG-backed database operations used by consumers.

func New

New creates a new CNPG-backed database connection.

Jump to

Keyboard shortcuts

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