Why use the PlanetScale serverless driver
Before learning how to use the PlanetScale serverless driver for JavaScript, it’s worth understanding why you should use this over other MySQL packages available in the directory. Some serverless and edge function hosts do not permit arbitrary outbound TCP connections, which is how many MySQL clients operate. Using the PlanetScale serverless driver for JavaScript provides a means of accessing your database and executing queries over an HTTP connection, which is generally not blocked by cloud providers. If you encounter issues using MySQL packages with PlanetScale, use the serverless driver instead.NoteBe sure to check out our F1 Championship Stats demo application to find examples for use with Cloudflare Workers, Vercel Edge Functions, and Netlify Edge Functions.
Add and use the PlanetScale serverless driver for JavaScript to your project
To install the package in your project, run the following install command:Connect to the database
The first step to using the PlanetScale serverless driver for JavaScript is to connect to your database. You can get your connection string in the PlanetScale dashboard by clicking on your database, clicking “Connect”, and selectingdatabase-js
from the “Select your language or framework” section.

connect
function to create the connection and return it to an object.
Executing queries
To execute a query, use theexecute
function of the connection object, with the query passed as the first parameter.
results
object from the SELECT
statement:
?
in the specific locations you want the parameters passed into.
?
entries in the query with the values passed in the array, in the order in which they were placed.
results
object for the INSERT
statement:
:param_name
format.