0

I need to await a function in my $formatDatabaseJson. Im checking the docs (https://vincit.github.io/objection.js/#_s_formatdatabasejson) and seems not possible. Is there any way to do it manually?

class Person extends Model {
  async $formatDatabaseJson(json) {
    // Call the super class's implementation.
    json = await super.$formatDatabaseJson(json)
    // await function here
    return json
  }
}
Rashomon
  • 5,962
  • 4
  • 29
  • 67

1 Answers1

1

$formatDatabaseJson is synchronous and cannot be used to call async code. $beforeInsert, $beforeUpdate and $afterGet hooks are async and could be used depending on your use case.

Sami Koskimäki
  • 250
  • 2
  • 7