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

There is a critical issue in your code. #1

Closed
awesome1128 opened this issue Feb 5, 2022 · 5 comments
Closed

There is a critical issue in your code. #1

awesome1128 opened this issue Feb 5, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@awesome1128
Copy link

How are you?
Nice to meet you.
I found a critical issue in your code. You mentioned only >, !=, =, <, and so on in Query builder.
But for example, if I want to find data that contains a specific string from A column, then how can I build a Query?
Please let me know.
Thanks.

@eugenezadorin
Copy link
Owner

Hi. Could you please provide me some more details about your specific case?

Do you mean search by substring? Or this is about filtering rows by cell without knowing exact value of this cell?

Currently query builder has no methods to make such query in handy way, but you always can use raw formula.

If we talking about searching by substring, it can look something like that:

// find records where My Column value starts with foo
$query->whereRaw("REGEX_MATCH({My Column}, '^foo')");

You can also use values from other cells in your formula:

// find records where My Column contains value from Other Column
$query->whereRaw("REGEX_MATCH({My Column},('' & {Other Column} & ''))");

@awesome1128
Copy link
Author

awesome1128 commented Feb 7, 2022 via email

@eugenezadorin
Copy link
Owner

Sure, raw formula will work for you. Assume you look for users with name containing substring "Ivan". There are few options:

$query->whereRaw("REGEX_MATCH({Username}, 'Ivan')"); // case-sensitive, any place in cell

$query->whereRaw("REGEX_MATCH({Username}, '^Ivan')"); // case-sensitive, cell value must start with Ivan

$query->whereRaw("REGEX_MATCH({Username}, '(?i)Ivan')"); // case-insensitive, any place in cell

You can read more about regexp syntax here.

I think I could provide some convenient query builder methods for this later. Something like that:

$query->whereLike("Username", "Ivan");
$query->where("Username", "like", "Ivan%");
$query->whereMatch("Username", "(?i)ivan");

@eugenezadorin eugenezadorin added the enhancement New feature or request label Feb 7, 2022
@awesome1128
Copy link
Author

awesome1128 commented Feb 7, 2022 via email

@eugenezadorin
Copy link
Owner

Implemented in v0.3.0

Few examples:

// look for emails, matching @gmail.com in case-insensitive way
$query->where('email', 'match', '(?i)^(.+)@gmail.com$');

// look for names, which starts with Ivan (case-sensitive!)
$query->where('name', 'like', 'Ivan%');

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

No branches or pull requests

2 participants