| 1 | package rethinkdb |
| 2 | |
| 3 | import ( |
| 4 | p "gopkg.in/rethinkdb/rethinkdb-go.v6/ql2" |
| 5 | ) |
| 6 | |
| 7 | // TableCreateOpts contains the optional arguments for the TableCreate term |
| 8 | type TableCreateOpts struct { |
| 9 | PrimaryKey interface{} `rethinkdb:"primary_key,omitempty"` |
| 10 | Durability interface{} `rethinkdb:"durability,omitempty"` |
| 11 | Shards interface{} `rethinkdb:"shards,omitempty"` |
| 12 | Replicas interface{} `rethinkdb:"replicas,omitempty"` |
| 13 | PrimaryReplicaTag interface{} `rethinkdb:"primary_replica_tag,omitempty"` |
| 14 | NonVotingReplicaTags interface{} `rethinkdb:"nonvoting_replica_tags,omitempty"` |
| 15 | } |
| 16 | |
| 17 | func (o TableCreateOpts) toMap() map[string]interface{} { |
| 18 | return optArgsToMap(o) |
| 19 | } |
| 20 | |
| 21 | // TableCreate creates a table. A RethinkDB table is a collection of JSON |
| 22 | // documents. |
| 23 | // |
| 24 | // Note: Only alphanumeric characters and underscores are valid for the table name. |
| 25 | func TableCreate(name interface{}, optArgs ...TableCreateOpts) Term { |
| 26 | opts := map[string]interface{}{} |
| 27 | if len(optArgs) >= 1 { |
| 28 | opts = optArgs[0].toMap() |
| 29 | } |
| 30 | return constructRootTerm("TableCreate", p.Term_TABLE_CREATE, []interface{}{name}, opts) |
| 31 | } |
| 32 | |
| 33 | // TableCreate creates a table. A RethinkDB table is a collection of JSON |
| 34 | // documents. |
| 35 | // |
| 36 | // Note: Only alphanumeric characters and underscores are valid for the table name. |
| 37 | func (t Term) TableCreate(name interface{}, optArgs ...TableCreateOpts) Term { |
| 38 | opts := map[string]interface{}{} |
| 39 | if len(optArgs) >= 1 { |
| 40 | opts = optArgs[0].toMap() |
| 41 | } |
| 42 | return constructMethodTerm(t, "TableCreate", p.Term_TABLE_CREATE, []interface{}{name}, opts) |
| 43 | } |
| 44 | |
| 45 | // TableDrop deletes a table. The table and all its data will be deleted. |
| 46 | func TableDrop(args ...interface{}) Term { |
| 47 | return constructRootTerm("TableDrop", p.Term_TABLE_DROP, args, map[string]interface{}{}) |
| 48 | } |
| 49 | |
| 50 | // TableDrop deletes a table. The table and all its data will be deleted. |
| 51 | func (t Term) TableDrop(args ...interface{}) Term { |
| 52 | return constructMethodTerm(t, "TableDrop", p.Term_TABLE_DROP, args, map[string]interface{}{}) |
| 53 | } |
| 54 | |
| 55 | // TableList lists all table names in a database. |
| 56 | func TableList(args ...interface{}) Term { |
| 57 | return constructRootTerm("TableList", p.Term_TABLE_LIST, args, map[string]interface{}{}) |
| 58 | } |
| 59 | |
| 60 | // TableList lists all table names in a database. |
| 61 | func (t Term) TableList(args ...interface{}) Term { |
| 62 | return constructMethodTerm(t, "TableList", p.Term_TABLE_LIST, args, map[string]interface{}{}) |
| 63 | } |
| 64 | |
| 65 | // IndexCreateOpts contains the optional arguments for the IndexCreate term |
| 66 | type IndexCreateOpts struct { |
| 67 | Multi interface{} `rethinkdb:"multi,omitempty"` |
| 68 | Geo interface{} `rethinkdb:"geo,omitempty"` |
| 69 | } |
| 70 | |
| 71 | func (o IndexCreateOpts) toMap() map[string]interface{} { |
| 72 | return optArgsToMap(o) |
| 73 | } |
| 74 | |
| 75 | // IndexCreate creates a new secondary index on a table. Secondary indexes |
| 76 | // improve the speed of many read queries at the slight cost of increased |
| 77 | // storage space and decreased write performance. |
| 78 | // |
| 79 | // IndexCreate supports the creation of the following types of indexes, to create |
| 80 | // indexes using arbitrary expressions use IndexCreateFunc. |
| 81 | // - Simple indexes based on the value of a single field. |
| 82 | // - Geospatial indexes based on indexes of geometry objects, created when the |
| 83 | // geo optional argument is true. |
| 84 | func (t Term) IndexCreate(name interface{}, optArgs ...IndexCreateOpts) Term { |
| 85 | opts := map[string]interface{}{} |
| 86 | if len(optArgs) >= 1 { |
| 87 | opts = optArgs[0].toMap() |
| 88 | } |
| 89 | return constructMethodTerm(t, "IndexCreate", p.Term_INDEX_CREATE, []interface{}{name}, opts) |
| 90 | } |
| 91 | |
| 92 | // IndexCreateFunc creates a new secondary index on a table. Secondary indexes |
| 93 | // improve the speed of many read queries at the slight cost of increased |
| 94 | // storage space and decreased write performance. The function takes a index |
| 95 | // name and RQL term as the index value , the term can be an anonymous function |
| 96 | // or a binary representation obtained from the function field of indexStatus. |
| 97 | // |
| 98 | // It supports the creation of the following types of indexes. |
| 99 | // - Simple indexes based on the value of a single field where the index has a |
| 100 | // different name to the field. |
| 101 | // - Compound indexes based on multiple fields. |
| 102 | // - Multi indexes based on arrays of values, created when the multi optional argument is true. |
| 103 | func (t Term) IndexCreateFunc(name, indexFunction interface{}, optArgs ...IndexCreateOpts) Term { |
| 104 | opts := map[string]interface{}{} |
| 105 | if len(optArgs) >= 1 { |
| 106 | opts = optArgs[0].toMap() |
| 107 | } |
| 108 | return constructMethodTerm(t, "IndexCreate", p.Term_INDEX_CREATE, []interface{}{name, funcWrap(indexFunction)}, opts) |
| 109 | } |
| 110 | |
| 111 | // IndexDrop deletes a previously created secondary index of a table. |
| 112 | func (t Term) IndexDrop(args ...interface{}) Term { |
| 113 | return constructMethodTerm(t, "IndexDrop", p.Term_INDEX_DROP, args, map[string]interface{}{}) |
| 114 | } |
| 115 | |
| 116 | // IndexList lists all the secondary indexes of a table. |
| 117 | func (t Term) IndexList(args ...interface{}) Term { |
| 118 | return constructMethodTerm(t, "IndexList", p.Term_INDEX_LIST, args, map[string]interface{}{}) |
| 119 | } |
| 120 | |
| 121 | // IndexRenameOpts contains the optional arguments for the IndexRename term |
| 122 | type IndexRenameOpts struct { |
| 123 | Overwrite interface{} `rethinkdb:"overwrite,omitempty"` |
| 124 | } |
| 125 | |
| 126 | func (o IndexRenameOpts) toMap() map[string]interface{} { |
| 127 | return optArgsToMap(o) |
| 128 | } |
| 129 | |
| 130 | // IndexRename renames an existing secondary index on a table. |
| 131 | func (t Term) IndexRename(oldName, newName interface{}, optArgs ...IndexRenameOpts) Term { |
| 132 | opts := map[string]interface{}{} |
| 133 | if len(optArgs) >= 1 { |
| 134 | opts = optArgs[0].toMap() |
| 135 | } |
| 136 | return constructMethodTerm(t, "IndexRename", p.Term_INDEX_RENAME, []interface{}{oldName, newName}, opts) |
| 137 | } |
| 138 | |
| 139 | // IndexStatus gets the status of the specified indexes on this table, or the |
| 140 | // status of all indexes on this table if no indexes are specified. |
| 141 | func (t Term) IndexStatus(args ...interface{}) Term { |
| 142 | return constructMethodTerm(t, "IndexStatus", p.Term_INDEX_STATUS, args, map[string]interface{}{}) |
| 143 | } |
| 144 | |
| 145 | // IndexWait waits for the specified indexes on this table to be ready, or for |
| 146 | // all indexes on this table to be ready if no indexes are specified. |
| 147 | func (t Term) IndexWait(args ...interface{}) Term { |
| 148 | return constructMethodTerm(t, "IndexWait", p.Term_INDEX_WAIT, args, map[string]interface{}{}) |
| 149 | } |
| 150 | |
| 151 | // ChangesOpts contains the optional arguments for the Changes term |
| 152 | type ChangesOpts struct { |
| 153 | Squash interface{} `rethinkdb:"squash,omitempty"` |
| 154 | IncludeInitial interface{} `rethinkdb:"include_initial,omitempty"` |
| 155 | IncludeStates interface{} `rethinkdb:"include_states,omitempty"` |
| 156 | IncludeOffsets interface{} `rethinkdb:"include_offsets,omitempty"` |
| 157 | IncludeTypes interface{} `rethinkdb:"include_types,omitempty"` |
| 158 | ChangefeedQueueSize interface{} `rethinkdb:"changefeed_queue_size,omitempty"` |
| 159 | } |
| 160 | |
| 161 | // ChangesOpts contains the optional arguments for the Changes term |
| 162 | func (o ChangesOpts) toMap() map[string]interface{} { |
| 163 | return optArgsToMap(o) |
| 164 | } |
| 165 | |
| 166 | // Changes returns an infinite stream of objects representing changes to a query. |
| 167 | func (t Term) Changes(optArgs ...ChangesOpts) Term { |
| 168 | opts := map[string]interface{}{} |
| 169 | if len(optArgs) >= 1 { |
| 170 | opts = optArgs[0].toMap() |
| 171 | } |
| 172 | return constructMethodTerm(t, "Changes", p.Term_CHANGES, []interface{}{}, opts) |
| 173 | } |