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

Expose raw values for parameters, before serialization #140

Closed
stalniy opened this issue Jan 5, 2021 · 2 comments · Fixed by #167
Closed

Expose raw values for parameters, before serialization #140

stalniy opened this issue Jan 5, 2021 · 2 comments · Fixed by #167
Labels
enhancement New feature or request

Comments

@stalniy
Copy link
Contributor

stalniy commented Jan 5, 2021

To illustrate what I mean (silly example that generates error):

sql`
  SELECT CONT(id)::int as amount
  FROM "person"
  WHERE nationality = ${'UK'} and id = ${1}
`

This query fails because of typo and the error has parameters property. When I check this property, I see this:

 [ { type: 0, value: 'UK' }, { type: 0, value: '1' } ]

I understand that this is serialized parameters with their data types in Postges but this is not what I passed to sql function. So, it's not fine to log something like this into log file (or even in stack trace) because it confuses. I also cannot map values to value property because then it looks like I passed string '1' to id but I passed a normal number. This becomes even more confusing when we deal with booleans and the value equals to f or t

debug option behaves the same way, I'd like to have a way to get back parameters I passed to sql function without writing additional logic on my end to unserialize all of those

@stalniy
Copy link
Contributor Author

stalniy commented Jan 5, 2021

@porsager we discussed this in gitter but after that I don't see any commits that address this. That's why decided to create an issue, just to keep this in repo

@porsager
Copy link
Owner

Hi @stalniy

Good thing you created an issue so we don't loose track of it ;) - And sorry for the late reply.

I think it's a good point, and we should get it fixed for v2.

@porsager porsager added the enhancement New feature or request label Mar 23, 2021
stalniy added a commit to stalniy/postgres that referenced this issue Mar 29, 2021
stalniy added a commit to stalniy/postgres that referenced this issue Mar 29, 2021
porsager pushed a commit that referenced this issue Apr 5, 2021
* feat: adds `raw` property to error and debug parameters

Fixes #140

* fix(types): adds `null` as additional type to `Parameter.raw` and `Parameter.value`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants