This example shows how to implement a gRPC API with TypeScript and Prisma Client. It is based on a SQLite database, you can find the database file with some dummy data at ./prisma/dev.db
.
Download this example:
curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/typescript/grpc
Install npm dependencies:
cd grpc
npm install
Alternative: Clone the entire repo
Clone this repository:
git clone [email protected]:prisma/prisma-examples.git --depth=1
Install npm dependencies:
cd prisma-examples/typescript/grpc
npm install
Run the following command to create your SQLite database file. This also creates the User
and Post
tables that are defined in prisma/schema.prisma
:
npx prisma migrate dev --name init
When npx prisma migrate dev
is executed against a newly created database, seeding is also triggered. The seed file in prisma/seed.ts
will be executed and your database will be populated with the sample data.
Execute this command to start the gRPC server:
npm run dev
The server is now running on 0.0.0.0:50051
.
To use the gRPC API, you need a gRPC client. We provide several client scripts inside the ./client
directory. Each script is named according to the operation it performs against the gRPC API (e.g. the feed.js
script sends the Feed
operation). Each script can be invoked by running the corresponding NPM script defined in package.json
, e.g. npm run feed
.
In case you prefer a GUI client, we recommend BloomRPC:
Please refer _setup/readme.md