Skip to content

Rest operator on bind will fail to execute on bigger tables #23

@vikiival

Description

@vikiival

.bind(...compiledQuery.parameters)

Context

For a few hours I am trying to debug a non trivial problem

D1_ERROR: too many SQL variables

I found that generation of kysely-d1 is using the rest operator .bind(...data) therefore from
array of objects i get one single array which is flat.
From this point D1 will fail because I have suddenly 100+ params

To reproduce

create a big table

export interface items {
  a: string;
  b: string;
  c: string;
  d: string;
  created_at: Generated<string | null>;
  e: string;
  f: Generated<number | null>;
  id: string;
  g: string | null;
  h: string;
  i: string | null;
  j: string;
  k: string;
  l: string;
  m: string;
  n: string;
}

try to do a insert with 10 items
Which produces sql like this

insert into "items" ("a", "b", "c", "d", "e", "f", "id", "g", "h", "i", "j", "k", "l", "m", "n") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

and params will be

Array(135) [ ]

To fix

Most possible adapt https://developers.cloudflare.com/d1/platform/client-api/#batch-statements ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions