Javascript Objective.js中的异步$formatDatabaseJson
我需要等待$formatDatabaseJson中的函数。我正在检查文档(),似乎不可能。有没有办法手动完成Javascript Objective.js中的异步$formatDatabaseJson,javascript,model,async-await,objection.js,Javascript,Model,Async Await,Objection.js,我需要等待$formatDatabaseJson中的函数。我正在检查文档(),似乎不可能。有没有办法手动完成 class Person extends Model { async $formatDatabaseJson(json) { // Call the super class's implementation. json = await super.$formatDatabaseJson(json) // await function here retu
class Person extends Model {
async $formatDatabaseJson(json) {
// Call the super class's implementation.
json = await super.$formatDatabaseJson(json)
// await function here
return json
}
}
$formatDatabaseJson
是同步的,不能用于调用异步代码$beforeInsert
、$beforeUpdate
和$afterGet
钩子是异步的,可以根据您的用例使用。不是解决方案,但最后我使用了$beforeInsert,因为它支持异步执行