PlanetScale
PlanetScale ↗ is a MySQL-compatible platform that makes databases infinitely scalable, easier and safer to manage.
Database Integrations allow you to connect to a database from your Worker by getting the right configuration from your database provider and adding it as secrets to your Worker.
To set up an integration with PlanetScale:
-
You need to have an existing PlanetScale database to connect to. Create a PlanetScale database ↗ or import an existing database to PlanetScale ↗.
-
From the PlanetScale web console ↗, create a
products
table with the following query: -
Insert some data in your newly created table. Run the following command to add a product and category to your table:
-
Add the PlanetScale integration to your Worker:
- Log in to the Cloudflare dashboard ↗ and select your account.
- In Account Home, select Workers & Pages.
- In Overview, select your Worker.
- Select Integrations > PlanetScale.
- Follow the setup flow, selecting the database created in step 1.
-
In your Worker, install the
@planetscale/database
driver to connect to your PlanetScale database and start manipulating data: -
The following example shows how to make a query to your PlanetScale database in a Worker. The credentials needed to connect to PlanetScale have been automatically added as secrets to your Worker through the integration.
To learn more about PlanetScale, refer to PlanetScale's official documentation ↗.