client

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 23 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

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound               = clienterrs.ErrNotFound
	ErrNotConnected           = clienterrs.ErrNotConnected
	ErrAuthFailed             = clienterrs.ErrAuthFailed
	ErrNoAuth                 = clienterrs.ErrNoAuth
	ErrNoPrivilege            = clienterrs.ErrNoPrivilege
	ErrNamespaceNotRegistered = clienterrs.ErrNamespaceNotRegistered
	ErrIndexNotFound          = clienterrs.ErrIndexNotFound
	ErrAuthKeyEmpty           = clienterrs.ErrAuthKeyEmpty
	ErrKeyRangeRequired       = clienterrs.ErrKeyRangeRequired
	ErrIndexNameRequired      = clienterrs.ErrIndexNameRequired
	ErrNoUpdateValues         = clienterrs.ErrNoUpdateValues
	ErrTopicEmpty             = clienterrs.ErrTopicEmpty
	ErrDuplicatedHandler      = clienterrs.ErrDuplicatedHandler
	ErrSubscriptionStopped    = clienterrs.ErrSubscriptionStopped
	ErrSubscribeAckTimeout    = clienterrs.ErrSubscribeAckTimeout
)

Functions

func All added in v0.1.16

func All[D x.Document](desc bool, filters ...x.Filter) mo.Result[[]D]

All returns every document currently stored in namespace D.

It is pure sugar over SearchKey with the key range set to "<storageNs>:*" — as a direct consequence, ordering is by the **primary storage key** (namespace:pk concatenation) in lexicographic order: ascending when desc=false, descending when desc=true. Any number of optional Filter arguments are AND-combined together; passing none matches every row.

func Auth

func Auth(authKey string) error

Auth authenticates the shared resp client connection with the given key.

func Connect

func Connect(respAddr, authKey string) error

Connect starts the bridge lifecycle.

func ConnectEmbedded added in v0.1.15

func ConnectEmbedded() error

ConnectEmbedded starts the bridge lifecycle against the in-process embedded server. It reads the ctrl-port address set by server.StartWith via internal.CtrlAddr() and authenticates with the shared per-process internal.AuthKey(). Callers that have not booted an in-process server (or that want to dial a remote cross-process server) should use Connect() with an explicit address and auth key.

func CountByIndex added in v0.1.24

func CountByIndex[D x.Document](idxName string, scopedKR x.KeyRange, filter x.Filter) mo.Result[int]

CountByIndex returns how many documents in namespace D match the given secondary-index query.

func CountByKey added in v0.1.24

func CountByKey[D x.Document](scopedKR x.KeyRange, filter x.Filter) mo.Result[int]

CountByKey returns how many documents in namespace D match the given primary storage-key range query.

func Delete

func Delete[D x.Document](d D) (bool, error)

func Get

func Get[D x.Document](key string) (D, error)

func IsAuthFailed added in v0.1.24

func IsAuthFailed(err error) bool

func IsNoAuth added in v0.1.24

func IsNoAuth(err error) bool

func IsNoPrivilege added in v0.1.24

func IsNoPrivilege(err error) bool

func IsNotConnected added in v0.1.24

func IsNotConnected(err error) bool

func IsNotFound added in v0.1.24

func IsNotFound(err error) bool

func Keys

func Keys[D x.Document](keyPattern string) mo.Result[[]string]

func Publish

func Publish(topic, msg string) bool

Publish enqueues a message for publishing to a specific topic.

func RegisterSchema added in v0.1.15

func RegisterSchema[T x.Document](defs ...x.IndexDef) error

RegisterSchema registers a typed-document schema (and, optionally, its inline secondary indexes) on the connected server immediately, mirroring x.RegisterSchema's shape:

client.RegisterSchema[Order](x.IndexOn("ordid", OrdIDAttr))

It is a plain command against the current connection (like Set), so it must be called while connected. The server applies it idempotently: an unchanged schema spec is a no-op and an already-existing index is not recreated, so calling it repeatedly is always safe. When and how often to (re)declare — including anything like re-declaring after a reconnect — is the caller's concern, not this function's.

