@prisma/extension-accelerate
Advanced tools
Comparing version 0.0.0-experimental-1522a6a to 0.0.0-experimental-1584e8d
{ | ||
"name": "@prisma/extension-accelerate", | ||
"type": "module", | ||
"version": "0.0.0-experimental-1522a6a", | ||
"version": "0.0.0-experimental-1584e8d", | ||
"description": "Prisma Client extension for Accelerate", | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"import": "./dist/esm/index.js", | ||
"require": "./dist/cjs/index.js" | ||
} | ||
"node": { | ||
"import": "./dist/esm/entry.node.js", | ||
"require": "./dist/cjs/entry.node.js" | ||
}, | ||
"import": "./dist/esm/entry.fetch.js", | ||
"require": "./dist/cjs/entry.fetch.js", | ||
"default": "./dist/esm/entry.fetch.js" | ||
}, | ||
"types": "./dist/cjs/index.d.ts", | ||
"types": "./dist/cjs/entry.node.d.ts", | ||
"scripts": { | ||
@@ -26,18 +29,21 @@ "build": "./scripts/build.sh", | ||
"devDependencies": { | ||
"prisma": "^4.10.0-dev.72", | ||
"@prisma/client": "^4.10.0-dev.72", | ||
"@tsconfig/esm": "^1.0.2", | ||
"@tsconfig/node14": "^1.0.3", | ||
"@tsconfig/node18-strictest-esm": "^1.0.1", | ||
"@typescript-eslint/eslint-plugin": "^5.47.1", | ||
"@typescript-eslint/parser": "^5.47.1", | ||
"dotenv": "^16.0.3", | ||
"eslint": "^8.30.0", | ||
"prettier": "2.8.1", | ||
"@prisma/client": "^5.2.0", | ||
"@tsconfig/node-lts": "^18.12.4", | ||
"@tsconfig/node16": "^16.1.1", | ||
"@tsconfig/strictest": "^2.0.1", | ||
"@typescript-eslint/eslint-plugin": "^6.4.1", | ||
"@typescript-eslint/parser": "^6.4.1", | ||
"dotenv": "^16.3.1", | ||
"eslint": "^8.47.0", | ||
"prettier": "^3.0.2", | ||
"prisma": "^5.2.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.4" | ||
"typescript": "^5.1.6" | ||
}, | ||
"peerDependencies": { | ||
"@prisma/client": ">=4.10.0-dev.72" | ||
"@prisma/client": ">=4.16.1" | ||
}, | ||
"engines": { | ||
"node": ">=16" | ||
} | ||
} |
# Accelerate Prisma Client extension | ||
Prisma Client extension to enable _Accelerate_. | ||
This is the package for the [Prisma Client extension](https://www.prisma.io/docs/concepts/components/prisma-client/client-extensions?utm_source=github&utm_medium=accelerate-readme) that enables usage of Prisma Accelerate. | ||
[Prisma Accelerate](https://www.prisma.io/data-platform/accelerate?utm_source=github&utm_medium=accelerate-readme) provides an external connection pool and global caching layer that you can use to speed up your database queries. | ||
It is part of the [Prisma](https://www.prisma.io?utm_source=github&utm_medium=accelerate-readme) ecosystem, alongside other tools such as: | ||
- [Prisma ORM](https://github.com/prisma/prisma): Next-generation Node.js and TypeScript ORM, supporting PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, CockroachDB, and MongoDB. | ||
- [Prisma Pulse](https://www.prisma.io/data-platform/pulse?utm_source=github&utm_medium=accelerate-readme): Real-time database events with type-safe subscriptions. | ||
Prisma is leading Data DX, a philosophy that promotes simplicity in data-driven application development. Learn more on the [Data DX manifesto](https://www.datadx.io/?utm_source=github&utm_medium=accelerate-readme). | ||
## Getting started with Accelerate | ||
### Resources | ||
You can explore Accelerate with the following resources: | ||
- [Get started](https://www.prisma.io/docs/data-platform/accelerate/getting-started?utm_source=github&utm_medium=accelerate-readme) | ||
- [Documentation](https://www.prisma.io/docs/data-platform/accelerate/what-is-accelerate?utm_source=github&utm_medium=accelerate-readme) | ||
- [Prisma Data Platform](https://console.prisma.io/login?utm_source=github&utm_medium=accelerate-readme) | ||
- [Accelerate Speed Test](https://accelerate-speed-test.prisma.io/?utm_source=github&utm_medium=accelerate-readme) | ||
### Using Accelerate | ||
#### 1. Enable Accelerate | ||
Log into [Prisma Data Platform](https://console.prisma.io/login?utm_source=github&utm_medium=accelerate-readme) and enable Accelerate for your project. | ||
#### 2. Add Accelerate to your application | ||
Replace the database connection string with the Accelerate connection string you generated in Prisma Data Platform (assuming you store your database connection string in the `DATABASE_URL` in the `.env` file): | ||
```bash | ||
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__" | ||
``` | ||
To be able to seamlessly continue to use Prisma Migrate, you can set the `directUrl` property in your `datasource`: | ||
```prisma | ||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
directUrl = env("DIRECT_DATABASE_URL") | ||
} | ||
``` | ||
And then add the URL that connects directly to your database as the value for `DIRECT_DATABASE_URL` : | ||
```prisma | ||
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__" | ||
DIRECT_DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE" | ||
``` | ||
Finally, extend your Prisma Client instance with the Accelerate extension to enable Accelerate’s connection pool: | ||
```ts | ||
import { PrismaClient } from "@prisma/client/edge"; | ||
import { withAccelerate } from "@prisma/extension-accelerate"; | ||
const prisma = new PrismaClient().$extends(withAccelerate()); | ||
``` | ||
#### 3. Add caching to your Accelerate queries | ||
You can optionally configure caching on a per-query level using the `ttl` (Time-To-Live) and `swl` (Stale-While-Revalidate) options: | ||
```ts | ||
await prisma.user.findMany({ | ||
cacheStrategy: { | ||
ttl: 3_600, | ||
swr: 500, | ||
}, | ||
}); | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
72243
28
1320
77
8