kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.85k stars 276 forks source link

Nested array doesn't work on MySQL 5.7.44 #1212

Closed tobe-continued closed 2 weeks ago

tobe-continued commented 2 weeks ago

Hello, i'm working on MySQL 5.7 in my office, and when i want use nested array, it doesn't work.

This :

import { jsonArrayFrom } from 'kysely/helpers/postgres'

const result = await db
  .selectFrom('person')
  .select((eb) => [
    'id',
    jsonArrayFrom(
      eb.selectFrom('pet')
        .select(['pet.id as pet_id', 'pet.name'])
        .whereRef('pet.owner_id', '=', 'person.id')
        .orderBy('pet.name')
    ).as('pets')
  ])
  .execute()

return :

sqlMessage: "Unknown column 'person.id' in 'where clause'",

Anyone has solution for this ?

See you later !

koskimas commented 2 weeks ago

You're importing the jsonArrayFrom helper from Postgres.