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

non-ascii named placeholders #2300

Open
jlous opened this issue Nov 29, 2023 · 2 comments
Open

non-ascii named placeholders #2300

jlous opened this issue Nov 29, 2023 · 2 comments

Comments

@jlous
Copy link

jlous commented Nov 29, 2023

I wish the requiremets for placeholders names matched the ones for js identifiers.

My project uses the local language in domain model identifiers, including some local non-ascii letters (æøå).
This works fine with with js/ts generally, but does not work with named placeholders.

This means I either have to let requirements from a specific persistence library pollute my core model, maintain an anti-corruption layer with redundant DTOs and mappers just for the spelling, or generate modified param objects on the fly (vulnerable to naming conflicts).
None of them are very tempting.

I would like to be able to do this:

    const person:Person = {
        ...
        født: 1972,
        ...
    }
    query (
        `
            UPDATE person
            SET født=:født,
                ...
            WHERE id = :id
        `,
        person
    )

-but mysql2 fails to bind placeholders with non-ascii characters:
"Error: Bind parameters must not contain undefined. To pass SQL NULL specify JS null"
If I 'normalize' the field name/placeholder to "foedt", everything works fine

@mbaumgartl
Copy link

mysql2 uses mysqljs/named-placeholders for this. The placeholders are identified using a regex.

I think you can close this issue and open new one in linked project.

@sidorares
Copy link
Owner

I probably want to phase out "named placeholder" in favour of external or build in tagged literal based placeholder generation.

PR to support built in api: #1539

External modules:

With 'template literal client' your example would look like

sql`
            UPDATE person
            SET født=${person.født},
                ...
            WHERE id = ${person.id}
`;

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

3 participants