Documentation
¶
Overview ¶
Package db implements the database connection and management.
Index ¶
- func ConnectToDB(ctx context.Context, logger *zap.Logger, dsn string, namespace string, ...) (*sql.DB, error)
- func Get5MinutesOfCongestion(ctx context.Context, querier *queries.Queries, originatorID, endMinute int32) (out [5]int32, err error)
- func InsertGatewayEnvelopeAndIncrementUnsettledUsage(ctx context.Context, db *sql.DB, ...) (int64, error)
- func NewNamespacedDB(ctx context.Context, logger *zap.Logger, dsn string, namespace string, ...) (*sql.DB, error)
- func NullInt32(v int32) sql.NullInt32
- func NullInt64(v int64) sql.NullInt64
- func RunInTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions, ...) error
- func RunInTxRaw(ctx context.Context, db *sql.DB, opts *sql.TxOptions, ...) error
- func RunInTxWithResult[T any](ctx context.Context, db *sql.DB, opts *sql.TxOptions, ...) (result T, err error)
- func SetVectorClock(q *queries.SelectGatewayEnvelopesParams, vc VectorClock) *queries.SelectGatewayEnvelopesParams
- type DBSubscription
- type PollableDBQuery
- type PollingOptions
- type Topic
- type VectorClock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectToDB ¶ added in v0.4.0
func ConnectToDB( ctx context.Context, logger *zap.Logger, dsn string, namespace string, waitForDB time.Duration, statementTimeout time.Duration, ) (*sql.DB, error)
ConnectToDB establishes a connection to an existing database using the provided DSN. Unlike NewNamespacedDB, this function does not create the database or run migrations. If namespace is provided, it overrides the database name in the DSN.
func Get5MinutesOfCongestion ¶ added in v0.3.0
func Get5MinutesOfCongestion( ctx context.Context, querier *queries.Queries, originatorID, endMinute int32, ) (out [5]int32, err error)
Get5MinutesOfCongestion gets the congestion for the minute specified by `endMinute` and the previous 4 minutes returned in descending order with missing values filled with 0
func InsertGatewayEnvelopeAndIncrementUnsettledUsage ¶ added in v0.3.0
func InsertGatewayEnvelopeAndIncrementUnsettledUsage( ctx context.Context, db *sql.DB, insertParams queries.InsertGatewayEnvelopeParams, incrementParams queries.IncrementUnsettledUsageParams, ) (int64, error)
InsertGatewayEnvelopeAndIncrementUnsettledUsage inserts a gateway envelope and increments the unsettled usage for the payer. It returns the number of rows inserted.
func NewNamespacedDB ¶ added in v0.1.2
func NewNamespacedDB( ctx context.Context, logger *zap.Logger, dsn string, namespace string, waitForDB time.Duration, statementTimeout time.Duration, ) (*sql.DB, error)
NewNamespacedDB creates a new database with the given namespace if it doesn't exist and returns the full DSN for the new database.
func RunInTxRaw ¶ added in v0.5.0
func RunInTxWithResult ¶ added in v0.3.0
func SetVectorClock ¶
func SetVectorClock( q *queries.SelectGatewayEnvelopesParams, vc VectorClock, ) *queries.SelectGatewayEnvelopesParams
Types ¶
type DBSubscription ¶
type DBSubscription[ValueType any, CursorType any] struct { // contains filtered or unexported fields }
DBSubscription is a subscription that polls a DB for updates Assumes there is only one listener (updates block on a single unbuffered channel)
func NewDBSubscription ¶
func NewDBSubscription[ValueType any, CursorType any]( ctx context.Context, log *zap.Logger, query PollableDBQuery[ValueType, CursorType], lastSeen CursorType, options PollingOptions, ) *DBSubscription[ValueType, CursorType]
func (*DBSubscription[ValueType, CursorType]) Start ¶
func (s *DBSubscription[ValueType, CursorType]) Start() (<-chan []ValueType, error)
type PollableDBQuery ¶
type PollingOptions ¶
PollingOptions specifies the polling options for a DB subscription. It can poll whenever notified, or at an interval if not notified.
type VectorClock ¶
func ToVectorClock ¶
func ToVectorClock(rows []queries.SelectVectorClockRow) VectorClock