Skip to main content

Connect to Supabase

Connect to a Supabase database with the supabase-js library.

Edit on Github
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

Did you find what you needed?

Privacy policy