Connect to Supabase
Connect to a Supabase database with the supabase-js library.
Import the createClient function from jsr supabase-js package
import { createClient } from "jsr:@supabase/supabase-js@2";
Create a single supabase client for interacting with your database
const supabase = createClient(
Deno.env.get("SUPABASE_URL")!,
Deno.env.get("SUPABASE_KEY")!,
);
Insert data into the countries table
let resource = await supabase
.from("countries")
.insert({ code: "JP", name: "Japan" })
.select();
if (resource.error) {
console.error(resource.error);
}
console.log(resource.data); // [ { code: "JP", name: "Japan" } ]
Get data from the countries table
resource = await supabase
.from("countries")
.select();
if (resource.error) {
console.error(resource.error);
}
console.log(resource.data); // [ { code: "JP", name: "Japan" }, ... ]
Run this example locally using the Deno CLI:
deno run --allow-net --allow-env https://docs.deno.com/examples/scripts/supabase.ts