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

Evaluate adding a way to re-use value bindings #517

Open
gajus opened this issue Oct 7, 2023 · 2 comments
Open

Evaluate adding a way to re-use value bindings #517

gajus opened this issue Oct 7, 2023 · 2 comments

Comments

@gajus
Copy link
Owner

gajus commented Oct 7, 2023

Consider this scenario:

sql.fragment`SELECT ${'a'}, ${'a'}, ${'a'}`

The resulting object is:

SELECT $1, $2, $3

with values ['a', 'a', 'a']

I wish we had a way to re-use the same value binding, e.g.

const value = sql.value('a');

sql.fragment`SELECT ${value}, ${value}, ${value}`

With the outcome of:

SELECT $1, $1, $1

and values ['a']

@gajus gajus changed the title Evaluate re-using the same values Evaluate adding a way to re-use value bindings Oct 7, 2023
@wozprzemek
Copy link

Hi, could I work on this one?

@wozprzemek
Copy link

What if we consider, e.g. nested sql.fragments, like in the simplified example:

const value = sql.value('a');
const nestedFragment = sql.fragment`SELECT ${value}`

sql.fragment`
  SELECT ${value}, ${value}, ${value},
  ${nestedFragment}
`

I understand that an example like this would also re-use the same value binding and produce the values ['a']?:

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

No branches or pull requests

2 participants