Notes: Uses docker
-
Install prisma
npm install prisma
-
Create service directory (The name will be passed by command line argument)
mkdir hello-world
cd hello-world
-
Use templates of docker-compose TODO: Change to be able to use PostgreSQL or MongoDB.
cp ../docker-compose.yml .
-
Launch
docker-compose up -d
-
Configure prisma API
npx prisma init --endpoint http://localhost:4466
-
Deploy prisma datamodel
prisma deploy
-
Generate prisma client
Append the following lines to the end of your prisma.yml
generate:
- generator: javascript-client
output: ./generated/prisma-client/
- Generate
prisma generate
9 Prepare Node Application
touch index.js
npm init -y
npm install --save prisma-client-lib
I think below is not appropriate
const { prisma } = require('./generated/prisma-client')
// A `main` function so that we can use async/await
async function main() {
// Create a new user called `Alice`
const newUser = await prisma.createUser({ name: 'Alice' })
console.log(`Created new user: ${newUser.name} (ID: ${newUser.id})`)
// Read all users from the database and print them to the console
const allUsers = await prisma.users()
console.log(allUsers)
}
main().catch(e => console.error(e))
- Install expo
npm install expo-cli
- Init Expo (The name will be passed by command line argument)
npx expo init my-new-project
cd my-new-project
- Copy template js files
cp ../index.js .
- Start Expo
npx expo start
https://nexus.js.org/docs/database-access-with-prisma