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

Should this package try to parse like PostgreSQL, or just what PostgreSQL produces? #101

Open
charmander opened this issue Sep 10, 2019 · 2 comments

Comments

@charmander
Copy link
Contributor

Take the boolean parser, for example:

function parseBool (value) {
if (value === null) return value
return value === 'TRUE' ||
value === 't' ||
value === 'true' ||
value === 'y' ||
value === 'yes' ||
value === 'on' ||
value === '1'
}

It checks for 'TRUE', 't', 'true', 'y', 'yes', 'on', and '1', and assumes anything else is false. This seems like overkill for interpreting fields from the server to me, since PostgreSQL only sends 't' and 'f' as text representations… but it’s not the right way to parse booleans in general the way PostgreSQL would either, since the latter

  • is case-insensitive ('True' is valid)
  • ignores surrounding whitespace (E' yes\t\n\f\r' is valid)
  • allows prefixes of words ('of', 'tru', 'fals' are valid)

In other words, there are strings PostgreSQL will parse as true that parseBool will parse as false with no warning.

So is 't'true, 'f'false, otherwise → throw a good direction? I’ll take a look at how it affects the performance of pg at some point.

@bendrucker
Copy link
Collaborator

That seems good to me!

@sehrope

This comment has been minimized.

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