安裝前提條件:
一、已經安裝了docker運行環境
二、如下命令執行記錄發生在MackBook環境
三、已經安裝了PostgreSQL(我使用的是11版本)
四、Node開發運行環境能夠正常工做git
首先須要經過Node包管理器安裝Prisma工具:github
npm install -g prisma
而後,建立並初始化prisma項目:docker
prisma init prisma-study
? Set up a new Prisma server or deploy to an existing server? (Use arrow keys) You can set up Prisma for local development (based on docker-compose) ❯ Use existing database Connect to existing database Create new database Set up a local database using Docker Or deploy to an existing Prisma server: Demo server Hosted demo environment incl. database (requires login) Use other server Manually provide endpoint of a running Prisma server
選擇使用已存在的數據庫(Use existing database)後,回車確認選擇。數據庫
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? MySQL MySQL compliant databases like MySQL or MariaDB ❯ PostgreSQL PostgreSQL database
移動上下箭頭鍵盤按鍵,選擇PostgreSQL後,再次回車確認選擇。npm
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? (Use arrow keys) ❯ No Yes (experimental - Prisma migrations not yet supported) Warning: Introspecting databases with existing data is currently an experimental feature. If you find any issues, please report them here: https://github.co m/prisma/prisma/issues
提示是否在選擇的數據庫中包含已存在數據。由於是一個新庫,因此默認選擇No,而後回車確認。瀏覽器
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? No ? Enter database host (localhost)
輸入數據庫的主機地址(注意,由於prisma會運行在docker中,因此,這兒須要配置宿主機IP,在類Linux系統上能夠經過ifconfig命令來獲取IP)。安全
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? No ? Enter database host 10.111.152.242 ? Enter database port (5432)
回車確認使用默認的Postgres數據庫的端口。服務器
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? No ? Enter database host 10.xxx.xxx.xxx(此處爲你的docker宿主機IP) ? Enter database port 5432 ? Enter database user
輸入數據庫的用戶名後回車確認。網絡
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? No ? Enter database host 10.xxx.xxx.xxx(此處爲你的docker宿主機IP) ? Enter database port 5432 ? Enter database user postgres ? Enter database password
輸入數據庫用戶對應的密碼後回車確認。ide
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? No ? Enter database host 10.xxx.xxx.xxx(此處爲你的docker宿主機IP) ? Enter database port 5432 ? Enter database user postgres ? Enter database password study ? Enter database name
輸入使用的數據庫名稱後回車。
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? No ? Enter database host 10.xxx.xxx.xxx(此處爲你的docker宿主機IP) ? Enter database port 5432 ? Enter database user postgres ? Enter database password study ? Enter database name study ? Use SSL? (Y/n)
提示是否使用安全的網絡協議,這裏選擇不使用(輸入n後回車)。
? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? No ? Enter database host 10.xxx.xxx.xxx(此處爲你的docker宿主機IP) ? Enter database port 5432 ? Enter database user postgres ? Enter database password study ? Enter database name study ? Use SSL? No Connecting to database 18ms ? Select the programming language for the generated Prisma client Prisma TypeScript Client Prisma Flow Client ❯ Prisma JavaScript Client Prisma Go Client Don't generate
這裏選擇產生JavaScript客戶端腳本(Prisma JavaScript
Client)。 ? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? PostgreSQL ? Does your database contain existing data? No ? Enter database host 10.xxx.xxx.xxx(此處爲你的docker宿主機IP) ? Enter database port 5432 ? Enter database user postgres ? Enter database password study ? Enter database name study ? Use SSL? No Connecting to database 18ms ? Select the programming language for the generated Prisma client Prisma JavaScript Client Created 3 new files: prisma.yml Prisma service definition datamodel.prisma GraphQL SDL-based datamodel (foundation for database) docker-compose.yml Docker configuration file Next steps: 1. Open folder: cd prisma-study 2. Start your Prisma server: docker-compose up -d 3. Deploy your Prisma service: prisma deploy 4. Read more about Prisma server: http://bit.ly/prisma-server-overview Generating schema... 20ms Saving Prisma Client (JavaScript) at /Users/chunrong.liu/dev/study/prisma-study/generated/prisma-client/
至此,Prisma項目建立並初始化完畢。
接下來按昭Next steps下面的步驟提示執行後續操做。
經過如下命令切換當前目錄至剛建立的項目目錄(prisma-study)中。
cd prisma-study/
經過docker編排命令在docker中運行prisma服務器。
docker-compose up -d
執行後命令行提示以下:
Creating prisma-study_prisma_1 … done
此時服務運行成功。
經過如下命令部署prisma服務。
$ prisma deploy Creating stage default for service default ✔ Deploying service `default` to stage `default` to server `local` 476ms Changes: User (Type) + Created type `User` + Created field `id` of type `GraphQLID!` + Created field `name` of type `String!` + Created field `updatedAt` of type `DateTime!` + Created field `createdAt` of type `DateTime!` Applying changes 1.2s Your Prisma GraphQL database endpoint is live: HTTP: http://localhost:4466 WS: ws://localhost:4466
用流程器打開http://localhost:4466/連接地址,能夠看到以下的UI界面。
運行以下命令能夠看到演練數據:
$ prisma playground Serving playground at http://localhost:3000/playground
此時會自動打開瀏覽器,並顯示以下界面:
關於數據庫沒法鏈接的問題:
https://blog.csdn.net/liuchun...
官方參考資料地址:
https://www.prisma.io/docs/qu...