Getting sqlViews with useDataQuery


Interested to hear peoples thoughts on how to implement a query for the sqlViews endpoint.

The url format is this:

So if I do not know the uid in advance how am I to define the query? I am only allowed to use variables at the params and id level, not the resource level.

For now I am just defining a wrapper function that creates a query with the correct resource, which is ok because I only need to generate a few queries and only use the once. But if this needed to be done for a lot of different UIDs and have them be run regularly I’m not sure if the above is still a good solution.

Any thoughts and solutions welcome!

Thanks for your time,

Hi @plinnegan,

Thank you for the interesting question! I’m trying to understand your post more. The title says useDataQuery so what I can conclude is that you have specific sqlViews that you want to get but you want to be able to get them without using the UID? If so then what is distinct about these sqlViews which maybe can be used in the filter?

Is this what you mean when using useDataQuery? You can then change the value of the filter based on what you want to request and you won’t need to use the id if you know what to filter

Hope this is what you are actually looking for.


Hi Gassim! :wave:

Unfortunately this is not quite what I need, in the above example you are fetching the metadata for the SQL view, what I am trying to do is get the data from running the SQL view which required the type of endpoint I posted above:


Anything I put in the params key will appear after the data.json part of the url, so I have no way to modify the part before this except by changing the resource value (which cannot be dynamic)

1 Like

Interesting, thanks! I never tried this before so I don’t know but I’m curious to know how you’d use this by itself without modification in the part const query = {}

Would it be possible to have it as variable = "api/sqlViews/" + id_variable + "data.json?" ? :smile:

Yes so that’s what I’m doing currently, I have a wrapper function which takes the view uid and returns a query object with the uid in the resource key. However this creates a new query for every sqlView I want to get data for, so I cannot dynamically pass the view uid into the query as a variable. This means they would all need their own individual useDataQuery hooks!!!

1 Like

Hey @plinnegan, perhaps you could try something like this:

  sqlView: {
     resource: "sqlView",
    id: ({ id }) => `${id}/data.json`,