clickhouse_cdr

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChargeRow

type ChargeRow struct {
	ANum    string          `ch:"a_num"    json:"a_num"`
	Charge  decimal.Decimal `ch:"charge"   json:"charge"`
	LastEnd *time.Time      `ch:"last_end" json:"last_end"`
}

type DBQuerier

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

func NewQuerier

func NewQuerier(conn genericConn) *DBQuerier

NewQuerier creates a DBQuerier that implements Querier. conn is typically a clickhouse.Conn.

func (*DBQuerier) FindCDRsByProvider

func (q *DBQuerier) FindCDRsByProvider(ctx context.Context, provider string) ([]FindCDRsByProviderRow, error)

FindCDRsByProvider implements Querier.FindCDRsByProvider.

func (*DBQuerier) FindChargesByLabel

func (q *DBQuerier) FindChargesByLabel(ctx context.Context, label string) ([]ChargeRow, error)

FindChargesByLabel implements Querier.FindChargesByLabel.

func (*DBQuerier) FindChargesByProvider

func (q *DBQuerier) FindChargesByProvider(ctx context.Context, provider string) ([]ChargeRow, error)

FindChargesByProvider implements Querier.FindChargesByProvider.

func (*DBQuerier) FindDataUsage

func (q *DBQuerier) FindDataUsage(ctx context.Context, params FindDataUsageParams) ([]FindDataUsageRow, error)

FindDataUsage implements Querier.FindDataUsage.

func (*DBQuerier) FindOldestStart

func (q *DBQuerier) FindOldestStart(ctx context.Context, provider string) (time.Time, error)

FindOldestStart implements Querier.FindOldestStart.

func (*DBQuerier) InsertCDR

func (q *DBQuerier) InsertCDR(ctx context.Context, params InsertCDRParams) error

InsertCDR implements Querier.InsertCDR.

func (*DBQuerier) ListCDRsPaged

func (q *DBQuerier) ListCDRsPaged(ctx context.Context, params ListCDRsPagedParams) ([]ListCDRsPagedRow, error)

ListCDRsPaged implements Querier.ListCDRsPaged.

func (*DBQuerier) ListProviders

func (q *DBQuerier) ListProviders(ctx context.Context) ([]string, error)

ListProviders implements Querier.ListProviders.

type FindCDRsByProviderRow

type FindCDRsByProviderRow struct {
	ANum           string            `ch:"a_num"           json:"a_num"`
	RecordType     string            `ch:"record_type"     json:"record_type"`
	Rat            *string           `ch:"rat"             json:"rat"`
	Provider       string            `ch:"provider"        json:"provider"`
	Units          int64             `ch:"units"           json:"units"`
	Charge         decimal.Decimal   `ch:"charge"          json:"charge"`
	StartDate      time.Time         `ch:"start_date"      json:"start_date"`
	EndDate        *time.Time        `ch:"end_date"        json:"end_date"`
	UpdatedAt      time.Time         `ch:"updated_at"      json:"updated_at"`
	Labels         []string          `ch:"labels"          json:"labels"`
	Metadata       map[string]string `ch:"metadata"        json:"metadata"`
	SubscriptionID uuid.UUID         `ch:"subscription_id" json:"subscription_id"`
	CustomerID     *uuid.UUID        `ch:"customer_id"     json:"customer_id"`
	Premium        bool              `ch:"premium"         json:"premium"`
}

type FindDataUsageParams

type FindDataUsageParams struct {
	Msisdns []string  `json:"msisdns"`
	From    time.Time `json:"from"`
	To      time.Time `json:"to"`
}

type FindDataUsageRow

type FindDataUsageRow struct {
	Msisdn      string          `ch:"msisdn"       json:"msisdn"`
	DataBytes   int64           `ch:"data_bytes"   json:"data_bytes"`
	TotalCharge decimal.Decimal `ch:"total_charge" json:"total_charge"`
	LastSeen    time.Time       `ch:"last_seen"    json:"last_seen"`
}

type InsertCDRParams

type InsertCDRParams struct {
	ANum           string            `json:"a_num"`
	RecordType     string            `json:"record_type"`
	Rat            *string           `json:"rat"`
	Provider       string            `json:"provider"`
	Units          int64             `json:"units"`
	Charge         decimal.Decimal   `json:"charge"`
	StartDate      time.Time         `json:"start_date"`
	EndDate        *time.Time        `json:"end_date"`
	UpdatedAt      time.Time         `json:"updated_at"`
	Labels         []string          `json:"labels"`
	Metadata       map[string]string `json:"metadata"`
	SubscriptionID uuid.UUID         `json:"subscription_id"`
	CustomerID     *uuid.UUID        `json:"customer_id"`
	Premium        bool              `json:"premium"`
}

type ListCDRsPagedParams

type ListCDRsPagedParams struct {
	Provider string `json:"provider"`
	Limit    uint32 `json:"limit"`
	Offset   uint32 `json:"offset"`
}

type ListCDRsPagedRow

type ListCDRsPagedRow struct {
	ANum  string `ch:"a_num" json:"a_num"`
	Units int64  `ch:"units" json:"units"`
}

type Querier

type Querier interface {
	// Sums data usage per subscriber over a time window. Inputs use ClickHouse's
	// own parameter syntax, so this file also runs as-is in clickhouse-client.
	FindDataUsage(ctx context.Context, params FindDataUsageParams) ([]FindDataUsageRow, error)

	// Returns every column, so the generated row struct covers the whole type
	// vocabulary.
	FindCDRsByProvider(ctx context.Context, provider string) ([]FindCDRsByProviderRow, error)

	// A single row.
	FindOldestStart(ctx context.Context, provider string) (time.Time, error)

	// A single column over many rows, which cannot use struct scanning.
	ListProviders(ctx context.Context) ([]string, error)

	InsertCDR(ctx context.Context, params InsertCDRParams) error

	// Two queries share one row struct through output=. The struct is declared
	// once, and chgen checks the two agree on every column before sharing it.
	FindChargesByProvider(ctx context.Context, provider string) ([]ChargeRow, error)

	// The same shape over a different filter. end_date is Nullable here too, so
	// the shared struct keeps the pointer.
	FindChargesByLabel(ctx context.Context, label string) ([]ChargeRow, error)

	// A parameter named after a ClickHouse setting. Inference sends parameters as
	// settings, so it has to rename them to describe the query; see
	// ch.RenameParams.
	ListCDRsPaged(ctx context.Context, params ListCDRsPagedParams) ([]ListCDRsPagedRow, error)
}

Querier is a typesafe Go interface backed by SQL queries.

Jump to

Keyboard shortcuts

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