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 ¶
- func Schema(streams, events, idType, boolType, timeType string) []string
- type Dialect
- type Streams
- func (s *Streams) Append(ctx context.Context, streamID string, events []ports.StreamEvent) ([]string, error)
- func (s *Streams) Close(ctx context.Context, streamID string, end ports.StreamEnd, grace time.Duration) error
- func (s *Streams) Delete(ctx context.Context, streamID string) error
- func (s *Streams) Open(ctx context.Context, streamID string, meta ports.StreamMeta, ttl time.Duration) error
- func (s *Streams) Read(ctx context.Context, streamID, after string) iter.Seq2[ports.StreamItem, error]
- func (s *Streams) Snapshot(ctx context.Context, streamID, after string) (*ports.StreamSnapshot, error)
- func (s *Streams) Wake(streamID string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.