dynamic create table how to get model
dduo518 opened this issue · 1 comments
dduo518 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
cdhowie commented
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()
.