db

package
v7.0.0-rc9 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupDB

func CleanupDB(t *testing.T, client *ClickHouse)

CleanupDB clears all test database tables.

func Disconnect

func Disconnect(client *ClickHouse)

Disconnect disconnects from the test database.

func DropDB

func DropDB(t *testing.T, client *ClickHouse)

DropDB drops all test database tables.

func Migrate

func Migrate(config *ClickHouseConfig) error

Migrate runs the database migration for a given connection string. This will use the embedded schema migration scripts.

Types

type ClickHouse

type ClickHouse struct {
	clickhouse.Conn
	// contains filtered or unexported fields
}

ClickHouse implements the Storage interface.

func Connect

func Connect() *ClickHouse

Connect connects to the test database.

func NewClickHouse

func NewClickHouse(config *ClickHouseConfig) (*ClickHouse, error)

NewClickHouse returns a new ClickHouse client for the given configuration.

func (*ClickHouse) SaveEvents

func (ch *ClickHouse) SaveEvents(ctx context.Context, events []model.Event) error

SaveEvents implements the Storage interface.

func (*ClickHouse) SavePageViews

func (ch *ClickHouse) SavePageViews(ctx context.Context, pageViews []model.PageView) error

SavePageViews implements the Storage interface.

func (*ClickHouse) SaveRequests

func (ch *ClickHouse) SaveRequests(ctx context.Context, requests []model.Request) error

SaveRequests implements the Storage interface.

func (*ClickHouse) SaveSessions

func (ch *ClickHouse) SaveSessions(ctx context.Context, sessions []model.Session) error

SaveSessions implements the Storage interface.

func (*ClickHouse) Session

func (ch *ClickHouse) Session(ctx context.Context, siteID, fingerprint uint64, maxAge time.Time) (*model.Session, error)

Session implements the Storage interface.

type ClickHouseConfig

type ClickHouseConfig struct {
	// Hostnames is the database hostname.
	Hostnames []string

	// Port is the database port.
	Port int

	// Cluster is the optional database cluster to use.
	Cluster string

	// Database is the database schema.
	Database string

	// Username is the database user.
	Username string

	// Password is the database password.
	Password string

	// Secure enables TLS encryption.
	Secure bool

	// SSLSkipVerify skips the SSL verification if set to true.
	SSLSkipVerify bool

	// MaxOpenConnections sets the number of maximum open connections.
	// If set to <= 0, the default value of 20 will be used.
	MaxOpenConnections int

	// MaxConnectionLifetimeSeconds sets the maximum amount of time a connection will be reused.
	// If set to <= 0, the default value of 1800 will be used.
	MaxConnectionLifetimeSeconds int

	// MaxIdleConnections sets the number of maximum idle connections.
	// If set to <= 0, the default value of 5 will be used.
	MaxIdleConnections int

	// Logger is the log.Logger used for logging.
	Logger *slog.Logger

	// Debug enables the logger for the ClickHouse connection.
	Debug bool
	// contains filtered or unexported fields
}

ClickHouseConfig is the configuration for the ClickHouse Storage implementation.

type Mock

type Mock struct {
	ReturnSession *model.Session
	// contains filtered or unexported fields
}

Mock implements the Storage interface.

func NewMock

func NewMock() *Mock

NewMock returns a new mock client.

func (*Mock) Events

func (client *Mock) Events() []model.Event

Events returns a sorted copy of the events slice.

func (*Mock) PageViews

func (client *Mock) PageViews() []model.PageView

PageViews returns a sorted copy of the page views slice.

func (*Mock) Requests

func (client *Mock) Requests() []model.Request

Requests returns a sorted copy of the request slice.

func (*Mock) SaveEvents

func (client *Mock) SaveEvents(_ context.Context, events []model.Event) error

SaveEvents implements the Storage interface.

func (*Mock) SavePageViews

func (client *Mock) SavePageViews(_ context.Context, pageViews []model.PageView) error

SavePageViews implements the Storage interface.

func (*Mock) SaveRequests

func (client *Mock) SaveRequests(_ context.Context, requests []model.Request) error

SaveRequests implements the Storage interface.

func (*Mock) SaveSessions

func (client *Mock) SaveSessions(_ context.Context, sessions []model.Session) error

SaveSessions implements the Storage interface.

func (*Mock) Session

func (client *Mock) Session(context.Context, uint64, uint64, time.Time) (*model.Session, error)

Session implements the Storage interface.

func (*Mock) Sessions

func (client *Mock) Sessions() []model.Session

Sessions returns an unsorted copy of the session slice.

type Storage

type Storage interface {
	// SavePageViews saves given hits.
	SavePageViews(context.Context, []model.PageView) error

	// SaveSessions saves given sessions.
	SaveSessions(context.Context, []model.Session) error

	// SaveEvents saves given events.
	SaveEvents(context.Context, []model.Event) error

	// SaveRequests saves given requests.
	SaveRequests(context.Context, []model.Request) error

	// Session returns the last hit for a given client, fingerprint, and maximum age.
	Session(context.Context, uint64, uint64, time.Time) (*model.Session, error)
}

Storage is the database storage interface.

Jump to

Keyboard shortcuts

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