Skip to content

Commit

Permalink
dstore: FirestoreCompatibilityMode
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed Apr 2, 2021
1 parent 1f5d721 commit 28dedbd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dstore/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ type Mem struct {
paths *StringSet
values map[string]*Document
clock tsutil.Clock
mode Mode
}

// Mode for any special behavior.
type Mode string

// Modes for compability
const (
FirestoreCompatibilityMode Mode = "firestore"
)

// NewMem creates an in memory Documents implementation.
func NewMem() *Mem {
return &Mem{
Expand All @@ -43,6 +52,11 @@ func (m *Mem) SetClock(clock tsutil.Clock) {
m.clock = clock
}

// SetMode to set a mode.
func (m *Mem) SetMode(mode Mode) {
m.mode = mode
}

// Create document at path.
// ErrPathExists if entry already exists.
func (m *Mem) Create(ctx context.Context, path string, values map[string]interface{}) error {
Expand Down Expand Up @@ -184,6 +198,9 @@ func (m *Mem) DocumentIterator(ctx context.Context, parent string, opt ...Option
func (m *Mem) Documents(ctx context.Context, parent string, opt ...Option) ([]*Document, error) {
m.RLock()
defer m.RUnlock()
if m.mode == FirestoreCompatibilityMode {
return nil, errors.Errorf("Use DocumentIterator instead (FirestoreCompatibilityMode)")
}

docs, err := m.list(ctx, parent, opt...)
if err != nil {
Expand Down

0 comments on commit 28dedbd

Please sign in to comment.