Connect to the TiDB serverless from the Netlify Edge Function using deno mysql driver.
You can deploy it with netlify cli:
netlify deploy
Netlify edge runtime is based on the Deno deploy. Deno mysql driver over TCP is more suitable as we have made it compatible with TiDB serverless.
Still want to use serverless driver? Here is an example:
import { connect } from 'https://esm.sh/@tidbcloud/serverless'
export default async () => {
const conn = connect({url: Netlify.env.get('DATABASE_URL')})
const result = await conn.execute('show tables')
return new Response(JSON.stringify(result));
}
export const config = { path: "/example" };