Skip to content

Commit

Permalink
refactor(db): use the new mysql2 option for JSON strings
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Jun 17, 2024
1 parent deb408f commit c79aac6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export const knexInstance = (): Knex<any, any[]> => {
return field.string() === "1" // 1 = true, 0 = false
}

// mysql2 driver will return JSON objects, which is nice, but we have many code paths that expect JSON strings
// so we convert JSON objects to JSON strings here (for now)
if (field.type === "JSON") {
return field.string("utf8")
}
return next()
},

// The mysql2 driver will return JSON objects by default, which is nice, but we have many code paths that
// expect JSON strings, so we instead tell it to return JSON strings.
//@ts-expect-error This is an option in mysql2 v3.10+, but it's not yet reflected in the knex types
jsonStrings: true,
},
})

Expand Down

0 comments on commit c79aac6

Please sign in to comment.