diff --git a/content/02-understand-prisma/03-how-prisma-fits-into-your-stack/01-rest.md b/content/02-understand-prisma/03-how-prisma-fits-into-your-stack/01-rest.md index c5ad93e74b..60eb8c164d 100644 --- a/content/02-understand-prisma/03-how-prisma-fits-into-your-stack/01-rest.md +++ b/content/02-understand-prisma/03-how-prisma-fits-into-your-stack/01-rest.md @@ -14,7 +14,7 @@ When building REST APIs, Prisma Client can be used inside your _route controller As Prisma Client is "only" responsible for sending queries to your database, it can be combined with any HTTP server library or web framework of your choice. -Here are a few examples: +Here's a non-exhaustive list of libraries and frameworks you can use with Prisma: - [Express](https://expressjs.com/) - [koa](https://koajs.com/) @@ -29,9 +29,7 @@ Here are a few examples: - [Micro](https://github.com/zeit/micro) - [Feathers](https://feathersjs.com/) -## Examples - -### REST API server example +## REST API server example Assume you have a Prisma schema that looks similar to this: @@ -69,10 +67,10 @@ You can now implement route controller (e.g. using Express) that use the generat app.get('/feed', async (req, res) => { const posts = await prisma.post.findMany({ where: { published: true }, - include: { author: true } - }) - res.json(posts) -}) + include: { author: true }, + }); + res.json(posts); +}); ``` Note that the `feed` endpoint in this case returns a nested JSON response of `Post` objects that _include_ an `author` object. Here's a sample response: @@ -97,7 +95,7 @@ Note that the `feed` endpoint in this case returns a nested JSON response of `Po ```ts app.post(`/post`, async (req, res) => { - const { title, content, authorEmail } = req.body + const { title, content, authorEmail } = req.body; const result = await prisma.post.create({ data: { title, @@ -105,39 +103,39 @@ app.post(`/post`, async (req, res) => { published: false, author: { connect: { email: authorEmail } }, }, - }) - res.json(result) -}) + }); + res.json(result); +}); ``` #### `PUT` ```ts app.put('/publish/:id', async (req, res) => { - const { id } = req.params + const { id } = req.params; const post = await prisma.post.update({ where: { id: Number(id) }, data: { published: true }, - }) - res.json(post) -}) + }); + res.json(post); +}); ``` #### `DELETE` ```ts app.delete(`/post/:id`, async (req, res) => { - const { id } = req.params + const { id } = req.params; const post = await prisma.post.delete({ where: { id: Number(id), }, - }) - res.json(post) -}) + }); + res.json(post); +}); ``` -### Ready-to-tun example projects +## Ready-to-tun example projects You can find several ready-to-tun examples that show how to implement a REST API with Prisma Client in the [`prisma-examples`](https://github.com/prisma/prisma-examples/) repository. diff --git a/content/02-understand-prisma/03-how-prisma-fits-into-your-stack/02-graphql.md b/content/02-understand-prisma/03-how-prisma-fits-into-your-stack/02-graphql.md index 0c7e97aabc..06f85334b7 100644 --- a/content/02-understand-prisma/03-how-prisma-fits-into-your-stack/02-graphql.md +++ b/content/02-understand-prisma/03-how-prisma-fits-into-your-stack/02-graphql.md @@ -1,14 +1,12 @@ --- - title: "GraphQL" - metaTitle: "" - metaDescription: "" +title: 'GraphQL' +metaTitle: '' +metaDescription: '' --- -**Note: The content of this page is still in progress.** - ## Overview -GraphQL is a query language for APIs. It is often used as an alternative to RESTful APIs, but can also be used as an additional "gateway" layer on top of existing RESTful services. +[GraphQL](http://graphql.org/) is a query language for APIs. It is often used as an alternative to RESTful APIs, but can also be used as an additional "gateway" layer on top of existing RESTful services. With Prisma, you can build GraphQL servers that connect to a database. Prisma is completely agnostic to the GraphQL tools you use. When building as GraphQL server, you can combine Prisma with tools like Apollo Server, `express-graphql`, TypeGraphQL, GraphQL.js or pretty much any tool or library that you're using in your GraphQL server setup. @@ -35,11 +33,11 @@ The GraphQL schema and HTTP server are typically handled by separate libraries. In addition to these standalone and single-purpose libraries, there are several projects building integrated _application frameworks_: -| Framework | Stack | Built by | Prisma | Description | -| :----------------------------------------- | :--------------- | :------------------------------------------------ | :--------------------- | :---- | -| [Nexus](https://www.nexusjs.org/#/) | Backend only | [Prisma Labs](https://github.com/prisma-labs/) | Prisma is optional | "Delightful GraphQL Application Framework" | -| [Redwood.js](https://redwoodjs.com) | Fullstack | [Tom Preston-Werner](https://github.com/mojombo/) | Built on top of Prisma | "Bringing full-stack to the JAMstack. " | -| [Blitz](https://github.com/blitz-js/blitz) | Fullstack | [Brandon Bayer](https://github.com/flybayer) | Built on top of Prisma | "Framework for building monolithic, full-stack, serverless React apps with zero data-fetching and zero client-side state management." | +| Framework | Stack | Built by | Prisma | Description | +| :----------------------------------------- | :----------- | :------------------------------------------------ | :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------ | +| [Nexus](https://www.nexusjs.org/#/) | Backend only | [Prisma Labs](https://github.com/prisma-labs/) | Prisma is optional | "Delightful GraphQL Application Framework" | +| [Redwood.js](https://redwoodjs.com) | Fullstack | [Tom Preston-Werner](https://github.com/mojombo/) | Built on top of Prisma | "Bringing full-stack to the JAMstack. " | +| [Blitz](https://github.com/blitz-js/blitz) | Fullstack | [Brandon Bayer](https://github.com/flybayer) | Built on top of Prisma | "Framework for building monolithic, full-stack, serverless React apps with zero data-fetching and zero client-side state management." | > **Note**: If you notive any GraphQL libraries/frameworks missing from the list, please let us know. diff --git a/content/04-guides/01-database-workflows/05-foreign-keys/01-postgresql.mdx b/content/04-guides/01-database-workflows/05-foreign-keys/01-postgresql.mdx index e1776a6c7d..752cdb555c 100644 --- a/content/04-guides/01-database-workflows/05-foreign-keys/01-postgresql.mdx +++ b/content/04-guides/01-database-workflows/05-foreign-keys/01-postgresql.mdx @@ -70,7 +70,6 @@ psql ForeignKeyDemo < single-column-foreign-key.sql Congratulations, you just created two tables called `User` and `Post` in the database. The `Post` table references the `User` table via the foreign key defined on the `author` column. -
Alternative: Define the constraint as a column constraint
diff --git a/content/04-guides/01-database-workflows/06-cascading-deletes/01-postgresql.mdx b/content/04-guides/01-database-workflows/06-cascading-deletes/01-postgresql.mdx index 5e10d556aa..5a8049cf3b 100644 --- a/content/04-guides/01-database-workflows/06-cascading-deletes/01-postgresql.mdx +++ b/content/04-guides/01-database-workflows/06-cascading-deletes/01-postgresql.mdx @@ -87,7 +87,6 @@ update or delete on table "User" violates foreign key constraint "Post_author_fk Detail: Key (id)=(1) is still referenced from table "Post". ``` -
Alternative: Define the constraint as a table constraint
diff --git a/content/04-guides/01-database-workflows/06-cascading-deletes/02-mysql.mdx b/content/04-guides/01-database-workflows/06-cascading-deletes/02-mysql.mdx index aa992c9ecb..7744ddf325 100644 --- a/content/04-guides/01-database-workflows/06-cascading-deletes/02-mysql.mdx +++ b/content/04-guides/01-database-workflows/06-cascading-deletes/02-mysql.mdx @@ -108,7 +108,6 @@ update or delete on table "User" violates foreign key constraint "Post_author_fk Detail: Key (id)=(1) is still referenced from table "Post". ``` -
Alternative: Define the constraint as a column constraint
diff --git a/content/05-more/05-faq.mdx b/content/05-more/05-faq.mdx index 59ec4e16d5..2d27b15f00 100644 --- a/content/05-more/05-faq.mdx +++ b/content/05-more/05-faq.mdx @@ -4,4 +4,83 @@ metaTitle: '' metaDescription: '' --- -Coming 🔜 +## Can I still access my database directly (e.g. using raw SQL)? + +Yes, Prisma Client provides has a method called [`.raw`]() which you can use to send raw SQL strings to the database. + +Note that Prisma currently doesn't support full [transactions](). If your application needs transactions, you can use Prisma Client alongside other lightweight query builder such as [knex](https://www.github.com/tgriesser/knex) to perform one-off queries as transaction. + +## Is Prisma Client an ORM? + +ORMs are typically object-oriented mapping layers that map classes to tables. A record is represented as an object that not only carries data but also implements various behaviors for storage, retrieval, serialization and deserialization of its own data, sometimes it also implements business/domain logic. Prisma Client acts more like a _query builder_ returning plain JavaScript objects with a focus on structural typing rather than rich object behavior. + +## Will Prisma Client support more databases (and other data sources) in the future? + +Yes. Prisma Client is based on Prisma's [query engine]() that can connect to any data source that provides a proper _connector implementation_. There will be built-in connectors such as the current ones for [PostgreSQL](), [MySQL]() and [SQLite](). + +However, it's also possible to build your own connectors, more documentation on that topic will follow soon. + +## How can I see the generated queries that Prisma Client sends to my database? + +You can view generated SQL queries by providing the `log` option to the `PrismaClient` constructor like so: + +```ts +const prisma = new PrismaClient({ + log: ["query"] +}) +``` + +Learn more on the [Debugging]() page in the docs. + +## How do schema migrations work with Prisma Client? + +Prisma Client is not opinionated on how exactly you migrate your database schema (e.g. create new tables, alter columns, ...). You can keep your existing migration system and re-[introspect]() your database schema after each schema migration. You can also use Prisma Migrate to run your migrations based on Prisma's declarative [data model definition](). + +## Is Prisma Client production-ready? Should I start using it? + +Although it's officially in beta, Prisma Client is considered production-ready. This means you can start using it in mission critical applications. Note that there might still be breaking changes as Prisma Client continues to be developed. + + +## Does Prisma Client support GraphQL schema delegation and GraphQL binding? + +GraphQL [schema delegation](https://www.prisma.io/blog/graphql-schema-stitching-explained-schema-delegation-4c6caf468405/) connects two GraphQL schemas by passing the [`info`](https://www.prisma.io/blog/graphql-server-basics-demystifying-the-info-argument-in-graphql-resolvers-6f26249f613a/) object from a resolver of the first GraphQL schema to a resolver of the second GraphQL schema. Schema delegation also is the foundation for [GraphQL binding](https://github.com/graphql-binding/graphql-binding). + +Prisma 1 officially supports both schema delegation and GraphQL binding as it exposes a GraphQL CRUD API through the [Prisma server](https://www.prisma.io/docs/prisma-server/). This API can be used to as foundation for an application-layer GraphQL API created with GraphQL binding. + +With Prisma 2.0, Prisma's [query engine]() doesn't expose a [spec](https://graphql.github.io/graphql-spec/June2018/)-compliant GraphQL endpoint any more, so usage of schema delegation and GraphQL binding with Prisma 2.0 is not supported. To build GraphQL servers with Prisma 2.0, be sure to check out [GraphQL Nexus](https://nexusjs.org/). GraphQL Nexus provides a code-first and type-safe way to build GraphQL servers in a scalable way. + +Learn more about how Prisma can be used to build GraphQL servers on the [GraphQL]() page in the docs. + +## Am I locked-in when using Prisma Migrate? Is it easy to migrate off it? + +There's no lock-in when using Prisma Migrate. To stop using Prisma for your migrations, you need to: + +- delete your [Prisma schema file]() +- the `migrations` directory on your file system +- drop the `_Migrations` table in your database/schema + +## How do I see details about how Prisma migrates my database schema? + +Each migration is represented via its own directory on your file system inside a directory called `migrations`. The name of each directory contains a timestamp so that the order of all migrations in the project history can be maintained. + +Each of these migration directories contains detailed information about the respective migration, for example which steps are executed (and in what order) as well as a human-friendly Markdown file that summarizes the most important information about the migration, such as the source and the target [data model definition]() of the migration. This information can also be found in the `_Migrations` table in your database/schema. + +## Is Prisma Migrate production-ready? Should I start using it? + +Prisma Migrate is currently in an experimental state. It has a number of issues that don't make it suitable for production uses. You can track the progress of the release process on [isprisma2ready.com](https://www.isprisma2ready.com). + +While it shouldn't be used for mission critical applications yet, Prisma Migrate is definitely in a usable state. You can help us accelerate the release process by using it and [sharing your feedback]() with us. + +## Since Prisma 2.0 is released, will Prisma 1 still be maintained? + +Yes, Prisma 1 will continue to be maintained. However, most Prisma engineering and support resources will go into the development of [Prisma 2.0](https://github.com/prisma/prisma2). + +There will be no new features developed for Prisma 1. + +## Where can I get more information about the plans for Prisma 2.0? + +Check out the [`specs`](https://github.com/prisma/specs) repo which contains the technical specifications for future Prisma 2.0 features. Get involved by [creating issues](https://github.com/prisma/prisma2/issues) and [sharing feedback]()! + +## How much does Prisma 2.0 cost? + +Prisma 2.0 is open source and using it is free of any charge! In the future, Prisma will offer additional cloud services to facilitate various database- and Prisma-related workflows. Note that these are optional, Prisma 2.0 can continue to be used without consuming any commercial services. \ No newline at end of file