Variables are placeholders that can be assigned and reassigned values throughout the SQL code.To assign a value to a variable, use the equal sign = followed by the value.
Copy
{name = 'foo'}{age = 30}{sum = 2 + 4}
For example, take a look at the following Latitude Query, and what will actually be compiled and executed in the database:
Copy
/* Defining the variable and SQL code */{sum = 2 + 4} SELECT *FROM tableWHERE id = {sum}
Variables can be modified using operations such as addition.
Copy
{counter = 10} /* Define the variable */SELECT *FROM tableWHERE id != nullAND ( {#each [1, 2, 3] as products, index} /* Print the value of the variable */ id = {counter} /* Add an 'OR' at the end to every element except the last one */ {#if index + 1 < products.length} OR {/if} /* Increment the value of the variable */ {counter = counter + 10} {/each})
Constants are similar to variables but, once defined, their value cannot be changed. Also the main syntax difference is constants are defined using the @const keyword.
Copy
{@const name = 'value'}
Your Query
Copy
{@const birthday = '2000/02/28'} /* Defined a constant */SELECT *FROM table{#if birthday = '2000/02/28'} {birthday = '2024/12/31'} /* Reassigning the constant */{/if}