Share your Prisma Client across projects

Creating a new Prisma project

  • First create a new typescript project and install the prisma package. Your dependencies should look similar to the ones below:
  • Next create or copy from one of you existing projects the prisma folder and the schema.prisma file. The only bit we care about from the schema.prisma file is the set of code which tells Prisma what we’re using as a datasource — in our case, a PostgreSQL db.
  • Now we can add the following scripts to our package.json file which allow us to generate the schema.prisma by introspecting our db and to update the prisma client:
  • Create a src directory and then create both index.ts and index.d.ts files inside it. We’ll need to create and export our context in our index.ts as below:
  • Last step is to create a postinstall script that builds your ts code and generates the prisma client after you install the newly create package:

Publishing your package

Press on Releases and create a new Draft release




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

React Multi Step form with Formik

How to handle MySQL database transactions with NodeJS

An Introduction to NodeJS and fs.createReadStream

A comparison of React and Cycle

Understanding Recursion

How to Embed Single File From a Multiple Files Gist on Medium

Pen and Paper

Synchronize the Asynchronous Calls in Javascript Generator Function

Article about Component Life Cycle  Mounting , Unmounting, Updating

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Isidoro Ferreiro

Isidoro Ferreiro

More from Medium

Adventures in Streaming to Http Requests in NodeJS

NoSQL Databases

To gain a clear understanding of NoSQL and MongoDB.

Merkel tree