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

[Idea] Calculating variable value based on Ruby code before performing SQL query #216

Closed
monfresh opened this Issue Oct 18, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@monfresh
Copy link

monfresh commented Oct 18, 2018

Hello. Thanks for this wonderful gem! One of the ways we're looking into using it is to make it easier to look up users (without having to SSH into our production server and fire up a Rails console). We look up users by their email address when they email our support team. The problem is that emails are encrypted in the DB, so we have a custom look up method User.find_with_email which generates a fingerprint of the email and then looks up the fingerprint in the DB.

It would be great to be able to use a variable-based query like SELECT * FROM users WHERE email = {email}, so that Blazer users could type in the email address, but behind the scenes, the query would first generate the fingerprint, and then perform SELECT * FROM users WHERE email_fingerprint = {email_fingerprint}

Another option could be to allow creating queries based on Ruby code instead of SQL, so you would have one query to generate the fingerprint, then you could enter the fingerprint in the variable-based query that runs SELECT * FROM users WHERE email_fingerprint = {email_fingerprint}.

Any other ways this can be achieved?

@ankane

This comment has been minimized.

Copy link
Owner

ankane commented Jan 4, 2019

Hey @monfresh, thanks for the suggestion 👍 I've been thinking about this myself. I think a simple way would be to allow a user-defined transformation based on the variable name.

Blazer.transform_variable = lambda do |name, value|
  value = User.compute_fingerprint(value) if name == "email_fingerprint"
  value
end

I've added this on the transform_variable branch. Let me know what you think.

@monfresh

This comment has been minimized.

Copy link
Author

monfresh commented Feb 9, 2019

Thanks! I haven't had the chance to take a look yet. I switched jobs a couple months ago and I'm not currently using Blazer.

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