forked from keystonejs/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Prisma adapter (keystonejs#3298)
- Loading branch information
Showing
71 changed files
with
1,942 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
'@keystonejs/adapter-prisma': major | ||
'@keystonejs/fields': major | ||
'@keystonejs/fields-auto-increment': major | ||
'@keystonejs/fields-cloudinary-image': major | ||
'@keystonejs/fields-content': major | ||
'@keystonejs/fields-location-google': major | ||
'@keystonejs/fields-mongoid': major | ||
'@keystonejs/fields-oembed': major | ||
'@keystonejs/fields-unsplash': major | ||
'@keystonejs/test-utils': major | ||
'@keystonejs/api-tests': major | ||
--- | ||
|
||
Added support for a Prisma adapter to Keystone. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,4 +113,6 @@ tags | |
# End of https://www.gitignore.io/api/vim | ||
|
||
projects/ | ||
temp/ | ||
temp/ | ||
|
||
.api-test-prisma-clients |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ packages/arch/www/public/**/* | |
**/dist | ||
**/.next | ||
**/.keystone | ||
.api-test-prisma-clients |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/*.md | ||
**/*.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @keystonejs/adapter-prisma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<!--[meta] | ||
section: api | ||
subSection: database-adapters | ||
title: Prisma adapter | ||
[meta]--> | ||
|
||
# Prisma database adapter | ||
|
||
[![View changelog](https://img.shields.io/badge/changelogs.xyz-Explore%20Changelog-brightgreen)](https://changelogs.xyz/@keystonejs/adapter-prisma) | ||
|
||
> The Keystone Prisma adapter is not currently production-ready. It depends on the [`prisma-migrate`](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-migrate) system which is currently flagged as `EXPERIMENTAL`. Once `prisma-migrate` is out of experimental mode we will release a production-ready version of `@keystonejs/adapter-prisma`. | ||
The [Prisma](https://www.prisma.io/) adapter allows Keystone to connect a database using a client generated by Prisma. | ||
|
||
> This adapter currently only supports `PostgreSQL`. Future releases will enable support for all database backends which are [supported by Prisma](https://www.prisma.io/docs/reference/database-connectors/database-features). | ||
## Usage | ||
|
||
```javascript | ||
const { PrismaAdapter } = require('@keystonejs/adapter-prisma'); | ||
|
||
const keystone = new Keystone({ | ||
adapter: new PrismaAdapter({ url: 'postgres://...' }), | ||
}); | ||
``` | ||
|
||
## Config | ||
|
||
### `url` | ||
|
||
_**Default:**_ `DATABASE_URL` | ||
|
||
The connection string for your database, in the form `postgres://<user>:<password>@<host>:<port>/<dbname>`. | ||
By default it will use the value of the environment variable `DATABASE_URL`. | ||
|
||
### `getPrismaPath` | ||
|
||
_**Default:**_ `({ prismaSchema }) => '.prisma'` | ||
|
||
A function which returns a directory name for storing the generated Prisma schema and client. | ||
|
||
### `getDbSchemaName` | ||
|
||
_**Default:**_ `({ prismaSchema }) => 'public'` | ||
|
||
A function which returns a database schema name to use for storage of all Keystone tables in your database. | ||
|
||
> You can also set the schema name by including the suffix `?schema=...` in your `DATABASE_URL` or `url`. In this case you should set this value to `() => null`. | ||
### `enableLogging` | ||
|
||
_**Default:**_ `false` | ||
|
||
Enables logging at the [`query`](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/logging#overview) level in the Prisma client. | ||
|
||
### `dropDatabase` | ||
|
||
_**Default:**_ `false` | ||
|
||
Allow the adapter to drop the entire database and recreate the tables / foreign keys based on the list schema in your application. This option is ignored in production, i.e. when the environment variable NODE_ENV === 'production'. | ||
|
||
## Setup | ||
|
||
Before running Keystone with the Prisma adapter you will need to have a PostgreSQL database to connect to. | ||
|
||
If you already have a database then you can use its connection string in the `url` config option. | ||
If you don't have a database already then you can create one locally with the following commands. | ||
|
||
```shell allowCopy=false showLanguage=false | ||
createdb -U postgres keystone | ||
psql keystone -U postgres -c "CREATE USER keystone5 PASSWORD 'k3yst0n3'" | ||
psql keystone -U postgres -c "GRANT ALL ON DATABASE keystone TO keystone5;" | ||
``` | ||
|
||
If using the above, you will want to set a connection string of: | ||
|
||
```javascript | ||
const keystone = new Keystone({ | ||
adapter: new PrismaAdapter({ url: `postgres://keystone5:k3yst0n3@localhost:5432/keystone` }), | ||
}); | ||
``` | ||
|
||
See the [adapters setup](/docs/quick-start/adapters.md) guide for more details on how to setup a database. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { PrismaAdapter, PrismaListAdapter, PrismaFieldAdapter } = require('./lib/adapter-prisma'); | ||
|
||
module.exports = { PrismaAdapter, PrismaListAdapter, PrismaFieldAdapter }; |
Oops, something went wrong.