clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dynamic create table how to get model

dduo518 opened this issue · comments

commented

hi!
I use api dynamic create table;

function _define(params) {
    params.schema = _defineSchema(params.schema);
    dynogels.define(params.name, {
        hashKey: params.hashkey,
        timestamps: true,
        createdAt: true,
        updatedAt: 'updateTimestamp',
        schema: params.schema
    });
    return new Promise((resolve, reject) => {
        dynogels.createTables(function(err) {
            if (err) {
                reject(err);
            } else {
                resolve({ success: true });
            }
        })
    })
}

one api want to query the table ,then how to get the model;
or change expression:
can I not defined the model and save or query the table
thanks

dynogels.define() returns the table model. Perhaps you could return this from your promise?

let model = dynogels.define(...);

// In callback:
resolve({ success: true, model });

You can also access any model by its name as an attribute of dynogels.models. For example, in your code you could fetch the model as dynogels.models[params.name] after the call to dynogels.define().