...

Package api

import "bitbucket.org/twicedb/twicedb-go/client/api"
Overview
Index
Subdirectories

Overview ▾

Package api defines the TwiceDB client API.

Index ▾

Constants
func ProjectedFieldsToProtos(objectProjectedFields map[shared.ProjectedFieldKey]*shared.ProjectedFieldValue) ([]*projectp.ProjectedField, error)
type Client
type Event
type EventF
    func (e *EventF) Equal(o any) bool
    func (ev *EventF) EventId() shared.EventId
    func (ev *EventF) SetEventId(eid shared.EventId) error
    func (ev *EventF) SetTt(tt shared.Tt) error
    func (ev *EventF) Tt() shared.Tt
type Indexable
type IndexableF
    func (i *IndexableF) BackfillTt() shared.BackfillTt
    func (i *IndexableF) Equal(o any) bool
    func (i *IndexableF) LastWrite() shared.Tt
    func (i *IndexableF) ObjectId() shared.ObjectId
    func (i *IndexableF) Refs() *sync.Map
    func (i *IndexableF) ResetBackfillTt(bt shared.BackfillTt)
    func (i *IndexableF) ResolvedRefs() *sync.Map
    func (i *IndexableF) SetBackfillTt(bt shared.BackfillTt) error
    func (i *IndexableF) SetLastWrite(lw shared.Tt) error
    func (i *IndexableF) SetObjectId(oid shared.ObjectId) error
    func (i *IndexableF) SetTimesliceId(tid shared.TimesliceId) error
    func (i *IndexableF) SetTtFrom(tt shared.Tt) error
    func (i *IndexableF) SetTtResolvedAt(tt shared.Tt) error
    func (i *IndexableF) SetTtTo(tt shared.Tt) error
    func (i *IndexableF) SetVtFrom(vt shared.Vt) error
    func (i *IndexableF) SetVtResolvedAt(vt shared.Vt) error
    func (i *IndexableF) SetVtTo(vt shared.Vt) error
    func (i *IndexableF) TimesliceId() shared.TimesliceId
    func (i *IndexableF) TtFrom() shared.Tt
    func (i *IndexableF) TtResolvedAt() shared.Tt
    func (i *IndexableF) TtTo() shared.Tt
    func (i *IndexableF) VtFrom() shared.Vt
    func (i *IndexableF) VtResolvedAt() shared.Vt
    func (i *IndexableF) VtTo() shared.Vt
