orda

package
v0.0.0-...-cc9b1f3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Connect() error
	Close() error
	Sync() error
	IsConnected() bool
	CreateDatatype(key string, typeOf model.TypeOfDatatype, handlers *Handlers) Datatype

	CreateCounter(key string, handlers *Handlers) Counter
	SubscribeOrCreateCounter(key string, handlers *Handlers) Counter
	SubscribeCounter(key string, handlers *Handlers) Counter

	CreateMap(key string, handlers *Handlers) Map
	SubscribeOrCreateMap(key string, handlers *Handlers) Map
	SubscribeMap(key string, handlers *Handlers) Map

	CreateList(key string, handlers *Handlers) List
	SubscribeOrCreateList(key string, handlers *Handlers) List
	SubscribeList(key string, handlers *Handlers) List

	CreateDocument(key string, handlers *Handlers) Document
	SubscribeOrCreateDocument(key string, handlers *Handlers) Document
	SubscribeDocument(key string, handlers *Handlers) Document
}

Client is a client of Orda which manages connections and data

func NewClient

func NewClient(conf *ClientConfig, alias string) Client

NewClient creates a new Orda client

type ClientConfig

type ClientConfig struct {
	ServerAddr       string
	NotificationAddr string
	CollectionName   string
	SyncType         model.SyncType
}

ClientConfig is a configuration for OrdaClient

func NewLocalClientConfig

func NewLocalClientConfig(collectionName string) *ClientConfig

NewLocalClientConfig makes a new local client which do not synchronize with OrdaServer

type Counter

type Counter interface {
	Datatype
	CounterInTx
	Transaction(tag string, txFunc func(counter CounterInTx) error) error
}

Counter is an Orda datatype which provides int counter interfaces.

type CounterInTx

type CounterInTx interface {
	Get() int32
	Increase() (int32, errors.OrdaError)
	IncreaseBy(delta int32) (int32, errors.OrdaError)
}

CounterInTx is an Orda datatype which provides int counter interfaces in a transaction.

type Datatype

type Datatype interface {
	GetType() model.TypeOfDatatype
	GetState() model.StateOfDatatype
	GetKey() string // @baseDatatype
	ToJSON() interface{}
}

Datatype is an Orda Datatype which provides common interfaces.

type Document

type Document interface {
	Datatype
	DocumentInTx
	Transaction(tag string, txFunc func(document DocumentInTx) error) error
}

Document is an Orda datatype which provides document (JSON-like) interfaces.

type DocumentInTx

type DocumentInTx interface {
	PutToObject(key string, value interface{}) (Document, errors.OrdaError)
	DeleteInObject(key string) (Document, errors.OrdaError)

	InsertToArray(pos int, value ...interface{}) (Document, errors.OrdaError)
	UpdateManyInArray(pos int, values ...interface{}) ([]Document, errors.OrdaError)
	DeleteInArray(pos int) (Document, errors.OrdaError)
	DeleteManyInArray(pos int, numOfNodes int) ([]Document, errors.OrdaError)

	GetByPath(path string) (Document, errors.OrdaError)

	GetFromObject(key string) (Document, errors.OrdaError)
	GetFromArray(pos int) (Document, errors.OrdaError)
	GetManyFromArray(pos int, numOfNodes int) ([]Document, errors.OrdaError)
	GetValue() interface{}

	Patch(ops ...jsondiff.Operation) errors.OrdaError
	PatchByJSON(jsonStr string) ([]jsondiff.Operation, errors.OrdaError)

	GetParentDocument() Document
	GetRootDocument() Document
	GetTypeOfJSON() TypeOfJSON
	IsGarbage() bool
	Equal(o Document) bool

	ToJSONBytes() []byte
}

DocumentInTx is an Orda datatype which provides document (JSON-like) interfaces in a transaction.

type Handlers

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

Handlers defines a set of handlers which can handles the events related to Datatype

func NewHandlers

func NewHandlers(
	stateChangeHandler func(dt Datatype, old model.StateOfDatatype, new model.StateOfDatatype),
	remoteOperationHandler func(dt Datatype, opList []interface{}),
	errorHandler func(dt Datatype, errs ...errors.OrdaError)) *Handlers

NewHandlers creates a set of handlers for a datatype.

func (*Handlers) SetHandlers

func (its *Handlers) SetHandlers(
	stateChangeHandler func(dt Datatype, old model.StateOfDatatype, new model.StateOfDatatype),
	remoteOperationHandler func(dt Datatype, opList []interface{}),
	errorHandler func(dt Datatype, errs ...errors.OrdaError))

SetHandlers sets the handlers if a given handler is not nil.

type List

type List interface {
	Datatype
	ListInTx
	Transaction(tag string, txFunc func(listTxn ListInTx) error) error
}

List is an Orda datatype which provides the list interfaces.

type ListInTx

type ListInTx interface {
	Insert(pos int, value interface{}) (interface{}, errors.OrdaError)
	InsertMany(pos int, value ...interface{}) (interface{}, errors.OrdaError)
	Get(pos int) (interface{}, errors.OrdaError)
	GetMany(pos int, numOfNodes int) ([]interface{}, errors.OrdaError)
	Delete(pos int) (interface{}, errors.OrdaError)
	DeleteMany(pos int, numOfNodes int) ([]interface{}, errors.OrdaError)
	Update(pos int, values ...interface{}) ([]interface{}, errors.OrdaError)
	Size() int
}

ListInTx is an Orda datatype which provides the list interfaces in a transaction.

type Map

type Map interface {
	Datatype
	MapInTx
	Transaction(tag string, txFunc func(hashMap MapInTx) error) error
}

Map is an Orda datatype which provides the hash map interfaces.

type MapInTx

type MapInTx interface {
	Get(key string) interface{}
	Put(key string, value interface{}) (interface{}, errors.OrdaError)
	Remove(key string) (interface{}, errors.OrdaError)
	Size() int
}

MapInTx is an Orda datatype which provides hash map interface in a transaction.

type TypeOfJSON

type TypeOfJSON int

TypeOfJSON is a type to denote the type of JSON.

const (

	// TypeJSONElement denotes a JSON element type.
	TypeJSONElement TypeOfJSON
	// TypeJSONObject denotes a JSON object type.
	TypeJSONObject
	// TypeJSONArray denotes a JSON array type.
	TypeJSONArray
)

func (TypeOfJSON) Name

func (its TypeOfJSON) Name() string

Name returns the name of JSONType

Jump to

Keyboard shortcuts

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