Skip to content

store

import "github.com/alimasry/go-collab-editor/store"

Index

type CachedStore

CachedStore wraps a backing DocumentStore with an in-memory cache. All reads and writes are served from the cache. Dirty documents are flushed to the backing store periodically in the background.

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

func NewCachedStore

func NewCachedStore(backing DocumentStore, flushInterval time.Duration) *CachedStore

NewCachedStore creates a CachedStore that caches in memory and flushes dirty documents to the backing store every flushInterval.

func (*CachedStore) AppendOperation

func (cs *CachedStore) AppendOperation(ctx context.Context, id string, op ot.Operation, version int) error

func (*CachedStore) Close

func (cs *CachedStore) Close()

Close signals the flush loop to perform a final flush and waits for it to complete.

func (*CachedStore) Create

func (cs *CachedStore) Create(ctx context.Context, id, content string) error

func (*CachedStore) Get

func (cs *CachedStore) Get(ctx context.Context, id string) (*DocumentInfo, error)

func (*CachedStore) GetOperations

func (cs *CachedStore) GetOperations(ctx context.Context, id string, fromVersion int) ([]ot.Operation, error)

func (*CachedStore) List

func (cs *CachedStore) List(ctx context.Context) ([]DocumentInfo, error)

func (*CachedStore) UpdateContent

func (cs *CachedStore) UpdateContent(ctx context.Context, id, content string, version int) error

type DocumentInfo

DocumentInfo holds document metadata and content.

type DocumentInfo struct {
    ID        string
    Content   string
    Version   int
    CreatedAt time.Time
    UpdatedAt time.Time
}

type DocumentStore

DocumentStore abstracts document persistence. Implementations: MemoryStore (in-memory), FirestoreStore (Google Cloud Firestore).

type DocumentStore interface {
    Create(ctx context.Context, id, content string) error
    Get(ctx context.Context, id string) (*DocumentInfo, error)
    List(ctx context.Context) ([]DocumentInfo, error)
    UpdateContent(ctx context.Context, id, content string, version int) error
    AppendOperation(ctx context.Context, id string, op ot.Operation, version int) error
    GetOperations(ctx context.Context, id string, fromVersion int) ([]ot.Operation, error)
}

type FirestoreStore

FirestoreStore is a Firestore-backed implementation of DocumentStore.

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

func NewFirestoreStore

func NewFirestoreStore(client *firestore.Client) *FirestoreStore

NewFirestoreStore creates a new FirestoreStore using the given Firestore client.

func (*FirestoreStore) AppendOperation

func (s *FirestoreStore) AppendOperation(ctx context.Context, id string, op ot.Operation, version int) error

func (*FirestoreStore) Create

func (s *FirestoreStore) Create(ctx context.Context, id, content string) error

func (*FirestoreStore) Get

func (s *FirestoreStore) Get(ctx context.Context, id string) (*DocumentInfo, error)

func (*FirestoreStore) GetOperations

func (s *FirestoreStore) GetOperations(ctx context.Context, id string, fromVersion int) ([]ot.Operation, error)

func (*FirestoreStore) List

func (s *FirestoreStore) List(ctx context.Context) ([]DocumentInfo, error)

func (*FirestoreStore) UpdateContent

func (s *FirestoreStore) UpdateContent(ctx context.Context, id, content string, version int) error

type MemoryStore

MemoryStore is an in-memory implementation of DocumentStore.

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) AppendOperation

func (s *MemoryStore) AppendOperation(_ context.Context, id string, op ot.Operation, version int) error

func (*MemoryStore) Create

func (s *MemoryStore) Create(_ context.Context, id, content string) error

func (*MemoryStore) Get

func (s *MemoryStore) Get(_ context.Context, id string) (*DocumentInfo, error)

func (*MemoryStore) GetOperations

func (s *MemoryStore) GetOperations(_ context.Context, id string, fromVersion int) ([]ot.Operation, error)

func (*MemoryStore) List

func (s *MemoryStore) List(_ context.Context) ([]DocumentInfo, error)

func (*MemoryStore) UpdateContent

func (s *MemoryStore) UpdateContent(_ context.Context, id, content string, version int) error

Generated by gomarkdoc