安裝前提條件:
10年積累的成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先做網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有靜海免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
1、已經(jīng)安裝了docker運(yùn)行環(huán)境
2、以下命令執(zhí)行記錄發(fā)生在MackBook環(huán)境
3、已經(jīng)安裝了PostgreSQL(我使用的是11版本)
4、Node開發(fā)運(yùn)行環(huán)境可以正常工作
首先需要通過Node包管理器安裝Prisma工具:
npm install -g prisma
然后,創(chuàng)建并初始化prisma項(xiàng)目:
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
選擇使用已存在的數(shù)據(jù)庫(Use existing database)后,回車確認(rè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?
??MySQL?????????????MySQL compliant databases like MySQL or MariaDB
? PostgreSQL????????PostgreSQL database
移動(dòng)上下箭頭鍵盤按鍵,選擇PostgreSQL后,再次回車確認(rè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? (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
提示是否在選擇的數(shù)據(jù)庫中包含已存在數(shù)據(jù)。因?yàn)槭且粋€(gè)新庫,所以默認(rèn)選擇No,然后回車確認(rè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 (localhost)
輸入數(shù)據(jù)庫的主機(jī)地址(注意,因?yàn)閜risma會(huì)運(yùn)行在docker中,所以,這兒需要配置宿主機(jī)IP,在類Linux系統(tǒng)上可以通過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)
回車確認(rèn)使用默認(rèn)的Postgres數(shù)據(jù)庫的端口。
? 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宿主機(jī)IP)
? Enter database port 5432
? Enter database user
輸入數(shù)據(jù)庫的用戶名后回車確認(rè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宿主機(jī)IP)
? Enter database port 5432
? Enter database user postgres
? Enter database password
輸入數(shù)據(jù)庫用戶對(duì)應(yīng)的密碼后回車確認(rè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宿主機(jī)IP)
? Enter database port 5432
? Enter database user postgres
? Enter database password study
? Enter database name
輸入使用的數(shù)據(jù)庫名稱后回車。
? 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宿主機(jī)IP)
? Enter database port 5432
? Enter database user postgres
? Enter database password study
? Enter database name study
? Use SSL? (Y/n)
提示是否使用安全的網(wǎng)絡(luò)協(xié)議,這里選擇不使用(輸入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宿主機(jī)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
這里選擇產(chǎn)生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宿主機(jī)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項(xiàng)目創(chuàng)建并初始化完畢。
接下來按昭Next steps下面的步驟提示執(zhí)行后續(xù)操作。
通過以下命令切換當(dāng)前目錄至剛創(chuàng)建的項(xiàng)目目錄(prisma-study)中。
cd prisma-study/
通過docker編排命令在docker中運(yùn)行prisma服務(wù)器。
docker-compose up -d
執(zhí)行后命令行提示如下:
Creating prisma-study_prisma_1 … done
此時(shí)服務(wù)運(yùn)行成功。
通過以下命令部署prisma服務(wù)。
$ 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界面。
運(yùn)行如下命令可以看到演練數(shù)據(jù):
$ prisma playground
Serving playground at http://localhost:3000/playground
此時(shí)會(huì)自動(dòng)打開瀏覽器,并顯示如下界面:
關(guān)于數(shù)據(jù)庫無法連接的問題:
https://blog.csdn.net/liuchunming033/article/details/44810899
官方參考資料地址:
https://www.prisma.io/docs/quickstart/