Using a variable for a column in QB where clause

Hi

Is it possible to use in the QueryBuilder where clause variables? Something like:

var tableColumn = getColumn();
var value = getValue();

var query = datasources.db.<db>.<table>.createSelect();
...
...
query.where
	.add(tableColumn.eq(value));

Regards,

Hi,

sorry, i am not sure i understand correctly your question; is not clear to me if you want to build a query dinamically for any x column, or if you are trying to Get the values set on an existing Query/QueryBuilder.

If you are simply looking for a way to construct dinamically your query, using any column X, well yes that’s possible; see my sample below.

// columnName can be any column of dataSource customers.
var columnName = "city";
var query = datasources.db.example_data.customers.createSelect();
var qbColumn = query.getColumn(columnName);
query.result.add(qbColumn);
query.where.add(qbColumn.like(value));
query.sort.add(qbColumn.asc);
var dataset = databaseManager.getDataSetByQuery(query,-1);

Instead if you are looking for something else, can you tell us more on what kind of API are you looking for and most importantly what are you trying to achieve exactly ? Perhaps there is a different pattern to get to your desired result.

Regards,
Paolo

Hi Paolo

You perfectly answered my question! I am just having two different columns depending on a selected tab and wanted to have the query a bit dynamic.

The missing piece of code for me was the following line:

var qbColumn = query.getColumn(columnName);

Now the QB Select works as expected.

Many thanks and regards,