clickhouse

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingDocument = errors.New("document not found")

ErrMissingDocument is returned by Retrieve when no document matches the id.

Functions

This section is empty.

Types

type Backend

type Backend struct {

	// Options is the set of options for the clickhouse Backend.
	Options *BackendOptions
	// contains filtered or unexported fields
}

Backend implements the protobom/storage.Backend interface backed by ClickHouse.

func NewBackend

func NewBackend(opts ...Option) *Backend

NewBackend creates a new clickhouse Backend, applying the given options on top of the defaults.

func (*Backend) CloseClient

func (backend *Backend) CloseClient() error

CloseClient closes the underlying ClickHouse connection.

func (*Backend) Conn

func (backend *Backend) Conn() driver.Conn

Conn exposes the underlying ClickHouse connection for advanced queries.

func (*Backend) Debug

func (backend *Backend) Debug() *Backend

Debug enables debug output on the backend's client.

func (*Backend) InitClient

func (backend *Backend) InitClient() error

InitClient connects to ClickHouse, ensures the target database exists and applies the backend's schema.

func (*Backend) Retrieve

func (backend *Backend) Retrieve(id string, _ *storage.RetrieveOptions) (*sbom.Document, error)

Retrieve implements the storage.Retriever interface. It reads the serialized document blob stored by Store and unmarshals it, so the returned document is a lossless copy of the one originally stored.

FINAL collapses any not-yet-merged ReplacingMergeTree duplicates so the latest stored version of the document is returned.

func (*Backend) Store

func (backend *Backend) Store(doc *sbom.Document, opts *storage.StoreOptions) error

Store implements the storage.Storer interface. It keeps the full serialized document as a blob for lossless retrieval and, in parallel, decomposes the node list into the wide nodes and edges tables for querying.

ClickHouse has no cross-table transactions; correctness on re-store comes from idempotency: the tables are ReplacingMergeTree engines keyed by content, so storing the same document twice converges rather than duplicating rows.

func (*Backend) WithAddr

func (backend *Backend) WithAddr(addr ...string) *Backend

WithAddr sets the ClickHouse node addresses to connect to.

func (*Backend) WithBackendOptions

func (backend *Backend) WithBackendOptions(opts *BackendOptions) *Backend

WithBackendOptions replaces the backend's options with opts.

func (*Backend) WithCredentials

func (backend *Backend) WithCredentials(username, password string) *Backend

WithCredentials sets the username and password used to authenticate.

func (*Backend) WithDatabase

func (backend *Backend) WithDatabase(database string) *Backend

WithDatabase sets the ClickHouse database that holds the protobom tables.

type BackendOptions

type BackendOptions struct {
	// Database is the ClickHouse database that holds the protobom tables.
	Database string

	// Username and Password are the credentials used to authenticate.
	Username string
	Password string

	// Settings are additional ClickHouse settings passed through on connect.
	Settings map[string]any

	// TLS, when set, enables a secure connection to the server.
	TLS *tls.Config

	// Addr is the list of ClickHouse node addresses (host:port) to connect to.
	Addr []string

	// Debug configures the client to output debug information.
	Debug bool
}

BackendOptions contains options specific to the protobom clickhouse backend. Field order is chosen to satisfy the fieldalignment linter.

func NewBackendOptions

func NewBackendOptions() *BackendOptions

NewBackendOptions creates a new BackendOptions with sensible defaults for a local single-node ClickHouse server.

type Option

type Option func(*Backend)

Option represents a single configuration option for the clickhouse backend.

func Debug

func Debug() Option

func WithAddr

func WithAddr(addr ...string) Option

func WithBackendOptions

func WithBackendOptions(opts *BackendOptions) Option

func WithCredentials

func WithCredentials(username, password string) Option

func WithDatabase

func WithDatabase(database string) Option

Jump to

Keyboard shortcuts

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