您好,登錄后才能下訂單哦!
安裝前提條件:
1、已經安裝了docker運行環境
2、以下命令執行記錄發生在MackBook環境
3、已經安裝了PostgreSQL(我使用的是11版本)
4、Node開發運行環境可以正常工作
首先需要通過Node包管理器安裝Prisma工具:
npm install -g prisma
然后,創建并初始化prisma項目:
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后,再次回車確認選擇。
? 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
輸入數據庫用戶對應的密碼后回車確認。
? 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/liuchunming033/article/details/44810899
官方參考資料地址:
https://www.prisma.io/docs/quickstart/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。