dynogels icon indicating copy to clipboard operation
dynogels copied to clipboard

Feature: Create a Dynogels Factory with Independent Configurations

Open naerbnic opened this issue 6 years ago • 3 comments

Currently when you're configuring dynogels, you call a module-global method to initialize the configuration state:

const dynogels = require('dynogels');
dynogels.AWS.config.update(myConfig);

While convenient, this makes it difficult to run independent configurations, such as may be necessary with either multiple regions or with tests that point to local implementations.

I propose we add a factory method that constructs independent dynogels modules, as many other modules do. With a bike-sheddable interface:

const dynogels = require('dynogels').createWithConfig(myConfig1);

const users = dynogels.define('Users', ...)

This module is independent of others created with createWithConfig(), and global changes to configuration do not affect it.

The dynogels module itself would not change it's API for purposes of compatibility, so the first code block above would still operate as expected.

naerbnic avatar Nov 13 '17 18:11 naerbnic

That sounds like a reasonable use case. Can it be solved with the feature to add an external dynamodb instance?

From the README.md:

You can also pass in a custom instance of the aws-sdk DynamoDB client

var dynamodb = new AWS.DynamoDB();
Account.config({dynamodb: dynamodb});

// or globally use custom DynamoDB instance
// all defined models will now use this driver
dynogels.dynamoDriver(dynamodb);

jkav77 avatar Nov 26 '17 03:11 jkav77

This is a useful and interesting feature. Bluebird has a similar thing that we use to augment the promise prototype with our own methods, without polluting Bluebird for any other modules that use it. As much as possible, I think Node modules should provide factories to produce new and independent module instances.

I will try to work on this over the next month or so.

cdhowie avatar Dec 15 '17 18:12 cdhowie

FWIW, that would be definitely a nice way to hook in a dynamodb-local instance for testing purposes.

pdeschen avatar Jan 18 '18 13:01 pdeschen