New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@prisma/adapter-neon

Package Overview
Dependencies
Maintainers
10
Versions
2136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma/adapter-neon

Prisma's driver adapter for "@neondatabase/serverless"

  • 5.6.0-dev.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26K
increased by15.14%
Maintainers
10
Weekly downloads
 
Created
Source

@prisma/adapter-neon

Prisma driver adapter for Neon Serverless Driver.

See https://github.com/prisma/prisma/releases/tag/5.4.0 and https://www.prisma.io/blog/serverless-database-drivers-KML1ehXORxZV for details.

The following usage tutorial is valid for Prisma 5.4.2 and later versions.

How to install

After creating your database on Neon, you'll need to install the @prisma/adapter-neon driver adapter, Neon’s serverless database driver @neondatabase/serverless, and ws to set up a WebSocket connection for use by Neon.

npm install @prisma/adapter-neon
npm install @neondatabase/serverless
npm install ws

Make sure your Neon database connection string is copied over to your .env file. The connection string will start with postgres://.

# .env
DATABASE_URL="postgres://..."

Make sure you also include the driverAdapters Preview feature in your schema.prisma.

// schema.prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

Now run npx prisma generate to re-generate Prisma Client.

How to use

In TypeScript, you will need to:

  1. Import packages
  2. Set up the Neon serverless database driver
  3. Instantiate the Prisma Neon adapter with the Neon serverless database driver
  4. Pass the driver adapter to the Prisma Client instance
// Import needed packages
import { Pool, neonConfig } from '@neondatabase/serverless';
import { PrismaNeon } from '@prisma/adapter-neon';
import { PrismaClient } from '@prisma/client';
import ws from 'ws';

// Setup
neonConfig.webSocketConstructor = ws;
const connectionString = `${process.env.DATABASE_URL}`;

// Init prisma client
const pool = new Pool({ connectionString });
const adapter = new PrismaNeon(pool);
const prisma = new PrismaClient({ adapter });

// Use Prisma Client as normal

Now your code has built-in benefits of the Neon serverless driver, such as WebSocket connections and message pipelining, while Prisma covers connection creation and destruction, error handling, and type safety. If you have any feedback about our Neon Serverless Driver support, please leave a comment on our dedicated GitHub issue and we'll use it as we continue development.

FAQs

Package last updated on 24 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc