Custom queries in toolkit


#1

Hello, i saw that we can use some custom queries in Chartfactor studio, but i have an embedded application usin react and Postgres SQL as a provider, so my question is, can we do de something similar in my application?, i dont want to create a view for that in the database, so i think creating a custom query like in ChartFactor Studio solves the problem, it is posible?


#2

Yes, and actually is very easy to do, you just need to include that custom query in your provider metadata, like this:

const providers = [
      {
        name: "My provider",
        url: "http://localhost:5432",
        provider: "redshift",
        metadata: {
            "myCustomQuery": { 
                query: `select * from public.my_table limit 100`
            }
        }
      }
    ];

And then use it in your visualizations like this:

let provider = cf.provider("My provider");
let source = provider.source("myCustomQuery");
let metric0 = cf.Metric("my_metric", "sum");
let group1 = cf.Attribute("my_group")
          .limit(10)
          .sort("desc", cf.Metric("my_metric", "sum"));
let myData = source.groupby(group1).metrics(metric0);
let myChart = myData
          .graph("Bars")
          .execute()

#3

Thanks, that’s amazing, it really helps me and saves my time, i tried and it works for me, just one more question, it can be done also with bigquery and other providers, right?


#4

Of course, but just SQL peoviders and just in case here you have the documentation for that: CUSTOM QUERIES


#5

I see, all is in the documentation :sweat_smile:, i’ll review that first the next time, thank you so much.