clickhouse

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client manages ClickHouse connections and analytical queries.

func Connect

func Connect(ctx context.Context, cfg Config) (*Client, error)

Connect establishes a connection to ClickHouse, ensuring the database exists.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying ClickHouse connection.

func (*Client) Conn

func (c *Client) Conn() driver.Conn

Conn returns the driver connection.

func (*Client) Empty

func (c *Client) Empty(ctx context.Context) (bool, error)

Empty reports whether usage_events holds no event yet.

func (*Client) EnsureSchema

func (c *Client) EnsureSchema(ctx context.Context) error

EnsureSchema applies any pending embedded migrations in sequential order.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks ClickHouse database connectivity.

func (*Client) QuerySummary

func (c *Client) QuerySummary(ctx context.Context, params domain.SummaryParams) ([]domain.SummaryRow, bool, error)

QuerySummary executes multi-dimensional analytical aggregations on ClickHouse.

func (*Client) QueryUsageByMeta

func (c *Client) QueryUsageByMeta(ctx context.Context, params domain.MetaUsageParams) ([]domain.MetaUsageRow, bool, error)

QueryUsageByMeta aggregates token usage by meta key/value filtering.

type Config

type Config struct {
	Addr     string
	Database string
	User     string
	Password string
}

Config holds the ClickHouse connection settings.

type Outbox

type Outbox interface {
	ClaimOutbox(ctx context.Context, owner uuid.UUID, limit int, lease time.Duration) (repository.OutboxBatch, []*domain.UsageEvent, error)
	RenewOutbox(ctx context.Context, owner, batch uuid.UUID, lease time.Duration) (bool, error)
	AckOutbox(ctx context.Context, batch uuid.UUID) error
	RetryOutboxLater(ctx context.Context, owner, batch uuid.UUID, delay time.Duration) (bool, error)
}

Outbox is the Postgres side: events written there in the same statement as the event itself, leased out in batches until ClickHouse has them.

type Replicator

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

Replicator copies events from the Postgres outbox to ClickHouse. Nothing is held only in memory: while ClickHouse is down the outbox grows, and a restart resumes where it stopped.

func NewReplicator

func NewReplicator(outbox Outbox, conn driver.Conn, batchSize int, interval time.Duration) *Replicator

NewReplicator copies up to batchSize events per insert, checking the outbox every interval.

func (*Replicator) Close

func (r *Replicator) Close()

Close stops the loop. A batch it was copying stays leased in the outbox and is copied, without duplicates, by whoever claims it once the lease ends.

func (*Replicator) Start

func (r *Replicator) Start()

Jump to

Keyboard shortcuts

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