From af1a6892f5fb921a0a025a428a89583d653f24db Mon Sep 17 00:00:00 2001 From: Nikolas Date: Wed, 25 Mar 2020 17:22:56 +0100 Subject: [PATCH] Content/init (#29) - add line separators between next step in getting started - remove unfinished setup guide with Prisma migrate for now --- content/01-getting-started/02-quickstart.mdx | 10 ++ .../01-add-to-an-existing-project.mdx | 8 +- .../02-start-from-scratch-sql-migrations.mdx | 10 +- .../03-start-from-scratch-prisma-migrate.mdx | 119 ------------------ 4 files changed, 24 insertions(+), 123 deletions(-) delete mode 100644 content/01-getting-started/03-setup-prisma/03-start-from-scratch-prisma-migrate.mdx diff --git a/content/01-getting-started/02-quickstart.mdx b/content/01-getting-started/02-quickstart.mdx index a525acb0..98f08c16 100644 --- a/content/01-getting-started/02-quickstart.mdx +++ b/content/01-getting-started/02-quickstart.mdx @@ -337,6 +337,9 @@ const deletedUser = await prisma.user.delete({ + +--- + ### Setup Prisma with your own database To learn how to connect Prisma to your own database, you can follow the respective setup guide: @@ -344,6 +347,8 @@ To learn how to connect Prisma to your own database, you can follow the respecti - [Add Prisma to an existing project]() - [Setup Prisma from scratch with your own database]() +--- + ### Explore the data in Prisma Studio (experimental) Prisma Studio is a visual editor for the data in your database. You can use it by running the following command: @@ -352,6 +357,8 @@ Prisma Studio is a visual editor for the data in your database. You can use it b npx prisma studio --experimental ``` +--- + ### Change the database schema (e.g. add more tables) Changing your database schema using SQL typically happens with the following steps. @@ -428,6 +435,9 @@ Now you can run the migration against the database `npx prisma migrate up --exp You can now run queries against the new `Profile` table, e.g. using `prisma.profile.findMany()`. +--- + + ### Try a Prisma example The [`prisma-examples`]() repository contains a number of ready-to-run examples: diff --git a/content/01-getting-started/03-setup-prisma/01-add-to-an-existing-project.mdx b/content/01-getting-started/03-setup-prisma/01-add-to-an-existing-project.mdx index b19b29ef..01ec8fbd 100644 --- a/content/01-getting-started/03-setup-prisma/01-add-to-an-existing-project.mdx +++ b/content/01-getting-started/03-setup-prisma/01-add-to-an-existing-project.mdx @@ -454,6 +454,8 @@ const deletedUser = await prisma.user.delete({ +--- + ### Explore the data in Prisma Studio (experimental) Prisma Studio is a visual editor for the data in your database. You can use it by running the following command: @@ -472,11 +474,13 @@ To evolve the app, you need to follow the same flow of the tutorial: ![](https://imgur.com/7BUqpyv.png) +--- + ### Try a Prisma example The [`prisma-examples`]() repository contains a number of ready-to-run examples: -#### TypeScript +**TypeScript** | Demo | Stack | Description | | :----------------------------------------------------------------------------------------------------------------- | :----------- | --------------------------------------------------------------------------------------------------- | @@ -486,7 +490,7 @@ The [`prisma-examples`]() repository contains a number of ready-to-run examples: | [`rest-express`](https://github.com/prisma/prisma-examples/tree/prisma2/typescript/rest-express) | Backend only | Simple REST API with Express.JS | | [`grpc`](https://github.com/prisma/prisma-examples/tree/prisma2/typescript/grpc) | Backend only | Simple gRPC API | -#### JavaScript (Node.js) +**JavaScript (Node.js)** | Demo | Stack | Description | | :----------------------------------------------------------------------------------------------------------------- | :----------- | :-------------------------------------------------------------------------------------------------- | diff --git a/content/01-getting-started/03-setup-prisma/02-start-from-scratch-sql-migrations.mdx b/content/01-getting-started/03-setup-prisma/02-start-from-scratch-sql-migrations.mdx index 4dcddef1..eaffd29a 100644 --- a/content/01-getting-started/03-setup-prisma/02-start-from-scratch-sql-migrations.mdx +++ b/content/01-getting-started/03-setup-prisma/02-start-from-scratch-sql-migrations.mdx @@ -521,6 +521,8 @@ const deletedUser = await prisma.user.delete({ +--- + ### Explore the data in Prisma Studio (experimental) Prisma Studio is a visual editor for the data in your database. You can use it by running the following command: @@ -529,6 +531,8 @@ Prisma Studio is a visual editor for the data in your database. You can use it b npx prisma studio --experimental ``` +--- + ### Change the database schema (e.g. add more tables) To evolve the app, you need to follow the same flow of the tutorial: @@ -539,11 +543,13 @@ To evolve the app, you need to follow the same flow of the tutorial: ![](https://imgur.com/7BUqpyv.png) +--- + ### Try a Prisma example The [`prisma-examples`]() repository contains a number of ready-to-run examples: -#### TypeScript +**TypeScript** | Demo | Stack | Description | | :----------------------------------------------------------------------------------------------------------------- | :----------- | --------------------------------------------------------------------------------------------------- | @@ -553,7 +559,7 @@ The [`prisma-examples`]() repository contains a number of ready-to-run examples: | [`rest-express`](https://github.com/prisma/prisma-examples/tree/prisma2/typescript/rest-express) | Backend only | Simple REST API with Express.JS | | [`grpc`](https://github.com/prisma/prisma-examples/tree/prisma2/typescript/grpc) | Backend only | Simple gRPC API | -#### JavaScript (Node.js) +**JavaScript (Node.js)** | Demo | Stack | Description | | :----------------------------------------------------------------------------------------------------------------- | :----------- | :-------------------------------------------------------------------------------------------------- | diff --git a/content/01-getting-started/03-setup-prisma/03-start-from-scratch-prisma-migrate.mdx b/content/01-getting-started/03-setup-prisma/03-start-from-scratch-prisma-migrate.mdx deleted file mode 100644 index 4031d1c8..00000000 --- a/content/01-getting-started/03-setup-prisma/03-start-from-scratch-prisma-migrate.mdx +++ /dev/null @@ -1,119 +0,0 @@ ---- -title: 'Start from scratch (Prisma Migrate)' -metaTitle: '' -metaDescription: '' ---- - -## Overview - -**Note: The content of this page is temporary and will be updated soon.** - -This page explains how to get started with Prisma from scratch by connecting it to an empty database. It uses Prisma Migrate to define and migrate your database schema. - -> **Warning**: Prisma Migrate is currently in an **experimental** state. When using any of the commands below, you need to explicitly opt-in via an `--experimental` flag, e.g. `prisma2 migrate save --name 'init' --experimental`. - -Follow these steps for an initial Prisma setup: - -1. Run `mkdir hello-prisma` to create your project directory -1. Run `cd hello-prisma` to navigate into it -1. Run `touch schema.prisma` to create an empty [Prisma schema](../../prisma-schema-file.md) -1. Add a `datasource` to the Prisma schema and set your database connection string as the `url`, e.g.: - ```prisma - datasource db { - provider = "postgresql" - url = "postgresql://janedoe:janedoe@localhost:5432/hello-prisma" - } - ``` -1. Add your models to the Prisma schema, e.g.: - - ```prisma - model Post { - post_id Int @id @default(autoincrement()) - content String? - title String - author User? - } - - model Profile { - profile_id Int @id @default(autoincrement()) - bio String? - user User - } - - model User { - user_id Int @id @default(autoincrement()) - email String @unique - name String? - posts Post[] - profiles Profile[] - } - ``` - -1. Add a `generator` to the Prisma schema to be able to generate Prisma Client: - ```prisma - generator client { - provider = "prisma-client-js" - } - ``` -1. Run the following commands to configure your project (TypeScript): - ``` - npm init -y - npm install typescript ts-node prisma2 @types/node --save-dev - npm install @prisma/client - ``` -1. Run `touch tsconfig.json` and the following contents to it: - ```json - { - "compilerOptions": { - "sourceMap": true, - "outDir": "dist", - "strict": true, - "lib": ["esnext"], - "esModuleInterop": true - } - } - ``` -1. Migrate your database by running the following commands: - ``` - npx prisma2 migrate save --name 'init' --experimental - npx prisma2 migrate up --experimental - ``` -1. Generate Prisma Client based on your data model with the following command: - ``` - npx prisma2 generate - ``` -1. Run `touch index.ts` to create a source file and add the following code: - - ```ts - import { PrismaClient } from '@prisma/client'; - - const prisma = new PrismaClient(); - - // A `main` function so that we can use async/await - async function main() { - const user1 = await prisma.user.create({ - data: { - email: 'alice@prisma.io', - name: 'Alice', - posts: { - create: { - title: 'Watch the talks from Prisma Day 2019', - content: 'https://www.prisma.io/blog/z11sg6ipb3i1/', - }, - }, - }, - include: { - posts: true, - }, - }); - console.log(user1); - } - - main() - .catch(e => console.error(e)) - .finally(async () => { - await prisma.disconnect(); - }); - ``` - -1. Run `npx ts-node index.ts` to execute the script