Is it possible to use Supabase with Google Apps Script (GAS)?
I'm new to Supabase and I've never tried to import external library to GAS before. I'm planning to use Supabase as a database for my project in GAS. The project is built to run a bot in a chatting platform rather than a user interface. Based on the documentation from Supabase, it looks like it works by executing function from the Supabase library.
I have tried to use the Supabase library by copy-pasting the whole library from here or using eval()
, but all of them return the error: ReferenceError: self is not defined
.
Here is the function I run that uses eval()
:
function myFunction(){
var x = eval(UrlFetchApp.fetch("https://unpkg.com/@supabase/supabase-js").getContentText())
var supabase = createClient(supabaseUrl,supabaseKey)
}
createClient()
is supposed to be a function from the Supabase library.
One possible route that I can think of to make this work is to use Postgrest, which is the underlining API server that Supabase users.
Since every Supabase instance can be accessed using rest API provided by Postgrest, you should be able to perform insert, update, delete and read operations to your Supabase database from your GAS project.
You can probably run something like this to access Supabase.
$anonKey = "YOUR_SUPABASE_ANON_KEY_HERE"
$url = "YOUR_SUPABASE_URL_HERE"
$var options = {
"async": true,
"crossDomain": true,
"method" : "GET",
"headers" : {
"Authorization" : "Bearer " + $anonKey,
"apikey": $anonKey
}
};
var response = UrlFetchApp.fetch($url + "YOUR_QUERY_PARAMETER_FOR_POSTGREST", options);