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

Allow quoting identifiers #588

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

yankyhoffman
Copy link

Currently, SqlKata allows consumers to quote identifiers only within ?Raw methods.

Due to that when working with identifiers which need to be quoted (whether being keywords or due to casing) separate logic needs to be implemented when calling a non-Raw vs a Raw method.

This PR allows any identifier to be quoted within the non-Raw methods as well.

@JordanMarr
Copy link

If you wrap your quoted identifiers in your raw expressions with { and } , SqlKata should automatically replace those with the provider specific identifiers.

@yankyhoffman
Copy link
Author

yankyhoffman commented Jul 18, 2022

If you wrap your quoted identifiers in your raw expressions with { and } , SqlKata should automatically replace those with the provider specific identifiers.

The documentation state that square brackets ([]) be used within Raw expressions.

The current PR adds the ability to quote in non-Raw expressions as well.

@JordanMarr
Copy link

Interesting. I am using { and } and it is still replaced (not sure where I read to use curly braces), but I tried with [ and ] and that also works.

@JordanMarr
Copy link

I found where I read that you can use { } or [ ]:
#407 (comment)

By default, SqlKata uses the {} and [] to identify tables and columns identifiers in the raw expressions.

So you should probably handle both in your PR.

@ahmad-moussawi
Copy link
Contributor

It's not clear for me why quoting in non raw methods is needed?

@yankyhoffman
Copy link
Author

yankyhoffman commented Sep 19, 2022

Sorry for my belated response...

Addressing your question Ahmed, indeed it is not needed to quote identifiers in the non-raw methods, but why not support them?

To give some more context and an actual use-case, I wrote a small abstraction over your beautiful library which translates classes and constructs a SqlKata query with Selects/Wheres etc, due to the nature of possible filters (or transformations (UPPER, DATE_PART etc) possible I needed to not only branch and use the raw vs non-raw version of the methods, I also had to branch and conditionally quote identifiers based on whether the end result was passed to a raw vs non-raw method.

This PR aims to simplify and allow consumers of the library to pass pre-quoted identifiers and not worry about getting triple quoted identifiers out as does it simplify the need of the consumer to manually quote non-raw identifiers with the concrete quotation character (i.e. the consumer passes the values to the compiler and doesn't have to worry whether to quote non-raw identifiers with double quotes (") or brackets ([]) or backticks (`).

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

Successfully merging this pull request may close these issues.

None yet

3 participants