Limitations
The Neon serverless driver supports two modes: HTTP and WebSockets. PlanetScale only supports WebSocket connections, so you must use aPool
object to execute queries, as shown in the example below.
You also must disable pileline connections.
More info in the security section below.
Using the driver
1
First, install the driver via npm:
2
You’ll need to create a Postgres role to use with the driver.
Once you have these credentials, place them in environment variables:These can all be added to a unified Postgres connection URL for use by the driver:
3
When connecting in your worker function, you must set the following configuration option when using the driver.
4
With this in place, pass the
process.env.DATABASE_URL
to the serverless driver Pool object, and begin executing queries on your PlanetScale database.
Here’s a complete example using the connection string created above:Security
PlanetScale requiresSCRAM-SHA-256
for all authentication to Postgres servers.
We maintain this strict requirement for security purposes.
Because of this, you must set neonConfig.pipelineConnect = false;
when using the Neon serverless driver.
This adds a bit of additional latency, but is necessary to connect using SCRAM-SHA-256
.
When this is "password"
(the default value) it requires using cleartext password authentication, reducing connection security.