RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
773 stars 69 forks source link

Kysely .any fails with expr must be an array when the column is Generated #184

Open Exellin opened 1 month ago

Exellin commented 1 month ago

I have a table areas with a column days_of_week_active (for example ['Mon', 'Tue']).

In my schema the column is days_of_week_active: Generated<string[]>;, and it is generated because it has the default of all the days of the week:

.addColumn('days_of_week_active', sql`varchar(3)[]`, col => col.defaultTo(sql.raw(`ARRAY[${days_of_week.map(day => `'${day}'`).join(', ')}]`)).notNull())

The following example doesn't compile

  const monAreas = db.selectFrom('areas')
    .selectAll('areas')
    .where((eb) => eb(
      eb.val('Mon'), '=', eb.fn.any('areas.days_of_week_active')
    )).execute();

I get the following typescript error:

Argument of type 'KyselyTypeError<"any(expr) call failed: expr must be an array">' is not assignable to parameter of type 'OperandValueExpressionOrList<DB, "areas", ExpressionWrapper<DB, "areas", string>>'.

If I temporarily remove Generated from the schema and set it to string[], then it works fine.

Upvote & Fund

Fund with Polar