Skip to content

Does duckdb-async support Async User-defined function ? #32

@unknowntpo

Description

@unknowntpo

Hi, thanks for this amazing package,
when I'm playing around with user-defined function, I came across this issue.
The code snippet below only give me Promise, not the actual string.

async function fetchFromHttp() {
  const db = await Database.create(":memory:");

  db.register_udf('css_selector', 'string', (url) => {
    console.log(`fetching from url: ${url}`);
    const data = fetch(url)
      .then(res => res.text())
      .then(data => {        
        return data;
      });
    return data;
  });

  const rows = await db.all(`select css_selector('https://example.com/') as html`);
  await db.wait();

  console.log(rows);
}

await fetchFromHttp();
$ yarn start
yarn run v1.22.21
$ node src/index.js
fetching from url: https://example.com/
[ { html: '[object Promise]' } ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions