Skip to content

Edge functions/Deno not supporting scheme 'postgres' #66

Open
@zzulanas

Description

@zzulanas

Bug report

  • [ ✅ ] I confirm this is a bug with Supabase, not with my own application.
  • [ ✅ ] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I'm unable to use the supabase-js client to access my database in an edge function using Deno.

To Reproduce

To reproduce, create a new Edge function, this is the function I was using below:

import { Configuration, OpenAIApi } from "openai";
import { createClient } from "@supabase/supabase-js";

const supabaseUrl = Deno.env.get("SUPABASE_DB_URL");
const supabaseKey = Deno.env.get("SUPABASE_ANON_KEY");
export const supabaseClient = createClient(supabaseUrl, supabaseKey);


const configuration = new Configuration({ apiKey:  Deno.env.get("OPEN_AI_KEY" });
const openAi = new OpenAIApi(configuration);

const documents = [
  "Zach loves long walks on the beach",
  "Zach loves ice cream, especially vanilla ice cream",
  "In Zach's free time he likes to rock climb, the highest grade he can do is around a V5, he's still learning!",
];

// Assuming each document is a string
for (const document of documents) {
  // OpenAI recommends replacing newlines with spaces for best results
  const input = document.replace(/\n/g, " ");

  const embeddingResponse = await openAi.createEmbedding({
    model: "text-embedding-ada-002",
    input,
  });

  const [{ embedding }] = embeddingResponse.data.data;

  // In production we should handle possible errors
  await supabaseClient.from("documents").insert({
    content: document,
    embedding,
  });
}

You can use this function or some other function that just inserts data into any table, but I'm not able to add any data through the edge functions.

Try deploying this as a Supabase edge function and invoking it. When I invoke it I get this error:

{
  message: "TypeError: scheme 'postgres' not supported",
  details: "TypeError: scheme 'postgres' not supported\n" +
    "    at opFetch (ext:deno_fetch/26_fetch.js:73:14)\n" +
    "    at "... 504 more characters,
  hint: "",
  code: ""
} error

Expected behavior

I expected the edge function to insert the data correctly, but no data was inserted into the DB, and the function errored out on the first document. I'm not sure if I'm doing this correctly, but this was following a guide to create embeddings in a normal Typescript file, I wanted to extend that to making an Edge function to do that. If that isn't possible then I was unaware and I can work with it some other way.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: MacOS
  • Browser (if applies) N/A
  • Version of supabase-js: 2.25.0
  • Version of Deno: 1.34.3

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions