How to access JSON nested value within a `select()`

Having this schema:

type Breakdown = {
  land: number;
  construction: number;
  other: number;
};

export const table = mysqlTable("table", {
  id: varchar("id", { length: 32 }).primaryKey(),
  ...
  debt: json("debt")
    .$type<Breakdown>()
    .default({ land: 0, construction: 0, other: 0 })
    .notNull(),


I would like to access debt values to compute the total in the select():

return db.select({
  ...getTableColumns(table),
  debt_total: table.debt.land + table.debt.construction + table.land.other,
})...


It does not seem possible as the moment or did I miss something?
Was this page helpful?