gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/query_write.go (about)

     1  package rethinkdb
     2  
     3  import (
     4  	p "gopkg.in/rethinkdb/rethinkdb-go.v6/ql2"
     5  )
     6  
     7  // InsertOpts contains the optional arguments for the Insert term
     8  type InsertOpts struct {
     9  	Durability      interface{} `gorethink:"durability,omitempty"`
    10  	ReturnChanges   interface{} `gorethink:"return_changes,omitempty"`
    11  	Conflict        interface{} `gorethink:"conflict,omitempty"`
    12  	IgnoreWriteHook interface{} `gorethink:"ignore_write_hook,omitempty"`
    13  }
    14  
    15  func (o InsertOpts) toMap() map[string]interface{} {
    16  	return optArgsToMap(o)
    17  }
    18  
    19  // Insert documents into a table. Accepts a single document or an array
    20  // of documents.
    21  func (t Term) Insert(arg interface{}, optArgs ...InsertOpts) Term {
    22  	opts := map[string]interface{}{}
    23  	if len(optArgs) >= 1 {
    24  		opts = optArgs[0].toMap()
    25  	}
    26  	return constructMethodTerm(t, "Insert", p.Term_INSERT, []interface{}{Expr(arg)}, opts)
    27  }
    28  
    29  // UpdateOpts contains the optional arguments for the Update term
    30  type UpdateOpts struct {
    31  	Durability      interface{} `gorethink:"durability,omitempty"`
    32  	ReturnChanges   interface{} `gorethink:"return_changes,omitempty"`
    33  	NonAtomic       interface{} `gorethink:"non_atomic,omitempty"`
    34  	Conflict        interface{} `gorethink:"conflict,omitempty"`
    35  	IgnoreWriteHook interface{} `gorethink:"ignore_write_hook,omitempty"`
    36  }
    37  
    38  func (o UpdateOpts) toMap() map[string]interface{} {
    39  	return optArgsToMap(o)
    40  }
    41  
    42  // Update JSON documents in a table. Accepts a JSON document, a ReQL expression,
    43  // or a combination of the two. You can pass options like returnChanges that will
    44  // return the old and new values of the row you have modified.
    45  func (t Term) Update(arg interface{}, optArgs ...UpdateOpts) Term {
    46  	opts := map[string]interface{}{}
    47  	if len(optArgs) >= 1 {
    48  		opts = optArgs[0].toMap()
    49  	}
    50  	return constructMethodTerm(t, "Update", p.Term_UPDATE, []interface{}{funcWrap(arg)}, opts)
    51  }
    52  
    53  // ReplaceOpts contains the optional arguments for the Replace term
    54  type ReplaceOpts struct {
    55  	Durability      interface{} `gorethink:"durability,omitempty"`
    56  	ReturnChanges   interface{} `gorethink:"return_changes,omitempty"`
    57  	NonAtomic       interface{} `gorethink:"non_atomic,omitempty"`
    58  	IgnoreWriteHook interface{} `gorethink:"ignore_write_hook,omitempty"`
    59  }
    60  
    61  func (o ReplaceOpts) toMap() map[string]interface{} {
    62  	return optArgsToMap(o)
    63  }
    64  
    65  // Replace documents in a table. Accepts a JSON document or a ReQL expression,
    66  // and replaces the original document with the new one. The new document must
    67  // have the same primary key as the original document.
    68  func (t Term) Replace(arg interface{}, optArgs ...ReplaceOpts) Term {
    69  	opts := map[string]interface{}{}
    70  	if len(optArgs) >= 1 {
    71  		opts = optArgs[0].toMap()
    72  	}
    73  	return constructMethodTerm(t, "Replace", p.Term_REPLACE, []interface{}{funcWrap(arg)}, opts)
    74  }
    75  
    76  // DeleteOpts contains the optional arguments for the Delete term
    77  type DeleteOpts struct {
    78  	Durability      interface{} `gorethink:"durability,omitempty"`
    79  	ReturnChanges   interface{} `gorethink:"return_changes,omitempty"`
    80  	IgnoreWriteHook interface{} `gorethink:"ignore_write_hook,omitempty"`
    81  }
    82  
    83  func (o DeleteOpts) toMap() map[string]interface{} {
    84  	return optArgsToMap(o)
    85  }
    86  
    87  // Delete one or more documents from a table.
    88  func (t Term) Delete(optArgs ...DeleteOpts) Term {
    89  	opts := map[string]interface{}{}
    90  	if len(optArgs) >= 1 {
    91  		opts = optArgs[0].toMap()
    92  	}
    93  	return constructMethodTerm(t, "Delete", p.Term_DELETE, []interface{}{}, opts)
    94  }
    95  
    96  // Sync ensures that writes on a given table are written to permanent storage.
    97  // Queries that specify soft durability do not give such guarantees, so Sync
    98  // can be used to ensure the state of these queries. A call to Sync does not
    99  // return until all previous writes to the table are persisted.
   100  func (t Term) Sync(args ...interface{}) Term {
   101  	return constructMethodTerm(t, "Sync", p.Term_SYNC, args, map[string]interface{}{})
   102  }