Skip to content
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

Support for more than one Model #1

Open
BCkmason opened this issue Mar 10, 2014 · 8 comments
Open

Support for more than one Model #1

BCkmason opened this issue Mar 10, 2014 · 8 comments

Comments

@BCkmason
Copy link

I've created two separate Model objects mapped to two different Dynamo tables.

When I'm done, both Models wind-up referencing the same Schema instance.

I think this is related to how prototypes are being used in model.js, but I'm not sure.

Is there something special I have to do to use more than one table with dynamodb-model?

@BCkmason
Copy link
Author

For example

  1. create any two Model objects mapped to two different DynamoDB tables as described in the README.md.

  2. Add the following two methods to DynamoModel in model.js (using the same technique as the existing getItem/putItem/etc. methods).

DynamoModel.prototype.showTableName = function () {
  console.log(tableName);
}

DynamoModel.prototype.showSchema = function () {
  console.log(schema);
}
  1. Then run this in a test file
var model1 = require('./models/model1');

console.log(Model1.showSchema());

var Model2 = require('./models/model2');

console.log(Model1.showTableName());
console.log(Model1.showSchema());
console.log(Model2.showTableName());
console.log(Model2.showSchema());

Notice that both Model1 and Model2 wind-up sharing the same table name and schema.

@extrabacon
Copy link
Owner

You are right and this has been heavily refactored in the next version, which has not been pushed to Github yet.

@BCkmason
Copy link
Author

Cool. Looking forward to the new version. Do you know about when that will drop? I'm trying to decide whether to make local modifications until then.

@extrabacon
Copy link
Owner

I am unsure. This project was initially started to ease the transition from MongoDB to DynamoDB, which has been postponed. The next version has huge changes that were never pushed. Maybe I could push them on an alternate branch so you can try them out.

@BCkmason
Copy link
Author

Works for me. That'd be awesome.

@extrabacon
Copy link
Owner

The branch is called vnext. Models now return instances of DynamoQuery. The tests are incomplete.

@BCkmason
Copy link
Author

Thanks!

@tony-gutierrez
Copy link

Integrating some more powerful schema validation with something like this https://www.npmjs.com/package/jsonschema could have been awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants