プロジェクトセットアップ
必要なもの
作業ディレクトリ作成
mkdir hello-prisma
cd hello-prisma
プロジェクトセットアップ
yarn init -y
yarn add --dev prisma @prisma/client typescript ts-node @types/node
TypeScript設定ファイル生成
以下の内容のファイルを作成します。
tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"strict": true,
"lib": ["esnext"],
"esModuleInterop": true
}
}
ヒアドキュメントを利用して、作成しましょう。
cat <<EOF > tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"strict": true,
"lib": ["esnext"],
"esModuleInterop": true
}
}
EOF
Prismaの初期プロジェクト設定
npx
コマンドを利用して、セットアップしていきます。
本チュートリアルでは、基本npx
を用います。
npx prisma init
データベース接続設定修正
.env
ファイルを以下のとおり、編集する
次のステップでローカルPCにpostgresをセットアップします。
.env
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=postgres"