/prisma-client-cli

Generates a CLI from your Prisma schema that allows you to query, seed, and export data

Primary LanguageTypeScriptMIT LicenseMIT

Prisma Client CLI

npm CI

A Prisma generator that generates a command-line interface from your Prisma schema using oclif. Use the CLI to run queries, seed records, or export your query results to a CSV file.

View the example project to see it in action.

Getting Started

  1. Install the generator and oclif:

    npm install prisma-client-cli @oclif/core --save-dev
    
  2. Add the generator to your Prisma schema:

    generator cli {
      provider = "prisma-client-cli"
    }
  3. Run Prisma's generate command to generate the CLI in the ./prisma/cli/ directory:

    npx prisma generate
    
  4. Add the following configuration for oclif to your package.json:

    "oclif": {
      "commands": "./prisma/cli/commands",
      "topicSeparator": " "
    }

    For more information about oclif's configuration, refer to their documentation.

CLI Usage

Run ./prisma/cli/bin/run --help to view available commands for your generated CLI.

Exporting to CSV

Use the --_csv flag to output the query results as comma-separated values.

Disable Generator

You can prevent the CLI from being generated by setting the following environment variable:

PRISMA_CLIENT_CLI=false