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

namedPlaceholders and array #248

Open
sbscan opened this issue Jun 23, 2023 · 1 comment
Open

namedPlaceholders and array #248

sbscan opened this issue Jun 23, 2023 · 1 comment

Comments

@sbscan
Copy link

sbscan commented Jun 23, 2023

When using namedPlaceholders if we use array parameters it sterilize array without quotes.
My parameter is an array like role => ["Admin","Accounting"]
When I use it as a namedPlaceholder in an insert statement the resulting SQL is: 'role': Admin,Teklif
Which should be: 'role': 'Admin,Teklif'
So ends with an SQL error.
Quick fix is using toString and convert array to string.

@rusher
Copy link
Collaborator

rusher commented Jun 23, 2023

That's the expected behavior : array permits sending multiple values.
Example :

    await conn.query('CREATE TABLE namedPlaceholders1(t varchar(128))');
    await conn.query("INSERT INTO `namedPlaceholders1` value ('a'), ('b'), ('c')");
    const res = await conn.query('select * from `namedPlaceholders1` where t IN (:possible)', { possible: ['a', 'c'] });`
   // res = [{ t: 'a' }, { t: 'c' }]

if your behavior is explicitly to have a string list, then, yes toString is the way to go.

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