diff --git a/docstore/docstore.go b/docstore/docstore.go index 9bcd0436d..a4bb0b650 100644 --- a/docstore/docstore.go +++ b/docstore/docstore.go @@ -135,20 +135,20 @@ func (c *Collection) Actions() *ActionList { // document; a Get after the write will see the new value if the service is strongly // consistent, but may see the old value if the service is eventually consistent. type ActionList struct { - coll *Collection - actions []*Action - atomicWrites bool - beforeDo func(asFunc func(interface{}) bool) error + coll *Collection + actions []*Action + enableAtomicWrites bool + beforeDo func(asFunc func(interface{}) bool) error } // An Action is a read or write on a single document. // Use the methods of ActionList to create and execute Actions. type Action struct { - kind driver.ActionKind - doc Document - fieldpaths []FieldPath // paths to retrieve, for Get - mods Mods // modifications to make, for Update - transaction bool // if this action is a part of transaction + kind driver.ActionKind + doc Document + fieldpaths []FieldPath // paths to retrieve, for Get + mods Mods // modifications to make, for Update + inAtomicWrite bool // if this action is a part of atomic writes } func (l *ActionList) add(a *Action) *ActionList { @@ -172,7 +172,7 @@ func (l *ActionList) add(a *Action) *ActionList { // Except for setting the revision field and possibly setting the key fields, the doc // argument is not modified. func (l *ActionList) Create(doc Document) *ActionList { - return l.add(&Action{kind: driver.Create, doc: doc, transaction: l.atomicWrites}) + return l.add(&Action{kind: driver.Create, doc: doc, inAtomicWrite: l.enableAtomicWrites}) } // Replace adds an action that replaces a document to the given ActionList, and @@ -184,7 +184,7 @@ func (l *ActionList) Create(doc Document) *ActionList { // See the Revisions section of the package documentation for how revisions are // handled. func (l *ActionList) Replace(doc Document) *ActionList { - return l.add(&Action{kind: driver.Replace, doc: doc, transaction: l.atomicWrites}) + return l.add(&Action{kind: driver.Replace, doc: doc, inAtomicWrite: l.enableAtomicWrites}) } // Put adds an action that adds or replaces a document to the given ActionList, and returns the ActionList. @@ -197,7 +197,7 @@ func (l *ActionList) Replace(doc Document) *ActionList { // See the Revisions section of the package documentation for how revisions are // handled. func (l *ActionList) Put(doc Document) *ActionList { - return l.add(&Action{kind: driver.Put, doc: doc, transaction: l.atomicWrites}) + return l.add(&Action{kind: driver.Put, doc: doc, inAtomicWrite: l.enableAtomicWrites}) } // Delete adds an action that deletes a document to the given ActionList, and returns @@ -212,7 +212,7 @@ func (l *ActionList) Delete(doc Document) *ActionList { // semantics of an action list are to stop at first error, then we might abort a // list of Deletes just because one of the docs was not present, and that seems // wrong, or at least something you'd want to turn off. - return l.add(&Action{kind: driver.Delete, doc: doc, transaction: l.atomicWrites}) + return l.add(&Action{kind: driver.Delete, doc: doc, inAtomicWrite: l.enableAtomicWrites}) } // Get adds an action that retrieves a document to the given ActionList, and @@ -254,10 +254,10 @@ func (l *ActionList) Get(doc Document, fps ...FieldPath) *ActionList { // the updated document, call Get after calling Update. func (l *ActionList) Update(doc Document, mods Mods) *ActionList { return l.add(&Action{ - kind: driver.Update, - doc: doc, - mods: mods, - transaction: l.atomicWrites, + kind: driver.Update, + doc: doc, + mods: mods, + inAtomicWrite: l.enableAtomicWrites, }) } @@ -433,7 +433,7 @@ func (c *Collection) toDriverAction(a *Action) (*driver.Action, error) { // A Put with a revision field is equivalent to a Replace. kind = driver.Replace } - d := &driver.Action{Kind: kind, Doc: ddoc, Key: key, InAtomicWrite: a.transaction} + d := &driver.Action{Kind: kind, Doc: ddoc, Key: key, InAtomicWrite: a.inAtomicWrite} if a.fieldpaths != nil { d.FieldPaths, err = parseFieldPaths(a.fieldpaths) if err != nil { @@ -539,7 +539,7 @@ func (l *ActionList) String() string { // AtomicWrites causes all following writes in the list to execute atomically. func (l *ActionList) AtomicWrites() *ActionList { - l.atomicWrites = true + l.enableAtomicWrites = true return l }