Created
January 17, 2015 06:49
-
-
Save mirhec/23fa4f06b67160fcb210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
## 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