Skip to content

Instantly share code, notes, and snippets.

@mirhec
Created January 17, 2015 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirhec/6aeca7c922e702e4d77d to your computer and use it in GitHub Desktop.
Save mirhec/6aeca7c922e702e4d77d to your computer and use it in GitHub Desktop.
###
## This creates the given index for the given
## table. If there occurs an error
## it will be printed out. If it succeeds, the
## callback next will be called.
###
createIndex: (tableName, indexName, next) ->
r.table(tableName).indexCreate(indexName).run @conn, (err, result) =>
if (err) and (not err.message.match(/Index `.*` already exists/))
console.log "Could not create the index `" + tableName + "." + indexName + "`"
console.log err
process.exit 1
console.log "Index `" + tableName + "." + indexName + "` created."
r.table(tableName).indexWait(indexName).run @conn, (err, result) =>
if err
console.log "Could not wait for the completion of the index `" + tableName + "." + indexName + "`"
console.log err
process.exit 1
console.log "Index `" + tableName + "." + indexName + "` ready."
if next?
next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment