clickhouse_cdr

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	PageCDRsSortStartDate = "start_date"
	PageCDRsSortUnits     = "units"
)
View Source
const FindDataUsageSQL = `` /* 333-byte string literal not displayed */

Variables

This section is empty.

Functions

This section is empty.

Types

type CDRPageRow added in v0.2.0

type CDRPageRow struct {
	ANum      string    `ch:"a_num"      json:"a_num"`
	Units     int64     `ch:"units"      json:"units"`
	StartDate time.Time `ch:"start_date" json:"start_date"`
}

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.

func (*DBQuerier) PageCDRs added in v0.2.0

func (q *DBQuerier) PageCDRs(ctx context.Context, params PageCDRsParams) ([]CDRPageRow, error)

PageCDRs dispatches to the keyset-pagination variant matching params.SortKey and params.Descending.

func (*DBQuerier) SumUnitsFrom added in v0.2.0

func (q *DBQuerier) SumUnitsFrom(ctx context.Context, cdrSource string, from time.Time) ([]SumUnitsFromRow, error)

SumUnitsFrom implements Querier.SumUnitsFrom.

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 PageCDRsParams added in v0.2.0

type PageCDRsParams struct {
	Provider   string     `json:"provider"`
	AfterANum  *string    `json:"after_a_num"`
	Limit      uint32     `json:"limit"`
	AfterStart *time.Time `json:"after_start"`
	AfterUnits *int64     `json:"after_units"`
	SortKey    string     `json:"sort_key"`
	Descending bool       `json:"descending"`
}

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.
	//
	// sql=FindDataUsageSQL also emits the query text as an exported constant, for
	// a caller that has to put the query inside another statement rather than run
	// it — see query.sql_test.go, which materializes it into a temporary table.
	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)

	// Reads a table chosen at run time. {cdr_source:Identifier} names a table
	// rather than carrying a value, so it cannot be bound like one: the generated
	// method substitutes it into the query text, having checked it is a plain
	// identifier. The from parameter beside it is bound the ordinary way, which is
	// the reason pggen substitutes rather than letting ClickHouse bind the
	// identifier itself — see ch.SubstituteIdentifiers.
	//
	// chgen describes this against a table named after the parameter, cdr_source,
	// which schema.sql declares.
	SumUnitsFrom(ctx context.Context, cdrSource string, from time.Time) ([]SumUnitsFromRow, error)

	PageCDRs(ctx context.Context, params PageCDRsParams) ([]CDRPageRow, error)
}

Querier is a typesafe Go interface backed by SQL queries.

type SumUnitsFromRow added in v0.2.0

type SumUnitsFromRow struct {
	Provider string `ch:"provider" json:"provider"`
	Units    int64  `ch:"units"    json:"units"`
}

Jump to

Keyboard shortcuts

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