Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vikiival opened this issue Oct 31, 2023 · 1 comment
Open

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

vikiival opened this issue Oct 31, 2023 · 1 comment

Comments

@vikiival
Copy link

.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 ?

@aidenwallis
Copy link
Owner

Interesting.. is this something you feel comfortable cutting a PR for? Else I can take a look next week (am travelling for the rest of the week)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants