clickhouse

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteCreatedEntitiesAfterTest

func DeleteCreatedEntitiesAfterTest(db *gorm.DB) func()

DeleteCreatedEntitiesAfterTest sets up GORM `onCreate` hook and return a function that can be deferred to remove all the entities created after the hook was set up You can use it as

func TestSomething(t *testing.T){
    db, _ := gorm.Open(...)

    cleaner := DeleteCreatedEntities(db)
    defer cleaner()

}

func GenerateRandomString

func GenerateRandomString(n int) string

GenerateRandomString generates a random string based on the size specified by the client

Types

type Client

type Client struct {
	// `Engine *gorm.DB` is defining a field named `Engine` of type `*gorm.DB` in the `Client` struct. This
	// field is used to store a reference to a GORM database connection.
	Engine *gorm.DB

	// `QueryTimeout` is a field in the `Client` struct that stores a pointer to a `time.Duration` value.
	// This value represents the maximum amount of time that a query can take before timing out. It is used
	// to set a timeout for queries executed by the `Client` instance.
	QueryTimeout *time.Duration

	// `InstrumentationClient *instrumentation.Client` is defining a field in the `Client` struct that
	// stores a reference to an `instrumentation.Client` instance. This instance is used to collect and
	// report metrics and traces related to the ClickHouse database queries executed by the `Client`
	// instance. The `InstrumentationClient` field allows the `Client` instance to integrate with an
	// external instrumentation library for monitoring and analysis purposes.
	InstrumentationClient *instrumentation.Client

	// `Logger *zap.Logger` is defining a field in the `Client` struct that stores a reference to a
	// `zap.Logger` instance. This instance is used for logging purposes and allows the `Client` instance
	// to log messages related to the ClickHouse database queries executed by the `Client`. The `Logger`
	// field allows the `Client` instance to integrate with an external logging library for debugging and
	// analysis purposes.
	Logger *zap.Logger
	// contains filtered or unexported fields
}

`type Client struct {` is defining a new struct type named `Client`. This struct will have several fields that will be used to store various properties and settings related to a ClickHouse database connection. The `Client` struct will be used to create instances of a ClickHouse client that can be used to execute queries against the database.

func New

func New(options ...Option) (*Client, error)

The New function creates a new client with optional configuration options.

func NewInMemoryTestDbClient

func NewInMemoryTestDbClient(models ...any) (*Client, error)

NewInMemoryTestDbClient creates a new in memory test db client This is useful only for unit tests

func (*Client) Close

func (c *Client) Close() error

Close closes the database connection

func (*Client) ConfigureNewTxCleanupHandlerForUnitTests

func (c *Client) ConfigureNewTxCleanupHandlerForUnitTests() *TestTxCleanupHandlerForUnitTests

ConfigureNewTxCleanupHandlerForUnitTests creates a new transaction with a save point and returns a handler that can be used to rollback to the save point. This is useful for unit tests that need to rollback a transaction to a save point.

func (*Client) PerformComplexTransaction

func (db *Client) PerformComplexTransaction(ctx context.Context, transaction CmplxTx) (interface{}, error)

PerformComplexTransaction takes as input an anonymous function witholding logic to perform within a transaction returning an abstract type. This function is then invoked within a transaction and depending on the occurrence of any specific errors, the transaction is either committed to the database or completely rolled back. This returns the result obtained from the invocation of the anonymous function as well as any error occuring throughout the transaction lifecycle.

func (*Client) PerformTransaction

func (db *Client) PerformTransaction(ctx context.Context, transaction Tx) error

PerformTransaction takes as input an anonymous function witholding logic to perform within a transaction. This function is then invoked within a transaction. if unsuccessful or any error is raised throughout the transaction, then, the transaction is rolled back. Returned is any error occuring throughout the transaction lifecycle

func (*Client) Validate

func (c *Client) Validate() error

Validate validates the client

type CmplxTx

type CmplxTx func(ctx context.Context, tx *gorm.DB) (interface{}, error)

CmplxTx is a type serving as a function decorator for complex database transactions

type Option

type Option func(*Client)

Option is a function that sets a parameter for the client

func WithConnectionString

func WithConnectionString(connectionString *string) Option

WithConnectionString sets the connection string

func WithInstrumentationClient

func WithInstrumentationClient(instrumentationClient *instrumentation.Client) Option

WithInstrumentationClient sets the instrumentation client

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger sets the logger

func WithMaxConnectionLifetime

func WithMaxConnectionLifetime(maxConnectionLifetime *time.Duration) Option

WithMaxConnectionLifetime sets the max connection lifetime

func WithMaxConnectionRetries

func WithMaxConnectionRetries(retries *int) Option

WithMaxConnectionRetries sets the max connection retries

func WithMaxConnectionRetryTimeout

func WithMaxConnectionRetryTimeout(timeout *time.Duration) Option

WithMaxConnectionRetryTimeout sets the max connection retry timeout

func WithMaxIdleConnections

func WithMaxIdleConnections(maxIdleConnections *int) Option

WithMaxIdleConnections sets the max idle connections

func WithMaxOpenConnections

func WithMaxOpenConnections(maxOpenConnections *int) Option

WithMaxOpenConnections sets the max open connections

func WithQueryTimeout

func WithQueryTimeout(timeout *time.Duration) Option

WithQueryTimeout sets the query timeout

func WithRetrySleep

func WithRetrySleep(sleep *time.Duration) Option

WithRetrySleep sets the retry sleep

type TestTxCleanupHandlerForUnitTests

type TestTxCleanupHandlerForUnitTests struct {
	Tx *gorm.DB
	// contains filtered or unexported fields
}

TestTxCleanupHandlerForUnitTests is a handler that can be used to rollback a transaction to a save point. This is useful for unit tests that need to rollback a transaction to a save point.

type Tx

type Tx func(ctx context.Context, tx *gorm.DB) error

Tx is a type serving as a function decorator for common database transactions

Jump to

Keyboard shortcuts

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