Prisma ClientSetup

Generating the Client (Go)

Overview

The Prisma client is auto-generated using the prisma generate command of the Prisma CLI. One Prisma client connects to exactly one Prisma service.

prisma generate reads the information that's specified under the generate root property in your service's prisma.yml.

Configuring generate in prisma.yml

The generate root property accepts a list of objects. Each object has two fields:

  • generator: The programming language in which the Prisma client should be generated. Here are the accepted values:

    • typescript-client
    • javascript-client
    • flow-client
    • go-client
  • output: The path and name of the file in which the Prisma client should be stored.

Example

As an example, consider the following prisma.yml:

datamodel: datamodel.prisma
endpoint: http://localhost:4466
secret: mysecret42

generate:
  - generator: go-client
    output: ./prisma-client/

Running prisma generate in the directory where that prisma.yml is located generates a Prisma client in Go and stores it in a directory called prisma-client.

The generated Prisma client is configured to target the endpoint specified in prisma.yml. It also knows the secret so that it can authenticate against your Prisma service when you're using it in your application.

Using environment variables in prisma.yml

Note that you can also reference environment variables in prisma.yml by using the env:-prefix and enclosing them with ${}. For example, if you have an environment variable set that's called MY_SECRET:

datamodel: datamodel.prisma
endpoint: http://localhost:4466
secret: ${env:MY_SECRET}

generate:
  - generator: go-client
    output: ./prisma-client/

You can find more info about using environment variables here.

Generated files

The Go client is generated in a single file called prisma.go which will be located in the directory specified as the output in your prisma.yml.