Skip to content

Instantly share code, notes, and snippets.

@mirhec
Created January 17, 2015 06:49
Show Gist options
  • Save mirhec/23fa4f06b67160fcb210 to your computer and use it in GitHub Desktop.
Save mirhec/23fa4f06b67160fcb210 to your computer and use it in GitHub Desktop.
###
## This creates the given table. The table param
## is either a string with the table name or an
## object with at least one parameter 'name' and
## optional the indices to create as string array.
## If there occurs an error it will be printed out.
## If it succeeds, the callback next will be called.
###
createTable: (table, next) ->
if typeof(table) is 'string'
table = name: table, indices: []
r.tableCreate(table.name).run @conn, (err, result) =>
if (err) and (not err.message.match(/Table `.*` already exists/))
console.log "Could not create the table `" + table.name + "`"
console.log err
process.exit 1
console.log "Table `" + table.name + "` created."
# create indices
if table.indices?
for idx in table.indices
@createIndex table.name, idx
if next?
next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment