Issue connect Worker and Planetscale
Hi,
I got this issue:
workerd/jsg/util.c++:275: error: e = kj/async-io-win32.c++:813: failed: getaddrinfo(): #11001 No such host is known.; params.host = undefined; params.service =
stack: 0 0 0 0 0 0 0 0 7ff67cbe5c04 0 0 7ff67cbe64a0 7ff67c5a2c6c; sentryErrorContext = jsgInternalError
my code:
import { Hono } from 'hono';
import { connect } from '@planetscale/database';
const app = new Hono();
let conn;
app.use(async (ctx, next) => {
if (!conn) {
const config = {
host: ctx.env.DATABASE_HOST,
username: ctx.env.DATABASE_USERNAME,
password: ctx.env.DATABASE_PASSWORD,
fetch: (url, init) => {
delete (init)["cache"];
return fetch(url, init);
}
}
console.log(config);
conn = connect(config); } await next(); }); async function fetchData(query: string) { const data = await conn.execute(query); return data.rows; } app.get('/order', async (ctx) => { const data = await fetchData('SELECT * FROM Orders;'); return ctx.json(data); }); app.get('/product', async (ctx) => { const data = await fetchData('SELECT * FROM Order_Status;'); return ctx.json(data); }); export default app; Already connect via Cloudflare dashboard, please help ๐ฆ
conn = connect(config); } await next(); }); async function fetchData(query: string) { const data = await conn.execute(query); return data.rows; } app.get('/order', async (ctx) => { const data = await fetchData('SELECT * FROM Orders;'); return ctx.json(data); }); app.get('/product', async (ctx) => { const data = await fetchData('SELECT * FROM Order_Status;'); return ctx.json(data); }); export default app; Already connect via Cloudflare dashboard, please help ๐ฆ
2 Replies
tried the code from https://developers.cloudflare.com/workers/databases/native-integrations/planetscale/ but still same issue
import { connect } from '@planetscale/database';
export default {
async fetch(request, env) {
const config = {
host: env.DATABASE_HOST,
username: env.DATABASE_USERNAME,
password: env.DATABASE_PASSWORD,
// see https://github.com/cloudflare/workerd/issues/698
fetch: (url, init) => {
delete (init)["cache"];
return fetch(url, init);
}
}
const conn = connect(config)
const data = await conn.execute('SELECT * FROM products;')
return new Response(JSON.stringify(data.rows), {
status: 200,
headers: {
'Content-Type': 'application/json'
}
});
},
};
Cloudflare Docs
PlanetScale ยท Cloudflare Workers docs
PlanetScale is a MySQL-compatible platform that makes databases infinitely scalable, easier and safer to manage.
GitHub
๐ BUG: The cache field on RequestInitializerDict is not implemented...
Which Cloudflare product(s) does this pertain to? Workers for Platforms What version of Wrangler are you using? Latest What operating system are you using? All Describe the Bug Making a fetch reque...
found the issue: When I test in local -> its not working. If I deploy to cloudflare -> its OK.
How to fix this?