type IndexedQuery
    func NewEmptyIndexedQuery(ixbl Indexable) *IndexedQuery
    func (iq *IndexedQuery) Equal(iqOther *IndexedQuery) bool
    func (iq *IndexedQuery) Indexes() []*indexp.IndexCondition
    func (iq *IndexedQuery) Ixbl() Indexable
    func (iq *IndexedQuery) ReadObjects(c Client, tc *shared.TemporalCoordinates) ([]Indexable, error)
    func (iq *IndexedQuery) ReadObjectsAsync(c Client, tc *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    func (iq *IndexedQuery) SetIndexes(indexes []*indexp.IndexCondition)
    func (iq *IndexedQuery) WhereEq(field string, value interface{}) *IndexedQuery
    func (iq *IndexedQuery) WhereEqUnique(field string, value interface{}) *IndexedQuery
    func (iq *IndexedQuery) WhereGt(field string, value interface{}) *IndexedQuery
    func (iq *IndexedQuery) WhereGte(field string, value interface{}) *IndexedQuery
    func (iq *IndexedQuery) WhereLt(field string, value interface{}) *IndexedQuery
    func (iq *IndexedQuery) WhereLte(field string, value interface{}) *IndexedQuery
type ObjectIterator
type PlainEvent
    func NewPlainEvent() *PlainEvent
    func NewPlainEventWithEventId(eventId shared.EventId) *PlainEvent
    func (o *PlainEvent) Blob() (shared.EventBlob, error)
    func (o *PlainEvent) Fqn() shared.Fqn
    func (o *PlainEvent) GenerateEventId() shared.EventId
    func (o *PlainEvent) GetEvent(c Client, eventId shared.EventId) (*PlainEvent, error)
    func (o *PlainEvent) GetEventAsync(c Client, eventId shared.EventId) chan *PlainEventAsyncResponse
    func (o *PlainEvent) InstantiateEventFromBlob(eb shared.EventBlob, eventId shared.EventId, tt shared.Tt) (*PlainEvent, error)
    func (o *PlainEvent) ProjectedFields() map[shared.ProjectedFieldKey]*shared.ProjectedFieldValue
type PlainEventAsyncResponse
type ProjectOp
type ProvidesEventId
type ProvidesFqn
type ProvidesObjectId
type Txn

Package files

client.go doc.go event.go indexable.go indexed_query.go object_iterator.go plain_event.go plain_event_accessors.go plain_event_constructor.go project_op.go projected_fields_converter.go provides_event_id.go provides_fqn.go provides_object_id.go txn.go

Constants

const (
    ClazzKey = "clazz"
)

func ProjectedFieldsToProtos

func ProjectedFieldsToProtos(objectProjectedFields map[shared.ProjectedFieldKey]*shared.ProjectedFieldValue) ([]*projectp.ProjectedField, error)

type Client

type Client interface {
    CatchUpLsqt(shared.Tt, time.Duration) (shared.Lsqt, error)
    CommitTxn(Txn) (*cshared.WrittenTransaction, error)
    CommitTxnAsync(Txn) chan cshared.WriteAsyncResponse
    Context() context.Context
    Delete(context.Context, shared.ObjectId, shared.Tt, shared.Vt) (*cshared.WrittenObject, error)
    DeleteAsync(context.Context, shared.ObjectId, shared.Tt, shared.Vt) chan cshared.WriteAsyncResponse
    DeleteObject(context.Context, Indexable, shared.Vt) (*cshared.WrittenObject, error)
    DeleteObjectAsync(context.Context, Indexable, shared.Vt) chan cshared.WriteAsyncResponse
    Lsqt() shared.Lsqt
    Put(context.Context, shared.ObjectId, shared.Tt, shared.Vt, *shared.Blob) (*cshared.WrittenObject, error)
    PutAsync(context.Context, shared.ObjectId, shared.Tt, shared.Vt, *shared.Blob) chan cshared.WriteAsyncResponse
    PutObject(context.Context, Indexable, shared.Tt, shared.Vt) (*cshared.WrittenObject, error)
    PutObjectAsync(context.Context, Indexable, shared.Tt, shared.Vt) chan cshared.WriteAsyncResponse
    ReadEvent(context.Context, shared.EventId, shared.Fqn, shared.Tt) (shared.Event, error)
    ReadEventAsync(context.Context, shared.EventId, shared.Fqn, shared.Tt) chan cshared.ReadAsyncResponse
    ReadEventForObject(context.Context, Indexable) (shared.Event, error)
    ReadEventForObjectAsync(context.Context, Indexable) chan cshared.ReadAsyncResponse
    ReadObject(context.Context, Indexable, *shared.TemporalCoordinates) (*cshared.ReadObject, error)
    ReadObjectAsync(context.Context, Indexable, *shared.TemporalCoordinates) chan cshared.ReadObject
    ReadObjects(context.Context, Indexable, *shared.TemporalCoordinates) ([]Indexable, error)
    ReadObjectsAsync(context.Context, Indexable, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    ReadObjectsByEvent(context.Context, shared.Event) ([]Indexable, error)
    ReadObjectsByEventAsync(context.Context, shared.Event) chan Indexable
    // No async version for this because it powers an Iterator.
    ReadObjectsByFqn(context.Context, shared.Fqn, shared.Tt, shared.TimesliceId, shared.Tt, shared.BatchSize) ([]Indexable, error)
    ReadObjectsByIndexedQuery(context.Context, *IndexedQuery, *shared.TemporalCoordinates) ([]Indexable, error)
    ReadObjectsByIndexedQueryAsync(context.Context, *IndexedQuery, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    ReadObjectsToIndexables([]*cshared.ReadObject) ([]Indexable, error)
    ReadPoint(context.Context, shared.ObjectId, *shared.TemporalCoordinates) (*cshared.ReadObject, error)
    ReadPointAsync(context.Context, shared.ObjectId, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    Reinstate(context.Context, shared.ObjectId, shared.Tt, shared.Vt) (*cshared.WrittenObject, error)
    ReinstateAsync(context.Context, shared.ObjectId, shared.Tt, shared.Vt) chan cshared.WriteAsyncResponse
    ReinstateObject(context.Context, Indexable, shared.Tt, shared.Vt) (*cshared.WrittenObject, error)
    ReinstateObjectAsync(context.Context, Indexable, shared.Tt, shared.Vt) chan cshared.WriteAsyncResponse
    Start()
    // Aggregations
    CountByIndexedQuery(*IndexedQuery, *shared.TemporalCoordinates) (*big.Int, bool, error)
    CountByIndexedQueryAsync(*IndexedQuery, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    MaxByIndexedQuery(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) (*big.Rat, bool, error)
    MaxByIndexedQueryAsync(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    MeanByIndexedQuery(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) (*big.Rat, bool, error)
    MeanByIndexedQueryAsync(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    MedianByIndexedQuery(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) (*big.Rat, bool, error)
    MedianByIndexedQueryAsync(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    MinByIndexedQuery(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) (*big.Rat, bool, error)
    MinByIndexedQueryAsync(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    PercentileByIndexedQuery(*IndexedQuery, shared.ProjectedFieldKey, shared.Percentile, *shared.TemporalCoordinates) (*big.Rat, bool, error)
    PercentileByIndexedQueryAsync(*IndexedQuery, shared.ProjectedFieldKey, shared.Percentile, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    StdevByIndexedQuery(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) (*big.Rat, bool, error)
    StdevByIndexedQueryAsync(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    SumByIndexedQuery(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) (*big.Rat, bool, error)
    SumByIndexedQueryAsync(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    VarByIndexedQuery(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) (*big.Rat, bool, error)
    VarByIndexedQueryAsync(*IndexedQuery, shared.ProjectedFieldKey, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    // Lock / Unlock Fqns
    ListLockedFqns(context.Context) ([]shared.Fqn, error)
    LockFqn(context.Context, shared.Fqn) (shared.Tt, error)
    UnlockFqn(context.Context, shared.Fqn) (shared.Tt, error)
    // Reindex
    ReindexObject(context.Context, Indexable) (*cshared.WrittenObject, error)
    ReindexObjectAsync(context.Context, Indexable) chan cshared.WriteAsyncResponse
    // Subscribe
    SubscribeToIndexedQuery(context.Context, *IndexedQuery) (cshared.SubscriptionId, chan cshared.SubscribeResponse, error)
    SubscribeToObjectId(context.Context, shared.ObjectId) (cshared.SubscriptionId, chan cshared.SubscribeResponse, error)
    // Tt timeline
    ReadObjectsAtVt(context.Context, Indexable, *shared.TemporalCoordinates) ([]Indexable, error)
    ReadObjectsAtVtAsync(context.Context, Indexable, *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse
    // Vt timeline
    ReadObjectsAtTt(context.Context, Indexable, shared.Tt) ([]Indexable, error)
    ReadObjectsAtTtAsync(context.Context, Indexable, shared.Tt) chan cshared.ReadAsyncResponse
    // Server status
    ServerStatus(context.Context, cshared.ServerType) (*cshared.ServerStatus, error)
    // Reload config
    ReloadConfig(context.Context) error
    // Entitlements
    Entitle(context.Context, shared.EmailAddress, shared.Fqn, cshared.ReadEntitlement, cshared.WriteEntitlement, cshared.EntitleEntitlement, shared.Vt, *shared.BackfillTt) (shared.Tt, error)
}

type Event

Event is an interface that is used to persist metadata about database events.

type Event interface {
    Equal(any) bool
    EventId() shared.EventId
    SetEventId(shared.EventId) error
    Tt() shared.Tt
    SetTt(tt shared.Tt) error
}

type EventF

type EventF struct {
    // contains filtered or unexported fields
}

func (*EventF) Equal

func (e *EventF) Equal(o any) bool

func (*EventF) EventId

func (ev *EventF) EventId() shared.EventId

func (*EventF) SetEventId

func (ev *EventF) SetEventId(eid shared.EventId) error

func (*EventF) SetTt

func (ev *EventF) SetTt(tt shared.Tt) error

func (*EventF) Tt

func (ev *EventF) Tt() shared.Tt

type Indexable

Indexable is an interface that is used to persist metadata about database objects.

type Indexable interface {
    BackfillTt() shared.BackfillTt
    EnsureCanProjectField(string, ProjectOp)
    EnsureCanQueryField(string)
    Equal(any) bool
    Fqn() shared.Fqn
    IndexedQuery() *IndexedQuery
    ProjectedFields() map[shared.ProjectedFieldKey]*shared.ProjectedFieldValue
    LastWrite() shared.Tt
    ObjectId() shared.ObjectId
    ResolvedRefs() *sync.Map
    SetObjectId(shared.ObjectId) error
    SetBackfillTt(shared.BackfillTt) error
    SetLastWrite(shared.Tt) error
    SetTtFrom(shared.Tt) error
    SetTtTo(shared.Tt) error
    SetVtFrom(shared.Vt) error
    SetVtTo(shared.Vt) error
    TtFrom() shared.Tt
    TtResolvedAt() shared.Tt
    SetTtResolvedAt(shared.Tt) error
    VtResolvedAt() shared.Vt
    SetVtResolvedAt(shared.Vt) error
    TimesliceId() shared.TimesliceId
    SetTimesliceId(shared.TimesliceId) error
}

type IndexableF

IndexableF provides a base set of fields to make working with structs as database objects easier.

type IndexableF struct {
    // contains filtered or unexported fields
}

func (*IndexableF) BackfillTt

func (i *IndexableF) BackfillTt() shared.BackfillTt

BackfillTt returns the Tt at which the object was backfilled.

func (*IndexableF) Equal

func (i *IndexableF) Equal(o any) bool

func (*IndexableF) LastWrite

func (i *IndexableF) LastWrite() shared.Tt

LastWrite returns the lastWrite.

func (*IndexableF) ObjectId

func (i *IndexableF) ObjectId() shared.ObjectId

ObjectId returns the objectId.

func (*IndexableF) Refs

func (i *IndexableF) Refs() *sync.Map

func (*IndexableF) ResetBackfillTt

func (i *IndexableF) ResetBackfillTt(bt shared.BackfillTt)

ResetBackfillTt resets the backfillTt. Unlike SetBackfillTt, this will not error if called more than once.

func (*IndexableF) ResolvedRefs

func (i *IndexableF) ResolvedRefs() *sync.Map

func (*IndexableF) SetBackfillTt

func (i *IndexableF) SetBackfillTt(bt shared.BackfillTt) error

SetBackfillTt sets the backfillTt. This will error if called more than once since an object's BackfillTt cannot change.

func (*IndexableF) SetLastWrite

func (i *IndexableF) SetLastWrite(lw shared.Tt) error

SetLastWrite sets the lastWrite. Unlike the objectId, the lastWrite does change as data is modified, so this can be called more than once.

func (*IndexableF) SetObjectId

func (i *IndexableF) SetObjectId(oid shared.ObjectId) error

SetObjectId sets the objectId. This will error if called more than once since an object's ObjectId cannot change.

func (*IndexableF) SetTimesliceId

func (i *IndexableF) SetTimesliceId(tid shared.TimesliceId) error

SetTimesliceId sets the TimesliceId of the object's data. This will error if called more than once since an object's timesliceId cannot change.

func (*IndexableF) SetTtFrom

func (i *IndexableF) SetTtFrom(tt shared.Tt) error

SetTtFrom sets the ttFrom. This will error if called more than once since an object's TtFrom cannot change.

func (*IndexableF) SetTtResolvedAt

func (i *IndexableF) SetTtResolvedAt(tt shared.Tt) error

SetTtResolvedAt sets the Tt at which the object was loaded. This will error if called more than once since an object's ttResolvedAt cannot change.

func (*IndexableF) SetTtTo

func (i *IndexableF) SetTtTo(tt shared.Tt) error

SetTtTo sets the ttTo. This will error if called more than once since an object's TtTo cannot change.

func (*IndexableF) SetVtFrom

func (i *IndexableF) SetVtFrom(vt shared.Vt) error

SetVtFrom sets the vtFrom. This will error if called more than once since an object's vtFrom cannot change.

func (*IndexableF) SetVtResolvedAt

func (i *IndexableF) SetVtResolvedAt(vt shared.Vt) error

SetVtResolvedAt sets the Vt at which the object was loaded. This will error if called more than once since an object's vtResolvedAt cannot change.

func (*IndexableF) SetVtTo

func (i *IndexableF) SetVtTo(vt shared.Vt) error

SetVtTo sets the vtFrom. This will error if called more than once since an object's vtFrom cannot change.

func (*IndexableF) TimesliceId

func (i *IndexableF) TimesliceId() shared.TimesliceId

TimesliceId returns the TimesliceId of the object's data.

func (*IndexableF) TtFrom

func (i *IndexableF) TtFrom() shared.Tt

TtFrom returns the Tt at which the object was written to the database.

func (*IndexableF) TtResolvedAt

func (i *IndexableF) TtResolvedAt() shared.Tt

TtResolvedAt returns the Tt at which the object was loaded.

func (*IndexableF) TtTo

func (i *IndexableF) TtTo() shared.Tt

TtTo returns the Tt at which the object becomes invalid because, for example, it was deleted.

func (*IndexableF) VtFrom

func (i *IndexableF) VtFrom() shared.Vt

VtFrom returns the Vt at which the object was written to the database.

func (*IndexableF) VtResolvedAt

func (i *IndexableF) VtResolvedAt() shared.Vt

VtResolvedAt returns the Vt at which the object was loaded.

func (*IndexableF) VtTo

func (i *IndexableF) VtTo() shared.Vt

VtTo returns the Vt at which the object becomes invalid because, for example, it was deleted.

type IndexedQuery

type IndexedQuery struct {
    // contains filtered or unexported fields
}

func NewEmptyIndexedQuery

func NewEmptyIndexedQuery(ixbl Indexable) *IndexedQuery

func (*IndexedQuery) Equal

func (iq *IndexedQuery) Equal(iqOther *IndexedQuery) bool

func (*IndexedQuery) Indexes

func (iq *IndexedQuery) Indexes() []*indexp.IndexCondition

func (*IndexedQuery) Ixbl

func (iq *IndexedQuery) Ixbl() Indexable

func (*IndexedQuery) ReadObjects

func (iq *IndexedQuery) ReadObjects(c Client, tc *shared.TemporalCoordinates) ([]Indexable, error)

func (*IndexedQuery) ReadObjectsAsync

func (iq *IndexedQuery) ReadObjectsAsync(c Client, tc *shared.TemporalCoordinates) chan cshared.ReadAsyncResponse

func (*IndexedQuery) SetIndexes

func (iq *IndexedQuery) SetIndexes(indexes []*indexp.IndexCondition)

func (*IndexedQuery) WhereEq

func (iq *IndexedQuery) WhereEq(field string, value interface{}) *IndexedQuery

FIXME: Write tests for these.

func (*IndexedQuery) WhereEqUnique

func (iq *IndexedQuery) WhereEqUnique(field string, value interface{}) *IndexedQuery

This is used only internally to set indexes to unique.

func (*IndexedQuery) WhereGt

func (iq *IndexedQuery) WhereGt(field string, value interface{}) *IndexedQuery

func (*IndexedQuery) WhereGte

func (iq *IndexedQuery) WhereGte(field string, value interface{}) *IndexedQuery

func (*IndexedQuery) WhereLt

func (iq *IndexedQuery) WhereLt(field string, value interface{}) *IndexedQuery

func (*IndexedQuery) WhereLte

func (iq *IndexedQuery) WhereLte(field string, value interface{}) *IndexedQuery

type ObjectIterator

type ObjectIterator[T Indexable] interface {
    HasNext() (bool, error)
    Next() (T, error)
}

type PlainEvent

type PlainEvent struct {
    EventF
}

func NewPlainEvent

func NewPlainEvent() *PlainEvent

func NewPlainEventWithEventId

func NewPlainEventWithEventId(eventId shared.EventId) *PlainEvent

func (*PlainEvent) Blob

func (o *PlainEvent) Blob() (shared.EventBlob, error)

func (*PlainEvent) Fqn

func (o *PlainEvent) Fqn() shared.Fqn

func (*PlainEvent) GenerateEventId

func (o *PlainEvent) GenerateEventId() shared.EventId

func (*PlainEvent) GetEvent

func (o *PlainEvent) GetEvent(c Client, eventId shared.EventId) (*PlainEvent, error)

func (*PlainEvent) GetEventAsync

func (o *PlainEvent) GetEventAsync(c Client, eventId shared.EventId) chan *PlainEventAsyncResponse

func (*PlainEvent) InstantiateEventFromBlob

func (o *PlainEvent) InstantiateEventFromBlob(eb shared.EventBlob, eventId shared.EventId, tt shared.Tt) (*PlainEvent, error)

func (*PlainEvent) ProjectedFields

func (o *PlainEvent) ProjectedFields() map[shared.ProjectedFieldKey]*shared.ProjectedFieldValue

type PlainEventAsyncResponse

type PlainEventAsyncResponse struct {
    Event *PlainEvent
    Error error
}

type ProjectOp

type ProjectOp int8
const (
    ProjectOpCount ProjectOp = iota
    ProjectOpMax
    ProjectOpMean
    ProjectOpMedian
    ProjectOpMin
    ProjectOpPercentile
    ProjectOpStdev
    ProjectOpSum
    ProjectOpVar
)

type ProvidesEventId

type ProvidesEventId interface {
    ProvidedEventId() shared.EventId
}

type ProvidesFqn

type ProvidesFqn interface {
    ProvidedFqn() shared.Fqn
}

type ProvidesObjectId

type ProvidesObjectId interface {
    ProvidedObjectId() shared.ObjectId
}

type Txn

type Txn interface {
    Delete(objectId shared.ObjectId, lastRead shared.Tt, vtFrom shared.Vt)
    Put(objectId shared.ObjectId, lastRead shared.Tt, vtFrom shared.Vt, blob *shared.Blob)
    Reinstate(objectId shared.ObjectId, lastRead shared.Tt, vtFrom shared.Vt)
    DeleteObject(object Indexable, vtFrom shared.Vt) error
    PutObject(object Indexable, vtFrom shared.Vt) error
    ReinstateObject(object Indexable, vtFrom shared.Vt) error
    HasEvent() bool
    Event() (shared.Event, error)
    SetEvent(ev shared.Event) error
    Objects() []Indexable
    WriteCommands() []*writerp.WriteRequest_WriteCommand
}

Subdirectories

Name Synopsis
..
constants Package constants defines constants used throughout the TwiceDB client API.