javascript - Objection.js 中的异步 $formatDatabaseJson
问题描述
我需要在我的 $formatDatabaseJson 中等待一个函数。我正在检查文档(https://vincit.github.io/objection.js/#_s_formatdatabasejson),似乎不可能。有什么办法可以手动完成吗?
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
钩子是异步的,可以根据您的用例使用。
推荐阅读
- azure - What are the sources supported in Azure Data Share?
- java - Weblogic 12.2.1.3 错误:无法找到或加载主类 com.oracle.cie.wizard.WizardController
- xml - TSQL:如何从 T1.Field_A 中的 XML 信息和 T2.Field_A 中的 nvarchar 的两个表中获取 UNION 结果
- selenium - 如何使用 selenium webdriver (Mac) 上传图像
- c# - 如何在 Xamarin.Forms 上使用 POST 方法将数据发送到 Google 电子表格?
- php - 如果从 laravel 5.5 升级到 5.8 护照不会在 oauth/token url 上生成令牌
- javascript - Fullcalendar 仅删除特定资源组或资源 ID
- android - 谷歌文档查看器不能在本地主机上工作吗?
- spring-boot - 自定义对象映射器在springboot中不生效
- javascript - ReactJS:已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查