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

Concat params in SQL #323

Closed
abgonzalez93 opened this issue Apr 24, 2024 · 3 comments
Closed

Concat params in SQL #323

abgonzalez93 opened this issue Apr 24, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@abgonzalez93
Copy link

Environment

  • Node version (node -v): 18.20.2
  • npm version (npm -v): 10.5.2
  • Latitude CLI version (latitude --version): 0.8.2
  • Latitude project version (check latitude.json at the root of your project): 0.11.0
  • OS: Ubuntu 22.04.3
  • Database: MySQL

Actual Behaviour

Is there anyway to concat a String with a param variable inside a SQL code?
For example, in my case, Im using a LIKE operator, which uses a % inside a string, ie '%something%'
So my question is, how can you concat a string with a param(variable) or even {interpolate(param(variable))}

This is my code right now (but its not working tho)
imagen

@abgonzalez93 abgonzalez93 added the bug Something isn't working label Apr 24, 2024
@csansoon
Copy link
Contributor

csansoon commented Apr 24, 2024

You can concatenate strings before adding it to the query, like this:

desc_agencia LIKE {'%' + param('agency_filter') + '%'}

or interpolate it if you need it:

desc_agencia LIKE \'{interpolate('%' + param('agency_filter') + '%')}\'

Also, you can use variables for improving the query readability:

{#if param('agency_filter', false)}
  {filter = '%' + param('agency_filter') + '%'}
  AND desc_agencia LIKE \'{interpolate(filter)}\'
{/if}

@abgonzalez93
Copy link
Author

Yeah, that actually helped. Thanks for your time!
It might be interesting if it's put into the website

@csansoon
Copy link
Contributor

You're right! I'm working on improving the SQL logic documentation to make it more clear and easy to understand. Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants