diff --git a/.gitignore b/.gitignore index 23c74905af..0537f2b963 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ node_modules # generated content .source cache +.compute +.compute-pruned-* # test & build /coverage @@ -37,9 +39,11 @@ next-env.d.ts /blob-report/ /playwright/.cache/ /playwright/.auth/ +.playwright-cli/ # opensrc - source code for packages opensrc .env # locally cloned prisma-next repo prisma-next/ +.prisma/ diff --git a/README.md b/README.md index e7927a9b4b..9b4d73466a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,62 @@ +# DEPLOYED TO COMPUTE + +This repository has been refactored and deployed to Prisma Compute using the monorepo app configuration in [`prisma.compute.ts`](prisma.compute.ts). The deployment uses three Compute apps: one for the homepage shell, one for docs, and one for the blog. + +## Live URLs + +| Surface | URL | Notes | +| --- | --- | --- | +| Homepage | [https://cmqkpxx900dea0ddxaoyu2s8l.fra.prisma.build/](https://cmqkpxx900dea0ddxaoyu2s8l.fra.prisma.build/) | Site app deployed from `apps/site`. | +| Docs | [https://cmqkoe8hg0cyt03l79u7thj20.fra.prisma.build/docs](https://cmqkoe8hg0cyt03l79u7thj20.fra.prisma.build/docs) | Docs app deployed from `apps/docs`. The homepage rewrites `/docs` to this Compute app. | +| Blog | [https://cmqkpw54o0yp4zndvj3zei5ml.fra.prisma.build/blog](https://cmqkpw54o0yp4zndvj3zei5ml.fra.prisma.build/blog) | Blog app deployed from `apps/blog`. The homepage rewrites `/blog` to this Compute app. | + +Representative route inventory and verification results are in [`docs/compute-deploy/route-inventory.md`](docs/compute-deploy/route-inventory.md). + +## Screenshots + +### Homepage + +![Homepage deployed to Prisma Compute](docs/compute-deploy/prisma-compute-homepage.png) + +### Docs + +![Docs deployed to Prisma Compute](docs/compute-deploy/prisma-compute-docs.png) + +### Blog + +![Blog deployed to Prisma Compute](docs/compute-deploy/prisma-compute-blog.png) + +## Obstacles Report + +| Obstacle | Resolution | +| --- | --- | +| The repository is a pnpm/Turbo monorepo, while Prisma Compute needs an explicit deploy shape. | Added [`prisma.compute.ts`](prisma.compute.ts) with three Compute apps: `site`, `docs`, and `blog`, each with its own root, build command, port, framework adapter, and environment. | +| The existing Next.js apps were not configured for Compute's standalone deployment requirements. | Added Compute-gated `output: "standalone"`, `outputFileTracingRoot`, and `turbopack.root` settings in the site, docs, and blog Next configs. These settings are enabled only when `PRISMA_COMPUTE_DEPLOY=true`, so normal local and production workflows keep their existing behavior. | +| Existing static asset prefixes such as `/site-static`, `/docs-static`, and `/blog-static` broke direct Compute asset loading. | Omitted those prefixes during Compute builds so the deployed apps can serve Next static assets from their own Compute origins. | +| Turbo was pruning deployment-only environment variables from builds. | Added `PRISMA_COMPUTE_DEPLOY`, `NEXT_DOCS_ORIGIN`, and `NEXT_BLOG_ORIGIN` to the Turbo build environment and set `PRISMA_COMPUTE_DEPLOY=true` directly in each Compute build command. | +| The homepage production build normally requires explicit blog and docs origins. | Bypassed that guard only for Compute builds, then configured the site Compute app with docs and blog origins so `/docs` and `/blog` can route to the deployed Compute apps. | +| Blog and docs search initialized the Mixedbread client at module load, which fails without `MIXEDBREAD_API_KEY`. | Changed both search API routes to lazily initialize Mixedbread only when a key exists. Missing keys now return an empty search result instead of failing the build or runtime. | +| Docs generated a large number of static routes during the Compute build. | Added Compute-specific `generateStaticParams()` guards for docs pages, LLMS routes, and OG routes so the Compute deployment can build a minimal runtime artifact instead of a full static export. | +| The blog `public` directory was too large for a practical Compute deployment. | Removed 152 pre-2024 blog posts and their matching media directories from `apps/blog/content/blog` and `apps/blog/public`, leaving 112 posts from 2024 onward. | +| The docs Next standalone server exceeded Compute beta runtime limits when served directly. | Switched docs to a no-proxy Bun static runtime generated by [`scripts/compute-build-static-app.mjs`](scripts/compute-build-static-app.mjs). The script builds the local Next app, snapshots the verified docs routes, and embeds the required HTML/assets into `.compute/server.ts`. | +| Docs section index pages such as `/docs/compute`, `/docs/orm`, and `/docs/guides` returned `Not found` because the first static runtime only embedded a small hand-written route list. | Updated the docs static builder to derive routes from docs frontmatter URLs, prioritize all Compute docs and major section indexes, and deploy a 181-page current-docs subset that was verified live. | +| Capturing every current docs route produced a 101.5 MB Compute artifact that deployed but never became reachable from its generated URL. | Capped the generated docs subset to 180 prioritized current docs routes. The resulting 57.7 MB artifact deployed successfully and serves `/docs/compute` plus the verified route subset. | +| The blog Next artifact still risked unpacking large media, even after pruning older content. | Switched blog to the same no-proxy Bun static runtime. The original failing blog post URL and representative current blog routes are served directly by Compute from embedded snapshots/assets. | +| Prisma Compute's Bun adapter bundles only the configured entrypoint and does not ship sibling generated files automatically. | Embedded the captured HTML, selected public assets, encoded `_next/static` assets, RSS, OG image, and favicon data into the generated `.compute/server.ts` files. | +| Encoded Next font asset URLs such as `%5Bwdth%2C...%5D` returned 404 from the first static runtime. | Added encoded path aliases for embedded static assets so browser requests with percent-encoded filenames resolve correctly. | +| The docs sidebar promo image was client-rendered and not visible as a plain HTML asset reference. | Added `/docs/imgs/sidebar-banners/prisma-next.png` to the docs static route inventory so the screenshot renders cleanly. | +| The old blog post URL reported by the user failed after the no-proxy change. | Rebuilt and redeployed the blog as a static Compute app. The exact `launching-prisma-compute-public-beta` URL, including tracking query parameters, now returns `200`. | +| A newer 2026 blog post returned `Not found` because the blog static runtime still relied on a small hand-written route list. | Updated the blog static builder to derive recent post routes from blog frontmatter, include dependent author and series pages for those posts, and add the blog series index. The reported post, its tracking-query URL, its media asset, its author page, its series page, and the homepage rewrite now return `200`. | +| Expanding the blog snapshot to 52 source routes produced a 330.5 MB Compute artifact that deployed but returned the platform `Service not found` page. | Capped the generated blog post subset to the 20 newest retained posts plus their author/series dependencies. The resulting 42-source-route, 230.1 MB deployment is reachable and passed live verification across all generated source routes plus query/rewrite checks. | +| The local machine hit disk pressure while iterating on Next/Turbo artifacts. | Removed generated cache and temporary deployment artifacts that were not needed, then kept `.compute`, `.playwright-cli`, and local Prisma cache output ignored. | +| The Compute CLI surfaced database URL warnings even though these apps do not need a database connection for this deployment. | Left database integration disabled and deployed without a Compute database binding. The warnings were non-blocking for static homepage, docs, and blog verification. | +| A Bun-powered CLI invocation failed while building docs because `tsx` could not resolve a nested CJS package under Bun. | Used the Node-backed `bunx @prisma/cli@latest` invocation for Compute deploys while still letting Compute build the generated Bun app runtime. | +| Preview-branch deployment was not necessary for this migration proof and introduced extra routing friction. | Used a dedicated Compute project named `web-compute-migration` with production branch `main` and deployed the three apps there. | +| Duplicate preview services created during iteration made app-name lookup ambiguous. | Targeted the production `main` branch with explicit app names and verified the stable production URLs after each deploy. | +| The service token needed to be used for deployment without leaking credentials into source control. | Used the token only through the local CLI environment. The token is not stored in the repository or README. | + +No requests are proxied to the existing live site. The site app is a Next standalone Compute app. The docs and blog apps are no-proxy Bun static runtimes generated from local Next builds and verified representative routes. + # Prisma Documentation [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/prisma/docs/blob/main/CONTRIBUTING.md) [![Discord](https://img.shields.io/discord/937751382725886062)](https://discord.com/invite/prisma-937751382725886062?utm_source=twitter&utm_medium=bio&dub_id=0HxLEKaaOg6pL0OL) diff --git a/apps/blog/content/blog/accelerate-ga-release-I9cQM6bSf2g6/index.mdx b/apps/blog/content/blog/accelerate-ga-release-I9cQM6bSf2g6/index.mdx deleted file mode 100644 index 12df3fbd84..0000000000 --- a/apps/blog/content/blog/accelerate-ga-release-I9cQM6bSf2g6/index.mdx +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: "Prisma Accelerate now in General Availability" -slug: "accelerate-ga-release-I9cQM6bSf2g6" -date: "2023-10-26" -authors: - - "Sam Bhatti" -metaTitle: "Prisma Accelerate now in General Availability" -metaDescription: "Supercharge your applications with Prisma Accelerate's scalable connection pooling and global edge caching. Plus, enjoy our exclusive launch offer." -metaImagePath: "/accelerate-ga-release-I9cQM6bSf2g6/imgs/meta-42554fa75736c00b0ca55e1e440dde26f43dcb3f-1266x711.png" -heroImagePath: "/accelerate-ga-release-I9cQM6bSf2g6/imgs/hero-de83f5f843f2a86abd05659c94c3069e7577a0f5-844x474.svg" -heroImageAlt: "Prisma Accelerate now in General Availability" -tags: - - "announcement" - - "platform" ---- - -Now in General Availability: Dive into [Prisma Accelerate](https://pris.ly/accelerate-blog), enhancing global database connections with connection pooling and edge caching for fast data access. - -Developing data-driven applications comes with its challenges, and efficient database connections and swift data retrieval are essential. The Prisma ORM is key for database access and now, with Prisma Accelerate, we provide a solution that offers not only global connection pooling across 16 regions but also edge caching. It guarantees efficient and low-latency database interactions. - -## What is Prisma Accelerate? - -- **Evolved Connection Pooling**: Available in 16 regions globally, Prisma Accelerate’s connection pooler ensures reliability and efficient database interactions, regardless of the database's geographical location. -- **Global Edge Caching:** Improve data retrieval speeds by caching frequently accessed data in over 280 locations worldwide, reducing the latency for repetitive database queries. - -### Pricing -Prisma Accelerate is priced based on your usage, and our Starter, Pro, and Business plans are now available to everyone. You can get started for free and only pay for what you need with full control over your costs, which we calculate based on the number of requests and your egress. - -To see the specifics of each plan, and to find the perfect fit for your needs, explore our detailed [Pricing page](https://www.prisma.io/pricing). - -> **Launch Special until Nov 12, 2023** - As part of Prisma Accelerate’s GA launch, we're excited to celebrate with you and offer a **50% lifetime discount** on the base price of our Pro and Business plans when you subscribe by November 12, 2023. - -## Prisma Accelerate in Production -To see what Prisma Accelerate can do, let's take a look at its implementation in two real-world cases: - -### Cal.com: Enhancing scheduling efficiency - -The logo of Cal.com - -[Cal.com](https://cal.com/), a popular open-source scheduling platform, provides appointment bookings for a diverse range of users. Given the high frequency of appointments scheduled every minute, they recognized the importance of swift database access in delivering the best user experience, especially during peak times. - -Prisma Accelerate's robust connection pooling is designed to handle high volumes of database interactions efficiently. For platforms like Cal.com, this means over 4M queries every day to enable seamless management of appointments, even with heavy traffic peaks. - - - - - Prisma Accelerate seamlessly complements our platform, powering Cal.com to handle millions of database queries every day, across our global user base. - - - - - -### Formbricks: Privacy-first survey suite - -The logo of Formbricks - -[Formbricks](https://formbricks.com/), an open-source experience management platform, streamlines user interactions, understanding their sentiments toward products. As a tool that facilitates real-time insights through surveys and feedback, swift and reliable database interactions are crucial. - -Leveraging Prisma Accelerate's connection pooling, Formbricks achieves seamless and rapid data access, with high-traffic peaking at 7M queries in a 24-hour time period. This allows them to maintain consistent performance, even when faced with unpredictable user traffic, ensuring a smooth experience for all their users. - - - - Thanks to Prisma Accelerate, we can seamlessly scale our serverless applications without concerns about data layer performance. - - - - - -## Prisma Accelerate and the Data DX Vision - -With the rise in data complexity, developers encounter mounting challenges in managing, integrating, and deploying data-centric solutions. [Data DX](https://datadx.io) champions a simplified approach to data-driven application development, avoiding unnecessary complexity while retaining depth and detail. Prisma Accelerate aligns perfectly with this philosophy, serving as a pivotal tool in our Data DX journey. - -### Time to get started - -We are incredibly excited about Prisma Accelerate and can't wait to see what you’ll build with it. As you dive in, please share your thoughts, engage with us on [Discord](https://pris.ly/discord), and let's build amazing data-driven applications together! - -[Get started with Prisma Accelerate](https://pris.ly/accelerate-blog) diff --git a/apps/blog/content/blog/accelerate-preview-release-ab229e69ed2/index.mdx b/apps/blog/content/blog/accelerate-preview-release-ab229e69ed2/index.mdx deleted file mode 100644 index 5e735a2310..0000000000 --- a/apps/blog/content/blog/accelerate-preview-release-ab229e69ed2/index.mdx +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: "Accelerate in Preview: Global Database Cache & Scalable Connection Pool" -slug: "accelerate-preview-release-ab229e69ed2" -date: "2023-08-10" -authors: - - "Ankur Datta" -metaTitle: "Accelerate in Preview: Global Database Cache & Scalable Connection Pool" -metaDescription: "Accelerate is going into Preview! Learn how to enable high-speed, scalable applications with a global cache and connection pooler." -metaImagePath: "/accelerate-preview-release-ab229e69ed2/imgs/meta-3a75c0ed5f8837980765d5b7589367216653d6b7-1266x711.png" -heroImagePath: "/accelerate-preview-release-ab229e69ed2/imgs/hero-587aeef34568af2258cd4e5f0453710b0b94259c-844x474.svg" -heroImageAlt: "Accelerate in Preview" -tags: - - "announcement" - - "platform" ---- - -[Prisma Accelerate](https://www.prisma.io/data-platform/accelerate) is now available to everyone in Preview! Make your application faster with our powerful global cache and scalable connection pooler. [Get started now](https://pris.ly/pdp), and let us know what you think. - -## Table of contents - -- [Cache query results close to your servers](#cache-query-results-close-to-your-servers) -- [Supercharge serverless and edge apps with Accelerate's connection pool](#supercharge-serverless-and-edge-apps-with-accelerates-connection-pool) -- [Boost your app performance and scalability](#boost-your-app-performance-and-scalability) -- [Let us know what you think](#let-us-know-what-you-think) - - -[Accelerate](https://www.prisma.io/data-platform/accelerate) has transitioned from Early Access to public Preview! Now you can leverage the power of a managed global cache and connection pool with Prisma with support for 300 locations globally and use a connection pool with support for 16 regions. - -## Cache query results close to your servers - -Accelerate ensures that cached query results are always served from the nearest cache node to the application server, resulting in faster response times. Accelerate's cache nodes are built with Cloudflare and are available in 300 locations worldwide. - -This greatly benefits distributed, serverless, and edge applications as performance remains consistent regardless of the application server's location. This is because a cache node is always available closest to the application server, and when data is cached, large round trips to the database are avoided. - -Accelerate cache nodes are available globally - -Suppose a database is located in North America, and a request is made to the database from a server in Japan. By using Accelerate to cache query results, the results can be retrieved from a cache in the same region of Japan, avoiding a round trip of about ~16,000 kilometers (considering the speed of light, there would be an additional latency of approximately 53 milliseconds) to fetch query results from the database in North America. - -### Programmatic control over cache behavior - -Accelerate extends your Prisma Client with an intuitive API offering granular control over established caching patterns on a per-query basis. Utilise [time-to-live](https://www.prisma.io/docs/data-platform/accelerate/concepts#time-to-live-ttl) (TTL) or [state-while-revalidate](https://www.prisma.io/docs/data-platform/accelerate/concepts#stale-while-revalidate-swr) (SWR) to fine-tune your cache behavior tailored to your application needs. - - - -```javascript -await prisma.user.findMany({ - cacheStrategy: { -+ ttl: 60, - }, -}); -``` -```javascript -await prisma.user.findMany({ - cacheStrategy: { -+ swr: 30, - }, -}); -``` -```javascript -await prisma.user.findMany({ - cacheStrategy: { -+ ttl: 60, -+ swr: 30, - }, -}); -``` - - -> Learn more about caching strategies in our [docs](https://www.prisma.io/docs/data-platform/accelerate/concepts#cache-strategies). - -To comply with regulations regarding the storage of personally identifiable information (PII) like phone numbers, social security numbers, and credit card numbers, you may need to avoid caching query results. Excluding the `cacheStrategy` from your queries provides a straightforward way to opt out of caching your query results. - -> To understand the advantages and drawbacks associated with caching database query results, read the blog post Database Caching: A Double-Edged Sword? Examining the Pros and Cons. - -## Supercharge serverless and edge apps with Accelerate's connection pool - -Accelerate seamlessly integrates with serverless and edge environments. While database connections are stateful, serverless and edge environments are stateless, making it challenging to manage stateful connections from a stateless environment. - -In serverless environments, a sudden surge in traffic can spawn several ephemeral servers (also referred to as ‘serverless functions’) to handle requests. This results in each server opening up one or more database connections, eventually exceeding the database connection limit. - -> Learn more about the serverless connection management challenge here. - -Accelerate's built-in connection pool can be deployed in the same region as your database. The connection pool helps you scale your application by persisting and reusing database connections, preventing the connection limit from being exceeded. - -Accelerate connection pooler - -## Boost your app performance and scalability - -Accelerate caches query results with incredible efficiency, allowing for lightning-fast retrieval of cached data with latencies as low as 5ms. The significant speedup provided by Accelerate is most noticeable when the results of complex, long-running queries are cached. - -For example, a query that usually takes 30 seconds to process can be cached with Accelerate, resulting in a response time of approximately 5-20 milliseconds, providing a massive ~1000x speedup. - -| | Queries with Prisma Client | Queries with Prisma Client and Accelerate without caching | Queries with Prisma Client and Accelerate with caching | -| :-------------- | :-----------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------: | -| **Description** | Prisma Client connects directly to the database and executes the query | The query is routed through the connection pool instance hosted close to the database region | Accelerate caches the query | -| **Pros** | • No need to write SQL

• No additional service or component | • Built-in connection pooling for serverless and edge runtimes

• Allows Prisma to be used in Edge Functions

| • Built-in connection pooling for serverless and edge runtimes

• Allows Prisma to be used in Edge Functions

• Performance boost | -| **Cons** | • Setting up and managing connection pooling for serverless/edge environments

• Long round-trips in multi-region deployments | • Slight latency overhead due to routing query through Accelerate’s connection pooler | • Data may be stale | - -Accelerate enables you to serve more users with fewer resources. Storing frequently accessed query results reduces the need for repeated database queries. This improves scalability and performance by freeing up the database to perform more tasks. Application servers can handle more requests if query results are cached because the queries respond faster. This can help accelerate your website's response times. - -
-[Test Accelerate's speed](https://accelerate-speed-test.vercel.app/) - -## Let us know what you think! - - -Get started to supercharge your application with Prisma Accelerate! Try it out and share your experience with us on Twitter or join the conversation on Discord. -
- -[Get started](https://pris.ly/pdp) -    - -[Read the docs](https://www.prisma.io/docs/data-platform/accelerate/what-is-accelerate) diff --git a/apps/blog/content/blog/all-you-need-to-know-about-apollo-client-2-7e27e36d62fd/index.mdx b/apps/blog/content/blog/all-you-need-to-know-about-apollo-client-2-7e27e36d62fd/index.mdx deleted file mode 100644 index f156abfae3..0000000000 --- a/apps/blog/content/blog/all-you-need-to-know-about-apollo-client-2-7e27e36d62fd/index.mdx +++ /dev/null @@ -1,149 +0,0 @@ ---- -title: "All you need to know about Apollo Client 2" -slug: "all-you-need-to-know-about-apollo-client-2-7e27e36d62fd" -date: "2017-11-07" -authors: - - "Nikolas Burk" -metaTitle: "All you need to know about Apollo Client 2 | Prisma" -metaDescription: "Learn about Apollo Client 2.0, including Apollo Link, local state management, cache updates, and the biggest changes from earlier Apollo Client releases." -metaImagePath: "/all-you-need-to-know-about-apollo-client-2-7e27e36d62fd/imgs/hero-ebd9548e6d9cfb33c4e35eac48e11a80532a8d30-1440x960.jpg" -heroImagePath: "/all-you-need-to-know-about-apollo-client-2-7e27e36d62fd/imgs/hero-ebd9548e6d9cfb33c4e35eac48e11a80532a8d30-1440x960.jpg" -heroImageAlt: "All you need to know about Apollo Client 2" ---- - -Apollo Client, a powerful and flexible GraphQL client library, just reached version 2.0. In this post, we want to - highlight some of the major changes compared to the previous release. - -## Simple modularity with Apollo Link - -Probably the biggest change in Apollo Client 2.0 is the transition from using the concept of a _network interface_ to a more modular approach based on a new primitive: [Apollo Link](https://github.com/apollographql/apollo-link). - -> Note: To learn more about the motivation behind Apollo Link, check out this article by [Evans Hauser](https://twitter.com/EvansHauser) who worked on Apollo Link as a summer intern: [Apollo Link: The modular GraphQL network stack](https://dev-blog.apollodata.com/apollo-link-the-modular-graphql-network-stack-3b6d5fcf9244) - -The now deprecated network interface used to enable your `ApolloClient` instance to send HTTP requests. It was also possible to hook into the process of preparing and sending the request (or processing the response) using the concept of _middleware_, e.g. for adding headers to the request. - -Apollo Client 2.0 still is based on the idea of middleware — however, this middleware now actually is a first-class citizen and can be implemented using Apollo Link. For each task that you require for your networking stack (data validation, logging, caching,…) you can now write a dedicated `link` and simply add it to the _chain_ of middleware that’s invoked whenever you’re sending a request. - -Here is what a simple implementation for a Link that’s making HTTP calls based on [`graphql-request`](https://github.com/graphcool/graphql-request) looks like: - -```js -class GraphQLRequestLink extends ApolloLink { - constructor({ endpoint, headers }) { - super() - this.client = new GraphQLClient(endpoint, { headers }) - } - - request(operation) { - return new Observable(observer => { - const { variables, query } = operation - this.client - .request(print(query), variables) - .then(data => { - observer.next(data) - observer.complete() - }) - .catch(e => { - observer.error(e) - }) - }) - } -} -``` -There are already a number of officially supported links which you can simply pull into your application using npm. Here’s a quick overview over a few of them (see [here](https://github.com/apollographql/apollo-link/tree/master/packages) for the full list): - -- [`apollo-link-http`](https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-http): Used to send GraphQL operations over HTTP -- [`apollo-link-error`](https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-error): Used for custom error reporting (e.g. with [Sentry](https://sentry.io/)) -- [`apollo-link-dedup`](https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-dedup): Deduplicated matching requests before sending them -- [`apollo-link-ws`](https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-ws): Used to send GraphQL operations over Websockets (often used for subscriptions) - -## Observables instead of Promises - -Another major change in going from 1.x to 2.0 is that [Observables](http://reactivex.io/intro.html) are replacing Promises as the core primitive for how data is processed. - -> [At a basic level, a Link is a function that takes a (GraphQL) operation and returns an Observable.](https://www.apollographql.com/docs/link/overview.html#overview) - -The biggest difference between Promises and Observables is that an **Observable represents a _stream_ of data** (meaning it can receive multiple values over time) while a **Promise only represents a single value** resulting from an asynchronous operation. - -Observables emit events during their lifetime, there generally are three kinds of events: - -- The **`next`** event carries the data the observers are interested in. This event can (but doesn’t have to) be emitted multiple times. For example, if an Observable represents a simple HTTP request, **`next`** will be emitted only once. If it represents mouse click events, it can emit any number of events until the Observable terminates. -- The **`error`** event indicates that an error occurred and terminates the Observable. Observers will receive some information that describes the error attached to the event. -- The **`completed`** event simply terminates the Observable and doesn’t carry any data. - -This example from [Evans Hauser’s article](https://dev-blog.apollodata.com/apollo-link-creating-your-custom-graphql-client-c865be0ce059) makes the role of these events clear: - -```js -class CatchLink extends ApolloLink { - request(operation, forward) { - const observable = forward(operation) - - return new Observable(observer => { - const subscription = observable.subscribe({ - next: observer.next.bind(observer), - error: error => { - // reroute errors as proper data - observer.next({ - data: { - error, - }, - }) - }, - complete: observer.complete.bind(observer), - }) - - return () => { - subscription.unsubscribe() - } - }) - } -} -``` -The `CatchLink` intercepts any errors that are received from the API and places them in the `data` field of the GraphQL response, thus treating them as regular response data which are not terminating the Observable. In the case of `next` and `completed` events it simply forwards these to the observers. - -The introduction of Observables opens the door to use links for implementing not only regular queries and mutations that follow the classic “request-response-cycle”, but also for subscriptions or live queries which continuously receive data from the server. - -## New npm package structure - -If you have used `react-apollo` before, you most likely know that it was the only dependency you had to install in your application to import anything you’d need from Apollo Client (except for subscriptions). A typical setup with `react-apollo` looked as follows: - -```js -import { ApolloProvider, createNetworkInterface, ApolloClient } from 'react-apollo' - -const networkInterface = createNetworkInterface({ uri }) -const client = new ApolloClient({ networkInterface }) - -export default ( - - - -) -``` -Since one major theme of Apollo Client 2.0 is _modularity_, you now have to import your functionality from multiple individual packages: - -```js -import { ApolloProvider } from 'react-apollo' -import { ApolloClient } from 'apollo-client' -import { HttpLink } from 'apollo-link-http' -import { InMemoryCache } from 'apollo-cache-inmemory' - -const client = new ApolloClient({ - link: new HttpLink({ uri }), - cache: new InMemoryCache(), -}) - -export default ( - - - -) -``` -In order to send queries and mutations, you also need to explicitly install the [`graphql-tag`](https://github.com/apollographql/graphql-tag) and even [`graphql`](https://github.com/graphql/graphql-js) libraries. - -To offer some convenience when getting started, the Apollo team created the [`apollo-client-presets`](https://www.npmjs.com/package/apollo-client-preset) package which includes `apollo-client`, `apollo-cache-inmemory` and `apollo-link-http`. Read more about the installation in the [README](https://github.com/apollographql/apollo-client#installation). - -## What’s next - -Apollo Client is a community-driven effort and thanks to the new link concept, it’s possible to write dedicated pieces of functionality and share them with other developers. This enables different cache implementations (so you’re not depending on Redux any more when using Apollo Client), offline support, deferred queries and much more! Exciting times for GraphQL 💚 - -> To learn more about Apollo Client 2.0 follow the [React & Apollo tutorial on How to GraphQL](https://www.howtographql.com/react-apollo/0-introduction/). - diff --git a/apps/blog/content/blog/ambassador-program-nxkWGcGNuvFx/index.mdx b/apps/blog/content/blog/ambassador-program-nxkWGcGNuvFx/index.mdx deleted file mode 100644 index 7f5b07b157..0000000000 --- a/apps/blog/content/blog/ambassador-program-nxkWGcGNuvFx/index.mdx +++ /dev/null @@ -1,97 +0,0 @@ ---- -title: "Prisma Ambassador Program — Building A Community of Experts" -slug: "ambassador-program-nxkWGcGNuvFx" -date: "2021-05-28" -authors: - - "Vladi Stevanovic" - - "Nikolas Burk" -metaTitle: "Announcing the Prisma Ambassador Program — Building A Community of Experts" -metaDescription: "We are thrilled to announce the launch of the Ambassador Program to empower the Prisma community, while also helping individual contributors build their own brand." -metaImagePath: "/ambassador-program-nxkWGcGNuvFx/imgs/meta-de28b5e0df55c52078065ee2ae0b44d6cdf0da1e-1692x852.png" -heroImagePath: "/ambassador-program-nxkWGcGNuvFx/imgs/hero-1bdf6237d95ded8d448f28db203012147fdcd39e-846x426.png" -heroImageAlt: "Prisma Ambassador Program — Building A Community of Experts" -tags: - - "announcement" ---- - -We are thrilled to announce the [Prisma Ambassador Program](https://www.prisma.io/ambassador) to empower the Prisma community, while also helping individual contributors build their own brand. - -## A huge shoutout to the awesome Prisma community 💚 - -We're continuosly amazed by the awesome content produced by the [Prisma community](https://www.prisma.io/community), be it in the form of example projects, video tutorials or blog articles! - -Not to mention how community members support each other in [GitHub Discussions](https://github.com/prisma/prisma/discussions) and on [Stackoverflow](https://stackoverflow.com/questions/tagged/prisma) or have lively discussions and show off their Prisma projects on [Slack](https://slack.prisma.io) (join the [`#showcase`](https://app.slack.com/client/T0MQBS8JG/C565176N6) channel to learn more). - -{/* */} - ---- - -## Recognising our community contributors - -Community contributors have helped us immensely over the years by providing an unvarnished review of their Prisma experience, highlighting the good and the not so good. - -This has helped shape the experience of new adopters as well as our own product and vision, allowing us to receive genuine and thoughtful feedback (e.g. via the [`#product-feedback`](https://app.slack.com/client/T0MQBS8JG/C01739JGFCM) channel where you can get in touch directly with our Product team). - -> Community contributors are a very powerful force, that influence new and existing users' choices! - -While Prisma has become significantly more popular over the past year, we're deeply aware that choosing a new tool to work with your database does incur a cognitive and practical cost. - -To make adoption easier and help our users be more successful with Prisma, we ... - -- ... provide dedicated community support via [GitHub Discussions](https://github.com/prisma/prisma/discussions) and [Slack](https://slack.prisma.io) -- ... incorporate feedback in our roadmap and release new versions [every two weeks](https://github.com/prisma/prisma) -- ... invest heavily in education e.g. via extensive [documentation](https://www.prisma.io/docs) and [videos](https://pris.ly/youtube) - -However, ultimately, **peer to peer feedback is indeed the most influencial approach there is**, and we want to reward those contributors who help spread the word about Prisma. - ---- - -## Introducing the Ambassador Program - -We wanted to invest in a user-centered, peer-to-peer program, that would grow from the periphery to the center. And so the Prisma Ambassador Program was born! - -These are the three guiding principles of this program: - -- **Rewarding and engaging our biggest fans**, who are genuinely passionate about our product, share our values, and enjoy supporting the wider community. -- **Build a network of Prisma champions and experts**, creating a space where they can collaborate with one another and share best practices. -- **Build long term cooperation with a loyal user base**, to help us shape our product roadmap and ultimately the vision for Prisma. - ---- - -## Why become an Ambassador? - -A couple of the benefits of becoming a Prisma Ambassador are: - -- **Networking** with other peers in your field by joining the private Ambassador Slack channel. -- **Direct communication** with the Prisma DevRel, Product and Engineering teams. -- **Enhancement to your credibility**, as well as strengthening your professional profile. -- **Prestige and recognition** for being selected as one of our most outstanding contributors. -- Ability to add a **valuable experience** to your resume and media kit. -- **Bonuses** in the form of training, swag, trips, design support, etc. - ---- - -## How does it work? - -Your task as a Prisma Ambassador is to highlight our technologies through the channels and mediums **that best fits your skills**, be that in the form of a blog post, video, event talk, GitHub contributions, etc. - -We prize quality over quantity. If you're already building valuable Prisma content, we want you to continue to do so, just with more support from our end. Our goal is to make this a mutually beneficial partnership! - -If you want to become an Ambassador, your mission is to: - -- Produce at least 1 piece of content per quarter -- Answer at least 1 question on [GitHub Discussions](https://github.com/prisma/prisma/discussions) or [Stackoverflow](https://stackoverflow.com/questions/tagged/prisma) per quarter -- Attend our quarterly Ambassador Board meetings - -The more you contribute the more we'll reward you! You can find more information about the program on the new [Ambassador Program website](https://www.prisma.io/ambassador) and the [FAQs](https://pris.ly/ambassador-faq). - -New Ambassadors will be supported by a dedicated Prisma team throughout the program, providing a tailored onboarding experience and answering all the questions they might have. - ---- - -## We can't wait to read and promote your content - -Throughtout the years, the Prisma community has been a fantastic source of ideas, feedback and content. We couldn't be more grateful and proud to work for and with such amazing individuals! We hope the [Ambassador Program](https://www.prisma.io/ambassador) will enable you all to further shine and highlight the amazing work you are doing. - -Don't hesitate to reach out to learn more. We can't wait to see what further content the community will create! - diff --git a/apps/blog/content/blog/amplication-customer-story-nmlkBNlLlxnN/index.mdx b/apps/blog/content/blog/amplication-customer-story-nmlkBNlLlxnN/index.mdx deleted file mode 100644 index ed15579046..0000000000 --- a/apps/blog/content/blog/amplication-customer-story-nmlkBNlLlxnN/index.mdx +++ /dev/null @@ -1,101 +0,0 @@ ---- -title: "How Prisma helps Amplication evolutionize backend development" -slug: "amplication-customer-story-nmlkBNlLlxnN" -date: "2022-04-29" -authors: - - "Alex Emerich" -metaTitle: "How Prisma helps Amplication evolutionize backend development" -metaDescription: "How Prisma helps Amplication evolutionize backend development" -metaImagePath: "/amplication-customer-story-nmlkBNlLlxnN/imgs/meta-4baa84e48a0da8e13e23367137d5a17515119aaf-2881x1620.png" -heroImagePath: "/amplication-customer-story-nmlkBNlLlxnN/imgs/hero-b1fb9ec0c8fca054011688621bfe51ea1836af10-844x474.svg" -heroImageAlt: "How Prisma helps Amplication evolutionize backend development" -tags: - - "case-study" ---- - -[Amplication](https://amplication.com/) is an open-source development tool. It helps you develop quality Node.js applications without spending time on repetitive coding tasks. It’s perfect for both backend and fullstack developers. - -## Prioritizing developers' focus - -Amplication enables development teams to focus their efforts on complex business logic and core functionality of their apps. Developers can then download the generated source code and start utilizing their skills to freely customize their project. - -With the help of Prisma, Amplication is packaging a full stack of modern tools for professional developers and driving the evolution of application development with low-code and open-source. - -## Empowering professional developers - -Working at larger companies, [Amplication](https://amplication.com/) founder, Yuval Hazzaz was regularly building business applications that required repetitive, error-prone tasks to get started. His teams needed a database, a user interface to interact with, and an API. These tasks were taking time away from innovating new app features. Yuval wanted to introduce a solution to improve developer experience and to create one platform that empowers professional developers to quickly create business applications and extend platform capabilities. - -With Amplication, you can easily create data models and configure role-based access control with a simple and intuitive UI (or even [via their CLI](https://github.com/amplication/amplication/tree/master/packages/amplication-cli#amp-entitiescreate-displayname)). Based on these model definitions, Amplication generates production-ready, yet fully customizable, application code. This code is continuously pushed to your GitHub repository, and you get a dedicated Docker container to house your database, a Node.js application, and a React client. - -![Amplication UI](/amplication-customer-story-nmlkBNlLlxnN/imgs/amplication-ui.png) - -For fullstack developers, their repetitive coding tasks are taken care of, but they still retain **complete ownership** of the code to deploy where they wish and are free to download the generated app code and continue development elsewhere. - -Developers get the foundation of what they need to seamlessly start an app, and reserve the ability to alter and add the code they need with no lock-in. Amplication's offering is truly the best of both worlds. - - -## The Amplication stack - -Amplication generates application code for you with the same building blocks they use themselves internally. The tools are all proven open-source and popular among the respective developer communities. - -For the server side you get: -- [NestJS](https://nestjs.com/): A progressive Node.js framework for building efficient, reliable and scalable server-side applications -- [Prisma](https://www.prisma.io/): A next-generation ORM for Node.js and TypeScript -- [PostgreSQL](https://www.postgresql.org/): The world’s most advanced open source relational database -- [Passport](http://www.passportjs.org/): A simple, unobtrusive authentication for Node.js -- [GraphQL](https://graphql.org/): A query language for APIs -- [Swagger UI](https://swagger.io/): Visual documentation for REST APIs based on OpenAPI specification -- [Jest](https://jestjs.io/): A delightful JavaScript testing framework with a focus on simplicity -- [Docker](https://www.docker.com/): An open platform for developing, shipping, and running applications - -![Generated App Server-side Architecture](/amplication-customer-story-nmlkBNlLlxnN/imgs/amplication-prisma-diagram2.png) - -The Amplication team strongly believes in open-source technology and a user focused community, so they made sure this belief was at the center of the tools they bring their users. - -## Betting on Prisma early - -When first beginning work on Amplication in 2020, [Yuval Hazaz](https://twitter.com/Yuvalhazaz1), CEO at Amplication, made an early bet on Prisma to not just be a tool used by himself and his engineers, but also a central cog in the stack managed by Amplication users. Among other ORM options, Yuval felt Prisma was meeting developer needs the best and was strongly convinced by the Prisma community. Yuval was impressed by the consistent work done by the Prisma team to bring new features to its users based on feedback directly from the community. Amplication places a strong importance on the open-source community’s ability to collaborate and make better developer experiences, a sentiment shared at Prisma. - - - -“Prisma was a really good bet, and it helped us a lot when working on Amplication. It was an enabler for us because we actually use Prisma in the generated app, and it is really easy to use. We adopted Prisma conventions as our standard, and it saves lots of time having from reinventing things ourselves.” - Yuval - - - -Aside from community, Prisma features also make life easier for the Amplication team. Prisma’s TypeScript experience was an important qualification for Amplication's data layer. Incorporating [NestJS](https://www.prisma.io/nestjs) with [GraphQL](https://www.prisma.io/graphql) in the Amplication-generated app made Prisma an easy choice in the stack. The [Prisma Client](https://www.prisma.io/client) integrates smoothly into the modular architecture of NestJS giving an incredible level of type-safety. - -Yuval also knew that Prisma’s migrations were going to be critical for Amplication even in its infancy as a feature. - - - -“Supporting and building with TypeScript was really great for us. I also think migrations are amazing. Even though it was early and was not what it is now today, it was an important vision that we wanted to follow and made our decision even easier.”- Yuval - - - -Yuval has seen [Prisma Migrate](https://www.prisma.io/migrate) improve since its first introduction, and it continues to deliver a quality developer experience. Prisma Migrate’s ability to automatically generate fully customizable database schema migrations from Prisma Schema changes keeps Amplication engineers and users focused on building out new app features rather than hassling with refactoring for entity changes and error-handling. - -Professional application development products rely on the ability to choose the right tools for their users. Amplication has a trust in the Prisma community and belief that Prisma features are delivering the best experience for developers. This is why they include it among other great tools in their generated app. - -## What’s ahead for Amplication - -[Amplication](https://amplication.breezy.hr/) is continuing to grow quickly and expected to double their team in the coming year. Already showing success with their current product, they are enthusiastic to continue working on an extensive [roadmap](https://amplication.com/#roadmap) full of interesting new features. - -They just recently announced [major seed funding of $6.6mio](https://venturebeat.com/2022/02/09/amplication-builds-out-open-source-low-code-no-code-platform/) to continue working towards evolving professional low-code application development into the modern-day programming practice they think it can be. - -Moreover, the team is working on an enterprise version of Amplication that will include support for micro-services architecture, deployment on Amplication cloud and broad range of features to support large-scale organization requirements. - -We also had the pleasure of speaking with Amplication on our What's New in Prisma Livstream. Check it out to hear more exciting insights from both our teams. - - diff --git a/apps/blog/content/blog/announcing-accelerate-usrvpi6sfkv4/index.mdx b/apps/blog/content/blog/announcing-accelerate-usrvpi6sfkv4/index.mdx deleted file mode 100644 index c0119a4f73..0000000000 --- a/apps/blog/content/blog/announcing-accelerate-usrvpi6sfkv4/index.mdx +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: "Introducing Accelerate in Early Access" -slug: "announcing-accelerate-usrvpi6sfkv4" -date: "2023-01-16" -authors: - - "Andrew Carlson" -metaTitle: "Prisma | Introducing Accelerate in Early Access" -metaDescription: "Query up to 1000x faster on any Prisma-supported database with our new distributed cache and scalable connection pool for Serverless apps." -metaImagePath: "/announcing-accelerate-usrvpi6sfkv4/imgs/meta-25afee16878423e24c7aff2bb3fe49a433996d03-1200x631.png" -heroImagePath: "/announcing-accelerate-usrvpi6sfkv4/imgs/hero-9c6258461d73719cebc60136dd4e976d79306dcb-845x475.svg" -heroImageAlt: "Introducing Accelerate in Early Access" -tags: - - "announcement" - - "platform" ---- - -Query up to 1000x faster on any Prisma-supported database with our distributed cache and scalable connection pool for Serverless apps. - -In late 2021 we embarked on a journey to deliver a platform for building the next generation of data-driven apps. June 2022 saw the GA release of the [Prisma Data Platform](https://cloud.prisma.io/) with the first round of great features. The [Data Proxy](https://www.prisma.io/docs/data-platform/data-proxy), with managed connection pooling; the [Query Console](https://www.prisma.io/docs/data-platform/query-console), which empowers you to run Prisma queries against a database directly from your browser; and the [Data Browser](https://www.prisma.io/docs/data-platform/data-browser), which grants easy, visual access to your databases from anywhere. - -With more than 1200 projects launched on the Data Platform and the Data Proxy serving more than 380,000,000 CPU ms/mo, we're excited to announce the evolution of the Data Proxy into "Accelerate," a fully-fledged Data CDN. - -## Make your app more responsive with a single line of code - -Accelerate includes everything you knew and loved from the Data Proxy, such as managed connection pooling for your Serverless apps, and adds a globally distributed cache that powers up to 1000x faster database queries and drives query latency down to as little as 5ms. - -Deployed globally in close to 280 locations, caching always happens as close to your application as possible. Best of all, it works with your existing database, and you can control the cache behavior straight from your Prisma queries. - -Accelerate is in [Early Access](https://prisma-data.typeform.com/to/WwPDKEQ5), and we're working hard to release it to a GA audience by mid-2023. This release is our next step toward realizing a Data Platform that empowers engineers everywhere to unlock productivity and make it more delightful to work with their data. - -We're so excited to have you join us on this journey, and we can't wait to hear what you think! - -
-
- -[Get on the waitlist](https://www.prisma.io/data-platform/accelerate) diff --git a/apps/blog/content/blog/announcing-discord-1LiAOpS7lxV9/index.mdx b/apps/blog/content/blog/announcing-discord-1LiAOpS7lxV9/index.mdx deleted file mode 100644 index 1db851102c..0000000000 --- a/apps/blog/content/blog/announcing-discord-1LiAOpS7lxV9/index.mdx +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: "Building on an Established Community: Prisma Now on Discord" -slug: "announcing-discord-1LiAOpS7lxV9" -date: "2023-06-16" -authors: - - "Jon Harrell" -metaTitle: "Building on an Established Community: Prisma Now on Discord" -metaDescription: "Prisma is excited to expand the established Prisma Community Discord and further collaborate with the Prisma community." -metaImagePath: "/announcing-discord-1LiAOpS7lxV9/imgs/meta-388b596e6a40f7eeaf42604a4645c93dd051af6a-1267x712.png" -heroImagePath: "/announcing-discord-1LiAOpS7lxV9/imgs/hero-7ae00282956a1f6a68f815b4cffee5ee1b1ce934-844x474.svg" -heroImageAlt: "Prisma Now on Discord" -tags: - - "announcement" ---- - -We are more than excited to join [Discord](https://discord.gg/KQyTW2H5ca)! Read to learn more about how we're approaching our Discord community, what to expect from it and how you can join. - -Hello Prisma Community, - -We're excited to share an important update with you: Prisma is making an entrance onto [Discord](https://discord.gg/KQyTW2H5ca)! While we take great pride in our strong community of over 50,000 members on Slack, we believe it's time to extend our reach and foster additional collaborative conversations on Discord, a platform many of you already enjoy and have asked us to be present on. We are happy to oblige! - -You might already be aware of the unofficial Prisma community on Discord, a space that's been vibrant with discussions and brainstorming. We've seen the impressive engagement and support that this community has grown into and, after talks with the server's creator, we are excited to officially adopt and expand upon this community. - -We would like to express our deepest gratitude to the original server owner, [Olyno](https://github.com/Olyno), whose hard work and dedication have provided a strong foundation for our new community presence on Discord. Their passion has created a dynamic space where Prisma users could connect, share ideas, and support each other. We are thrilled to be able to carry on their work. - -So, why are we adopting Discord? Besides the fact that many of you asked us to set up a Discord server, we see Discord serving the Prisma community in several ways: - -## Casual and open environment - -Discord's origins within the gaming community lends it a more relaxed atmosphere compared to the professional setting of Slack. This encourages informal and lively discussions, and allows users to interact more freely with our developer advocacy and support team. - -## Powerful moderation tools - -Discord’s strong suite of community moderation tools help us ensure that our online environment remains respectful, friendly, and conducive to productive discussions. - -## Topic-specific channels - -Discord’s multi-channel setup allows for more organized conversations on a variety of topics. Whether you want to talk about the latest updates, ask for help, or provide feedback, there's a channel just for that. - -## Advanced integration capabilities - -From code repositories to social media feeds, Discord's integration capabilities provide a one-stop hub where our community can get all the latest news about Prisma. - -## Real-time interaction - -With features like Stage Channels, we can host live events, AMAs, webinars, and more, encouraging real-time interaction between our team and the community. - -![](/announcing-discord-1LiAOpS7lxV9/imgs/discord-screenshot.png) - -We're incredibly excited to embark on this new chapter on Discord and look forward to enhancing the sense of camaraderie and collaboration that the Prisma community is known for. So whether you're an old member or a newcomer, we welcome you to join us on this exciting journey! - -
-[Join Discord](https://discord.gg/KQyTW2H5ca) - -The Prisma Team - diff --git a/apps/blog/content/blog/announcing-prisma-2-n0v98rzc8br1/index.mdx b/apps/blog/content/blog/announcing-prisma-2-n0v98rzc8br1/index.mdx deleted file mode 100644 index 22f97c00a4..0000000000 --- a/apps/blog/content/blog/announcing-prisma-2-n0v98rzc8br1/index.mdx +++ /dev/null @@ -1,692 +0,0 @@ ---- -title: "Prisma 2.0: Confidence and productivity for your database" -slug: "announcing-prisma-2-n0v98rzc8br1" -date: "2020-06-09" -authors: - - "Nikolas Burk" -metaTitle: "Announcing Prisma 2: Confidence and productivity for your database" -metaDescription: "Prisma 2 introduced a type-safe database client and declarative migrations to make working with databases in Node.js and TypeScript faster and more reliable." -metaImagePath: "/announcing-prisma-2-n0v98rzc8br1/imgs/hero-11436ec45c7ccbc812212d1d6d7c8794d9514f2f-1692x852.jpg" -heroImagePath: "/announcing-prisma-2-n0v98rzc8br1/imgs/hero-11436ec45c7ccbc812212d1d6d7c8794d9514f2f-1692x852.jpg" -heroImageAlt: " Ombre Prisma" ---- - -Accessing databases in Node.js and TypeScript can feel brittle and painful. Prisma removes the pain with an auto-generated and type-safe query builder that's tailored to your data! [Try it out!](https://www.prisma.io/docs/getting-started/quickstart) - -## Contents - -- [The problem: Working with databases is difficult](#the-problem-working-with-databases-is-difficult) -- [The solution: Prisma makes databases easy](#the-solution-prisma-makes-databases-easy) -- [What you can build with Prisma](#what-you-can-build-with-prisma) -- [A strong ecosystem growing around Prisma](#a-strong-ecosystem-growing-around-prisma) -- [Getting started with Prisma](#getting-started-with-prisma) -- [A huge thank you to our community 💚](#a-huge-thank-you-to-our-community-) - ---- - -## The problem: Working with databases is difficult - -The existing [landscape of database access libraries](https://www.prisma.io/dataguide/types/relational/comparing-sql-query-builders-and-orms) ranges from sending raw SQL strings to higher-level abstractions like SQL query builders and ORMs. Each of these approaches come with their own [problems and pitfalls](https://www.prisma.io/docs/concepts/overview/why-prisma#problems-with-sql-orms-and-other-database-tools). Overall, there's a lack of best practices for application developers who work with databases in Node.js and TypeScript. - -The jungle of existing tools and lack of best practices have two main consequences: - -- Developers aren't _productive_ because the existing tools don't fit their needs -- Developers aren't _confident_ that they're doing the "right thing" - -## The solution: Prisma makes databases easy - -Prisma is an open source database toolkit. It replaces traditional ORMs and makes database access easy with an auto-generated and type-safe query builder for Node.js and TypeScript. - -Prisma currently supports **PostgreSQL**, **MySQL** and **SQLite** databases – with more planned. Please create [new GitHub issues](https://github.com/prisma/prisma/issues/new) or subscribe to existing ones (e.g. for [MongoDB](https://github.com/prisma/prisma/issues?q=is%3Aissue+is%3Aopen+mongo) or [DynamoDB](https://github.com/prisma/prisma/issues/1676)) if you'd like to see support for specific databases. - -After running the Preview and Beta versions of Prisma 2.0 for almost a year and gathering lots of helpful feedback from our community, we are excited to launch Prisma Client for General Availability 🎉 - -### Prisma Client: Modern database access for Node.js and TypeScript - -Prisma Client provides an entirely new way for developers to access a database with two main goals in mind: - -- **Boost productivity** by letting developers query data in natural and familiar ways -- **Increase confidence** with type-safety, auto-completion and a robust query API - -### How Prisma Client boosts productivity and raises confidence - -In this section, we'll take a closer look at how Prisma Client enables developers to build applications faster while writing more resilient and robust code. - -Here's an overview of the benefits you get from Prisma Client: - -- [Thinking in objects: A natural and familiar query API](#thinking-in-objects-a-natural-and-familiar-query-api) -- [Working intuitively with relations](#working-intuitively-with-relations) -- [Auto-completion for database queries](#auto-completion-for-database-queries) -- [Fully type-safe database queries](#fully-type-safe-database-queries) -- [A declarative and human-readable database schema](#a-declarative-and-human-readable-database-schema) -- [A single source of truth for database and application models](#a-single-source-of-truth-for-database-and-application-models) - -#### Thinking in objects: A natural and familiar query API - -One of the biggest benefits of Prisma Client is the level of abstraction it provides. It allows developers to think of their data in _objects_ (instead of SQL), reducing the cognitive and practical overhead of mapping _relational_ to _object-oriented_ data. - -Although Prisma Client returns data as objects, [it's not an ORM](https://www.prisma.io/docs/concepts/overview/prisma-in-your-stack/is-prisma-an-orm) and therefore doesn't suffer from [common problems often caused by the object-relational impedance mismatch](http://blogs.tedneward.com/post/the-vietnam-of-computer-science/). - -Prisma doesn't map classes to tables and there are no complex model instances or hidden performance pitfalls (e.g. due to lazy loading) as often seen in traditional ORMs. Prisma Client provides a query API for _your_ database schema with a focus on _structural typing_ and natural querying (in that sense, it gets closest to the _data mapper_ pattern of traditional ORMs). - -As an example, assume you have these `User` and `Post` tables: - - - -![Entity Relationship Diagram](/announcing-prisma-2-n0v98rzc8br1/imgs/cQRivY4.png) - -```sql -CREATE TABLE "User" ( - id SERIAL PRIMARY KEY, - email VARCHAR(255) NOT NULL UNIQUE, - name TEXT -); -CREATE TABLE "Post" ( - id SERIAL PRIMARY KEY, - title VARCHAR(25) NOT NULL, - content TEXT, - "authorId" INTEGER NOT NULL, - FOREIGN KEY ("authorId") REFERENCES "User"(id) -); -``` - - -With Prisma Client, you can formulate queries like the following to read and write data in these tables: - - - -```ts -const postsByAuthor = await prisma.post.findMany({ - where: { - author: { id: 42 } - }, -}) -``` -```js -[{ - id: 1, - title: "Follow Prisma on Twitter" - authorId: 42, -}, { - id: 2, - title: "Join us online for Prisma Day 2020" - authorId: 42, -}] -``` - - -As you can see, the resulting `postsByAuthor` contains an array of plain JavaScript objects (if you're using TypeScript, these objects will be strongly typed). - -> **Note**: The `author` field is a _virtual_ [relation field](https://www.prisma.io/docs/concepts/components/prisma-schema/relations#relation-fields) that connects the `Post` to the `User` table in the Prisma Client API. Since it's not directly represented in the database, it can be [named in any way you like](https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/use-custom-model-and-field-names). - -You can also easily include the relations of a model, in this case, you could also retrieve the information about the "author" of the return posts: - - - -```ts -const postsByAuthorWithAuthorInfo = await prisma.post.findMany({ - where: { - author: { id: 42 } - }, - include: { - author: true, - } -}) -``` -```js -[{ - id: 1, - title: "Follow Prisma on Twitter", - content: null, - authorId: 42, - author: { - id: 42, - email: "alice@prisma.io", - name: "Alice" - } -}, { - id: 2, - title: "Join us online for Prisma Day 2020", - content: null, - authorId: 42, - author: { - id: 42, - email: "alice@prisma.io", - name: "Alice" - } -}] -``` - - -Note again that the objects in `postsByAuthorWithAuthorInfo` are fully typed when using TypeScript, so accessing a non-existing property on the `author` of a post, in this case, would throw a compiler error. - -#### Working intuitively with relations - -Accessing related data (meaning, data from tables that are connected via _foreign keys_) can be especially tricky with existing database tools. This is mostly due to the fundamental mismatch of how these relations are represented in relational databases and object-oriented languages: - -- **Relational**: Data is typically [_normalized_](https://en.wikipedia.org/wiki/Database_normalization) (flat) and uses _foreign keys_ to link across entities. The entities then need to be JOINed to manifest the actual relationships. -- **Object-oriented**: Objects can be _deeply nested structures_ where you can traverse relationships simply by using [dot notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Dot_notation). - -Prisma Client lets you intuitively read and write nested data: - - - -```ts -const result = await prisma.user.findMany({ - include: { - posts: { - select: { - id: true, - title: true - } - } - } -}) -``` -```ts -const result = await prisma.user.create({ - data: { - name: "Alice", - email: "alice@prisma.io", - posts: { - create: { - title: "Hello World" - } - } - } -}) -``` -```ts -const result = await prisma.user - .findOne({ where: { id: 42 }}) - .posts() -``` -```ts -const result = await prisma.user - .findOne({ - where: { email: 'alice@prisma.io' }, - }) - .posts({ - where: { - title: { - startsWith: 'Hello', - }, - }, - }) -``` - - -Note again that in all of the above cases, the `result` will be fully typed if you're using TypeScript! - -#### A declarative and human-readable database schema - -Reading definitions of tables and other database structures using SQL (e.g. `CREATE TABLE User`, `ALTER TABLE User ADD COLUMN email`) can feel noisy. Prisma introduces a declarative version of your database schema known as the [Prisma schema](https://www.prisma.io/docs/concepts/components/prisma-schema). - -The Prisma schema is generated by introspecting your database and serves as the foundation for the query API of Prisma Client. As an example, this is the equivalent version of the [above](#thinking-in-objects-a-natural-and-familiar-query-api) `User` and `Post` definitions: - - - -```prisma -model User { - id Int @default(autoincrement()) @id - email String @unique - name String? - posts Post[] -} - -model Post { - id Int @default(autoincrement()) @id - title String - content String? - author User @relation(fields: [authorId], references: [id]) - authorId Int -} -``` -```sql -CREATE TABLE "User" ( - id SERIAL PRIMARY KEY, - email VARCHAR(255) NOT NULL UNIQUE, - name TEXT -); -CREATE TABLE "Post" ( - id SERIAL PRIMARY KEY, - title VARCHAR(25) NOT NULL, - content TEXT, - "authorId" INTEGER NOT NULL, - FOREIGN KEY ("authorId") REFERENCES "User"(id) -); -``` - - -> **Note**: We are also working on a tool for _database migrations_ called [Prisma Migrate](https://www.prisma.io/docs/concepts/components/prisma-migrate). With Prisma Migrate, the [introspection-based workflow](https://www.prisma.io/docs/concepts/overview/what-is-prisma#typical-prisma-workflows) is "reversed" and you can map your declarative Prisma schema to the database; Prisma Migrate will generate the required SQL statements and execute them against the database. - -#### Auto-completion for database queries - -Auto-completion is an immensely powerful feature that enables developers to explore an API in their editors instead of looking up reference docs. Because Prisma Client is generated from _your_ database schema, the query API will feel very familiar to you. - -Having auto-completion available largely contributes to greater productivity because you can "learn the API as you use it". Auto-completion also increases confidence because you can be sure that the suggested API operations will work. - -{/*