Remote queries
Automatically create an enum map of your bases saved queries for quick references to calling them via the network.
Outerbase is incredibly powerful as a data insights tool and the ability to save queries we run and reference often makes jobs easier. Even more so we can take those saved remote queries from Outerbase and have our application code execute them remotely as well.
A huge benefit of executing saved queries is two-fold:
Saved queries in Outerbase can have cached responses for increased response times, particularly helpful for queries that are operation intensive or used by many people.
When you want run a SQL query from a platform such as your frontend without having to expose the actual SQL statement to the platform itself. It only needs to know the saved queries unique ID.
Let's take a look at how we can trigger saved queries from our application.
Add script to package
To generate an ENUM map of our queries names & ID values in your project we can add a script to our package.json
file that handles this automatically.
Run the script
With our script in place all we need to do to generate a new Typescript file containing this map locally is by running
Using the generated map in your code base helps ensure that you are referencing saved queries that do in fact exist in the Outerbase account you have linked via the API key. When they no longer exist and you re-run the script above your project should start throwing errors to alert you.
Sample output
After running the script above you should see a new index.ts
file in the path provided in your package.json
file. Now you can reference your saved queries in a type-safe manner.
Requesting a response
With a type-safe enum now in place, we can safely call an SDK function from the OuterbaseConnection
class to runSavedQuery
which takes a parameter of a remote saved query ID.
Last updated