Connect from Drizzle to Neon
Learn how to connect to Neon from Drizzle
What you will learn:
How to connect from Drizzle
How to use the Neon serverless driver with Drizzle
Source code
Drizzle is a modern ORM for TypeScript that provides a simple and type-safe way to interact with your database. This guide covers the following topics:
Connect to Neon from Drizzle
To establish a basic connection from Drizzle to Neon, perform the following steps:
-
Retrieve your Neon connection string. In the Connection Details widget on the Neon Dashboard, select a branch, a user, and the database you want to connect to. A connection string is constructed for you. The connection string includes the user name, password, hostname, and database name.
-
Add a
DATABASE_URL
variable to your.env
file and set it to the Neon connection string that you copied in the previous step. We also recommend adding?sslmode=require
to the end of the connection string to ensure a secure connection.Your setting will appear similar to the following:
Use the Neon serverless driver with Drizzle
The Neon serverless driver is a low-latency Postgres driver for JavaScript (and TypeScript) that lets you query data from serverless and edge environments. For more information about the driver, see Neon serverless driver.
To set up Drizzle with the Neon serverless driver, use the Drizzle driver adapter. This adapter allows you to choose a different database driver than Drizzle's default driver for communicating with your database.
Install the Neon serverless driver and ws
packages:
Update your Drizzle instance:
You can now use Drizzle instance as you normally would with full type-safety.
Need help?
Join our Discord Server to ask questions or see what others are doing with Neon. Users on paid plans can open a support ticket from the console. For more details, see Getting Support.