Fill Query Builder "enum" values from variables data

Hello,

I'm trying to fill the "enum" values in the query builder as below:

But with variable data from a ressource (Snowflake query for example)

So I would need something the result of the query below being in the enum:

SELECT DISTINCT
	{{query_builder.fields[0].name}}
FROM MY_TABLE

Which would prefill the values to generate a new query & avoid misspelling etc

So:

  • The result of the above query would fill the enum & enumNames of the query builder
  • It would not be for [0] only but for all the fields of the query_builder

I tried multiple things but not working.

Would you be able to help?

Thanks in advance,

Alex

Hey @AlexSul!

Happy to help here! If you are looking to dynamically populate the enum values here based on the values returned from a query for all results of your database, you could use the following code in the query builder that would build an object for each column returned and populate the dropdown dynamically based on the unique values returned:\

{{Object.keys(query1.data).map(colName => Object.assign({"name": colName, "label": colName, "enum": _.uniq(query1.data[colName]), "enumNames": _.uniq(query1.data[colName]) })) }}

This uses the lodash library to filter the array of row values for each column for unique values. Do you think this could work for your use case here?

1 Like

Hello @Chris-Thompson!

That's perfect! Did slights changes to make the label prettier than the SQL name and was exactly what I was looking for!

Thanks a lot :slight_smile: