One way I know I can do it is by listing throughdbList()
and tableList()
and then looking for what I want in the results.
Is there an easier wa
For the table existing checking I have found the following solution:
r.tableList().run(connection); //['people']
this will give you back an array of the tables which are defined on the default DB for example: ['people']. (if you want to set it do this: connection.use('test');)
then we can check if the array is containing our table name to create.
_.some(tableNames, tableName)
put it all together:
if (!_.isNil(tableName) && _.isString(tableName) && !_.isNil(connection)) {
r.tableList().run(connection).then(function(tableNames) {
if (_.includes(tableNames, tableName)) {
return r.tableCreate(tableName).run(connection);
} else {
return;
}
});
}