driver: Index | Examples | Files | Directories

package sdb

import ""



Package Files

client.go connection.go system.go token.go version.go


const (
    AnyVersion = int64(-2)

func ContextWithToken Uses

func ContextWithToken(ctx context.Context, token string) context.Context

ContextWithToken creates a new context with the token attached.

type Client Uses

type Client interface {
    // DB gets a handle for a given database.
    // If a database was specified in the connection string of
    // the client, passing an empty name (""), will returns
    // a handle to that collection.
    DB(name string) DB

    // Databases lists all available databases.
    Databases() ([]string, error)

    Close() error

    System() System

    // Clone clones the client with the provides context.
    Clone(ctx context.Context) Client

    Ping() error

func MustOpen Uses

func MustOpen(connectionString string) Client

See: Open

func MustOpenDefault Uses

func MustOpenDefault() Client

func Open Uses

func Open(connectionString string) (Client, error)

Open opens a connection to the specified streamsdb.

The format of the url is: sdb://[username:password@]host[:port]/[database]?[option_name]=[option_value]

See "connection string documentation" for more information:

func OpenDefault Uses

func OpenDefault() (Client, error)


client, err := sdb.OpenDefault()
if err != nil {
    log.Fatal("connect error", err)

if err := client.Ping(); err != nil {
    log.Fatal("ping error", err)

fmt.Println("Connected to StreamsDB!")


Connected to StreamsDB!

type DB Uses

type DB interface {
    AppendStream(stream string, expectedVersion int64, messages ...MessageInput) (int64, error)
    SubscribeStream(stream string, from int64, limit int) StreamSubscription
    DeleteMessage(stream string, at int64) error
    DeleteStream(stream string) error
    ReadStreamForward(stream string, from int64, limit int) (Slice, error)
    ReadStreamBackward(stream string, from int64, limit int) (Slice, error)
    ReadGlobal(from []byte, limit int) (GlobalSlice, error)
    ListStreamsForward(filter string, after string, limit int) (StreamPage, error)
    ListStreamsBackward(filter string, after string, limit int) (StreamPage, error)

type GlobalSlice Uses

type GlobalSlice struct {
    Database string
    From     []byte
    Next     []byte
    Messages []Message

type Message Uses

type Message struct {
    ID        string
    Position  int64
    Type      string
    Timestamp time.Time
    Header    []byte
    Value     []byte

type MessageInput Uses

type MessageInput struct {
    // The id of the message (not required).
    // If set, this is used for idempotentency. When appending
    // a message streamsdb checks if there is already a message
    // present with this Id. If so, the append is skipped.
    // This makes an append request with messages with id safe for
    // retrying.
    ID  string
    // The name of the message type.
    Type string
    // The headers that will be included in the record.
    Header []byte
    // The content of the message.
    Value []byte

MessageInput holds the data to be appended to a stream.

type Slice Uses

type Slice struct {
    Stream   string
    From     int64
    Next     int64
    HasNext  bool
    Head     int64
    Messages []Message
    Reverse  bool

type StreamPage Uses

type StreamPage struct {
    Total int
    Names []string

    Filter string
    Limit  int

    HasNext   bool
    HasBefore bool

type StreamSubscription Uses

type StreamSubscription struct {

    // Slices returns the available messages. Slices is closed if Cancel()
    // is called; or when an error has accored. Use Err() to get the err
    // if any.
    Slices <-chan Slice
    // contains filtered or unexported fields

StreamSubscription follows a stream. Use the Slices channel to receive slices containing the messages from the remote stream. The Slices channel will be closed if an error occurs or if the subscription was closed.

func (*StreamSubscription) Close Uses

func (this *StreamSubscription) Close()

Close cancels this subscription. The Slices channel will be closed and Err() will return nil.

Calling Close on an cancelled or errored subscription will do nothing.

func (*StreamSubscription) Err Uses

func (this *StreamSubscription) Err() error

Err returns the reason why Slices was closed, if so. If Slices is not closed, Err returns nil. If this subscription is canceled, Err returns nil.

type System Uses

type System interface {
    // Authenticate trades the provided username and password for a token.
    Authenticate(username string, password string) (string, error)
    EnableAcl(username string, password string) error
    CreateUser(username string, password string) error
    CreateDatabase(name string) (DB, error)
    ChangePassword(username string, password string) error
    GrandUserToDatabase(username string, database string) error

type TokenAuth Uses

type TokenAuth string

A authentication token that held a claim from a successful login.

func (TokenAuth) GetRequestMetadata Uses

func (t TokenAuth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

GetRequestMetadata gets the request metadata as a map from the TokenAuth.

func (TokenAuth) RequireTransportSecurity Uses

func (t TokenAuth) RequireTransportSecurity() bool



Package sdb imports 14 packages (graph) and is imported by 1 packages. Updated 2019-12-05. Refresh now. Tools for package owners.