sqlstreams

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sqlstreams is RunStreams over two SQL tables, shared by the SQLite and Postgres adapters. <prefix>streams has one row per stream: who it belongs to, whether it is closed, its end event and when it expires. <prefix>stream_events has one row per event, keyed by an ever-increasing integer that is the offset. The TS SQLite adapter uses the same tables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Schema

func Schema(streams, events, idType, boolType, timeType string) []string

Schema is the DDL for the two tables. idType is the type of an ever-increasing integer key, timeType the expiresAt column's.

Types

type Dialect

type Dialect struct {
	// Placeholder is the n-th (1-based) bind parameter: "?" or "$n".
	Placeholder func(n int) string
	// Time turns a time into the value the expiresAt column holds, and Now
	// is the SQL for the current time in that form.
	Time func(t time.Time) any
	Now  string
	// ForUpdate locks the stream row inside a transaction ("" where the
	// whole database is locked anyway).
	ForUpdate string
	// Notify, when set, tells other processes that a stream changed. It
	// runs inside the write's transaction.
	Notify func(ctx context.Context, tx *sql.Tx, streamID string) error
}

Dialect is what differs between the databases.

type Streams

type Streams struct {
	DB      *sql.DB
	D       Dialect
	Streams string // table names, prefixed
	Events  string
	// Poll is the longest a reader waits before reading again, news or
	// not: the floor under a missed wake-up from another process.
	Poll time.Duration
	// contains filtered or unexported fields
}

Streams implements ports.RunStreams.

func (*Streams) Append

func (s *Streams) Append(ctx context.Context, streamID string, events []ports.StreamEvent) ([]string, error)

func (*Streams) Close

func (s *Streams) Close(ctx context.Context, streamID string, end ports.StreamEnd, grace time.Duration) error

func (*Streams) Delete

func (s *Streams) Delete(ctx context.Context, streamID string) error

func (*Streams) Open

func (s *Streams) Open(ctx context.Context, streamID string, meta ports.StreamMeta, ttl time.Duration) error

func (*Streams) Read

func (s *Streams) Read(ctx context.Context, streamID, after string) iter.Seq2[ports.StreamItem, error]

func (*Streams) Snapshot

func (s *Streams) Snapshot(ctx context.Context, streamID, after string) (*ports.StreamSnapshot, error)

func (*Streams) Wake

func (s *Streams) Wake(streamID string)

Wake wakes this process's readers of a stream. The Postgres adapter also calls it for a NOTIFY from another process.

Jump to

Keyboard shortcuts

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