Skip to content

Commit 5f0abf7

Browse files
committed
Added the index_rename command
1 parent 8ee5305 commit 5f0abf7

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

query.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type WriteResponse struct {
100100
Updated int
101101
Unchanged int
102102
Replaced int
103+
Renamed int
103104
Deleted int
104105
GeneratedKeys []string `gorethink:"generated_keys"`
105106
FirstError string `gorethink:"first_error"` // populated if Errors > 0

query_table.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ func (t Term) IndexList(args ...interface{}) Term {
8989
return constructMethodTerm(t, "IndexList", p.Term_INDEX_LIST, args, map[string]interface{}{})
9090
}
9191

92+
type IndexRenameOpts struct {
93+
Overwrite interface{} `gorethink:"overwrite,omitempty"`
94+
}
95+
96+
func (o *IndexRenameOpts) toMap() map[string]interface{} {
97+
return optArgsToMap(o)
98+
}
99+
100+
// IndexRename renames an existing secondary index on a table. If the optional
101+
// argument overwrite is specified as True, a previously existing index with the
102+
// new name will be deleted and the index will be renamed. If overwrite is False
103+
// (the default) an error will be raised if the new index name already exists.
104+
func (t Term) IndexRename(oldName, newName interface{}, optArgs ...IndexRenameOpts) Term {
105+
return constructMethodTerm(t, "IndexRename", p.Term_INDEX_RENAME, []interface{}{oldName, newName}, map[string]interface{}{})
106+
}
107+
92108
// Get the status of the specified indexes on this table, or the status of all
93109
// indexes on this table if no indexes are specified.
94110
func (t Term) IndexStatus(args ...interface{}) Term {

query_table_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ func (s *RethinkSuite) TestTableIndexDelete(c *test.C) {
198198
c.Assert(response, JsonEquals, map[string]interface{}{"dropped": 1})
199199
}
200200

201+
func (s *RethinkSuite) TestTableIndexRename(c *test.C) {
202+
Db("test").TableDrop("test").Exec(sess)
203+
Db("test").TableCreate("test").Exec(sess)
204+
Db("test").Table("test").IndexCreate("test").Exec(sess)
205+
206+
// Test index rename
207+
query := Db("test").Table("test").IndexRename("test", "test2")
208+
209+
res, err := query.RunWrite(sess)
210+
c.Assert(err, test.IsNil)
211+
212+
c.Assert(res.Renamed, JsonEquals, 1)
213+
}
214+
201215
func (s *RethinkSuite) TestTableChanges(c *test.C) {
202216
Db("test").TableDrop("changes").Exec(sess)
203217
Db("test").TableCreate("changes").Exec(sess)

0 commit comments

Comments
 (0)