func RemoveHook added in v0.1.12

func RemoveHook(id HookID)

RemoveHook unregisters the hook with the given id; unknown ids are ignored.

func SearchIndex

func SearchIndex[D x.Document](idxName string, scopedKR x.KeyRange, filter x.Filter, desc bool) mo.Result[[]D]

SearchIndex queries documents in namespace D through a secondary index.

Ordering is by the **indexed field value** (ascending when desc=false, descending when desc=true); ties within a single index value are broken by the primary storage key lexicographically. The passed KeyRange scopes which owner-document primary keys participate in the index scan; pass x.KeysPattern with "<ns>:*" to scan the whole namespace through the index. nil or empty filter is treated as "match every scanned row".

func SearchKey

func SearchKey[D x.Document](scopedKR x.KeyRange, filter x.Filter, desc bool) mo.Result[[]D]

SearchKey queries documents in namespace D by primary storage-key range.

Ordering is by the **primary storage key** (namespace:pk concatenation) in lexicographic order — ascending when desc=false, descending when desc=true. nil or empty filter is treated as "return every row in the key range". Use x.Between, x.Prefix, x.KeysPattern or x.Key to build the scoped KeyRange.

func Set

func Set[D x.Document](d D) error

func SetHookTimeout added in v0.1.12

func SetHookTimeout(d time.Duration)

SetHookTimeout sets the per-hook wall-clock timeout. d <= 0 disables timeouts (panic isolation remains on). Default is 100ms.

func SetNX

func SetNX[D x.Document](d D) (bool, error)

func SetNXWithTTL added in v0.1.3

func SetNXWithTTL[D x.Document](d D, ttl time.Duration) (bool, error)

func SetWithTTL

func SetWithTTL[D x.Document](d D, ttl time.Duration) error

func Subscribe

func Subscribe(topic string) mo.Result[<-chan *ReceivedMessage]

Subscribe registers one local delivery channel for a topic and blocks until the server acknowledges the SUBSCRIBE, then returns that read-only channel.

It records the topic -> channel mapping in deliveryChByTopic, which is the single authoritative registry of subscriptions, and then wakes the background consumer so it can sync the remote SUBSCRIBE state from that registry. The wake-up is a coalescible signal: it can never be lost in a way that leaves the registry and the remote side diverged.

Success means the server confirmed the subscription, so the channel is live. On failure the registration is rolled back, which leaves the topic free to be retried. Duplicate topic registration is rejected.

func Update

func Update[D x.Document](scopedKR x.KeyRange, filter x.Filter, values ...x.Mutation) mo.Result[[]string]

Types

type HookID added in v0.1.12

type HookID = hook.ID

HookID uniquely identifies a registered write hook. The zero value means "invalid" and is a no-op for RemoveHook.

func AddAbortHook added in v0.1.12

func AddAbortHook(h func(key string, value []byte) error) HookID

AddAbortHook registers a fail-closed hook that vetoes the write when it returns an error. Applies to every subsequent write through this client.

func AddObserverAfterHook added in v0.1.12

func AddObserverAfterHook(h func(key string, value []byte, committed bool, writeErr error)) HookID

AddObserverAfterHook registers a fail-open hook that receives the write outcome (final value, committed flag, write error) after commit.

func AddObserverHook added in v0.1.12

func AddObserverHook(h func(key string, value []byte)) HookID

AddObserverHook registers a fail-open hook that inspects the post-Transform value before the write; panics and timeouts are logged, never fail the write.

func AddTransformHook added in v0.1.12

func AddTransformHook(h func(key string, value []byte) ([]byte, error)) HookID

AddTransformHook registers a fail-closed hook that rewrites the value before the write; transforms chain in registration order.

type ReceivedMessage

type ReceivedMessage struct {
	Channel string
	Pattern string
	Payload string
}

ReceivedMessage is a transport-agnostic message exposed to callers.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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