-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does duckdb-async support Async User-defined function ? #32
Comments
@unknowntpo your defined function is returning a promise instance instead of returning the promise resolved value. Try marking your defined function as Just another 10 cents: you don't need the last It should look like this: async function fetchFromHttp() {
const db = await Database.create(":memory:");
db.register_udf('css_selector', 'string', async (url) => {
console.log(`fetching from url: ${url}`);
const data = fetch(url)
.then(res => res.text());
return await data;
});
const rows = await db.all(`select css_selector('https://example.com/') as html`);
await db.wait();
console.log(rows);
}
await fetchFromHttp(); |
This is correct, thank you ! But actually this code does not show me the actual html content, it just show me [object Promise], I try to use
This is the code snippet. |
@unknowntpo I was checking DuckDB Node.js API and apparently it doesn't expect your udf callback to return a promise 😕 Which could explain why it doesn't resolve. See this code: https://github.com/duckdb/duckdb-node/blob/main/lib/duckdb.js#L336 It doesn't await on your supplied callback function. I guess in this case you should open an Issue there for discussion. Maybe there's a good reason why they don't do that. |
@vinimdocarmo Sorry for my late reply and thanks for your answer! That makes sense, and I'll open an new issue at duckdb-node. |
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.
The text was updated successfully, but these errors were encountered: