dbutil

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignBucketStart

func AlignBucketStart(t time.Time, bucketSeconds int) time.Time

AlignBucketStart rounds `t` down to the nearest `bucketSeconds` boundary. Used so the API and the rollup-writer agree on bucket edges to the second.

func BucketExpr

func BucketExpr(db *gorm.DB, column string, bucketSeconds int) string

BucketExpr returns the SQL expression that floors `created_at` to a bucket-aligned unix timestamp. Same shape on every dialect — only the epoch-extraction function differs.

The expression returns an integer number of seconds since the epoch, truncated down to the nearest `bucketSeconds` boundary. Group by this expression, count(*), and you have a contiguous-bucket histogram.

func DensifyBuckets

func DensifyBuckets(rows []BucketedRow, startUnix int64, bucketSeconds int, nBuckets int) []int64

DensifyBuckets takes a sparse list of {bucketStart, count} rows from the DB and emits a dense `nBuckets`-long slice aligned to `startUnix`. Bucket indexes outside the range are dropped — they can't render in a heatmap of fixed width.

Types

type BucketCount

type BucketCount struct {
	Bucket int64 // Unix seconds at the start of the bucket
	Count  int64
}

BucketCount represents one row of a bucketed count query.

type BucketedRow

type BucketedRow struct {
	BucketStart int64 `gorm:"column:bucket_start"`
	Cnt         int64 `gorm:"column:cnt"`
}

BucketedRow is the raw scan target for the GROUP BY query. Stays dialect-agnostic since every dialect returns BIGINT for FLOOR/CAST expressions.

Jump to

Keyboard shortcuts

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