2017-02-01 57 views
-1

我想獲得knex將數組映射到其組成字符串並使用承諾順序插入它們。Knex承諾產生類型錯誤

.map(messages, function (message) { 
    return knex.insert({contents: message}).into('newsFeed'); 
}) 

返回

TypeError: expecting a function but got [object Array]

+1

它應該是'messages.map(函數(消息){})' –

回答

0

嘗試這種情況:

let arrayOfMessageRowsToInsert = messages.map(message => ({ contents: message })); 

knex('newsFeed').insert(arrayOfMessageRowsToInsert).then(result => { 
    console.log("Handle result if you wish, result); 
});