-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dynasty.table()
requires the table to exist
#46
Comments
Interesting idea! I'll dig into the code and see if I can do that in a way that wouldn't break things, I suspect I can make this happen. In the meantime though, you can do it yourself in user space with something like the following: exports.my_table = dynasty.list()
.then(function(resp) {
if (resp.TableNames.indexOf('my_table') === -1) {
return dynasty
.create('my_table', {key_schema: {hash: ['id', 'string']}})
.return(dynasty.table('my_table'));
} else {
return dynasty.table('my_table');
}
}); note, I didn't test this code, so I'd suggest doing so! That should accomplish what you want -- returning a promise that either resolves to the table or to the table post-creation. I'll leave this issue open until I can assess whether |
Ah, thanks. It's easier than I thought! Noticed there's a typo in my original code (which I just fixed). |
Tried it out and it's not ideal because you end up with a promise, not a So when requiring this file as var db = require('db');
db.my_table
.then(function(table) {
// do operations on table here
}); Ideally I just want to be able do this: dynasty.create('my_table', {key_schema: {hash: ['id', 'string']}})
.find('some_id'); Though this will probably require making |
@chetbox Anytime I have a module where the exported value is a "future" value, I always export a callable function - in your case, something like |
The following example fails due to a race condition where the table has not yet been created.
Doing any operation on
my_table
fails with the errorUnhandled rejection ResourceNotFoundException: Cannot do operations on a non-existent table
even after the table has been successfully created.Is it possible to allow
dynasty.table()
to be lazy (i.e. the table does not need to exist when the object is created) or make it a promise somehow?What I'm trying to achieve is:
my_table
if necessarydynasty.table('my_table')
The text was updated successfully, but these errors were encountered: