forked from rethinkdb/rethinkdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_manipulation.go
113 lines (91 loc) · 4.99 KB
/
query_manipulation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package gorethink
import (
p "github.com/dancannon/gorethink/ql2"
)
// Returns the currently visited document.
var Row = newRqlTerm("Doc", p.Term_IMPLICIT_VAR, []interface{}{}, map[string]interface{}{})
func Literal(args ...interface{}) RqlTerm {
enforceArgLength(0, 1, args)
return newRqlTerm("Literal", p.Term_LITERAL, args, map[string]interface{}{})
}
// Get a single field from an object. If called on a sequence, gets that field
// from every object in the sequence, skipping objects that lack it.
func (t RqlTerm) Field(field interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "Field", p.Term_GET_FIELD, []interface{}{field}, map[string]interface{}{})
}
// Test if an object has all of the specified fields. An object has a field if
// it has the specified key and that key maps to a non-null value. For instance,
// the object `{'a':1,'b':2,'c':null}` has the fields `a` and `b`.
func (t RqlTerm) HasFields(fields ...interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "HasFields", p.Term_HAS_FIELDS, fields, map[string]interface{}{})
}
// Plucks out one or more attributes from either an object or a sequence of
// objects (projection).
func (t RqlTerm) Pluck(fields ...interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "Pluck", p.Term_PLUCK, fields, map[string]interface{}{})
}
// The opposite of pluck; takes an object or a sequence of objects, and returns
// them with the specified paths removed.
func (t RqlTerm) Without(fields ...interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "Without", p.Term_WITHOUT, fields, map[string]interface{}{})
}
// Merge two objects together to construct a new object with properties from both.
// Gives preference to attributes from other when there is a conflict.
func (t RqlTerm) Merge(arg interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "Merge", p.Term_MERGE, []interface{}{arg}, map[string]interface{}{})
}
// Append a value to an array.
func (t RqlTerm) Append(arg interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "Append", p.Term_APPEND, []interface{}{arg}, map[string]interface{}{})
}
// Prepend a value to an array.
func (t RqlTerm) Prepend(arg interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "Prepend", p.Term_PREPEND, []interface{}{arg}, map[string]interface{}{})
}
// Remove the elements of one array from another array.
func (t RqlTerm) Difference(arg interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "Difference", p.Term_DIFFERENCE, []interface{}{arg}, map[string]interface{}{})
}
// Add a value to an array and return it as a set (an array with distinct values).
func (t RqlTerm) SetInsert(arg interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "SetInsert", p.Term_SET_INSERT, []interface{}{arg}, map[string]interface{}{})
}
// Add a several values to an array and return it as a set (an array with
// distinct values).
func (t RqlTerm) SetUnion(arg interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "SetUnion", p.Term_SET_UNION, []interface{}{arg}, map[string]interface{}{})
}
// Intersect two arrays returning values that occur in both of them as a set (an
// array with distinct values).
func (t RqlTerm) SetIntersection(arg interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "SetIntersection", p.Term_SET_INTERSECTION, []interface{}{arg}, map[string]interface{}{})
}
// Remove the elements of one array from another and return them as a set (an
// array with distinct values).
func (t RqlTerm) SetDifference(arg interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "SetDifference", p.Term_SET_DIFFERENCE, []interface{}{arg}, map[string]interface{}{})
}
// Insert a value in to an array at a given index. Returns the modified array.
func (t RqlTerm) InsertAt(index, value interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "InsertAt", p.Term_INSERT_AT, []interface{}{index, value}, map[string]interface{}{})
}
// Insert several values in to an array at a given index. Returns the modified array.
func (t RqlTerm) SpliceAt(index, value interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "SpliceAt", p.Term_SPLICE_AT, []interface{}{index, value}, map[string]interface{}{})
}
// Remove an element from an array at a given index. Returns the modified array.
func (t RqlTerm) DeleteAt(index interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "DeleteAt", p.Term_DELETE_AT, []interface{}{index}, map[string]interface{}{})
}
// Remove the elements between the given range. Returns the modified array.
func (t RqlTerm) DeleteAtRange(index, endIndex interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "DeleteAt", p.Term_DELETE_AT, []interface{}{index, endIndex}, map[string]interface{}{})
}
// Change a value in an array at a given index. Returns the modified array.
func (t RqlTerm) ChangeAt(index, value interface{}) RqlTerm {
return newRqlTermFromPrevVal(t, "ChangeAt", p.Term_CHANGE_AT, []interface{}{index, value}, map[string]interface{}{})
}
// Return an array containing all of the object's keys.
func (t RqlTerm) Keys() RqlTerm {
return newRqlTermFromPrevVal(t, "Keys", p.Term_KEYS, []interface{}{}, map[string]interface{}{})
}