/prisma2-grpc-example

gRPC Server Example with Prisma2

Primary LanguageTypeScriptApache License 2.0Apache-2.0

gRPC Server Example with Prisma2

This example shows how to implement a gRPC API with TypeScript using Prisma2.

How to use

1. Clone repository & install dependencies

Clone the repository Install Node dependencies:

cd prisma2-grpc-test
npm install

2. Install the Prisma 2 CLI

To run the example, you need the Prisma 2 CLI:

npm install -g prisma2

3. Set up database

First, create a dev.db file in the prisma folder.

touch dev.db

Set up your database, run:

prisma2 lift save --name 'init'
prisma2 lift up

You can now use the SQLite Browser to view and edit your data in the ./prisma/dev.db file that was created when you ran prisma2 lift up.

4. Generate Photon (type-safe database client)

Run the following command to generate Photon JS:

prisma2 generate

Now you can seed your database using the seed script from package.json:

npm run seed

5. Start the gRPC server

npm run start

The server is now running on 0.0.0.0:50051.

6. Using the gRPC API

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 farmers.ts script sends the Farmers operation). Each script can be invoked by running the corresponding NPM script defined in package.json, e.g. npm run farmers.