@telaclaims-tech/prisma-package
v1.0.142
Published
prisma-package simplifies database management across microservices at Telaclaims by maintaining configurations in one place and integrating with Prisma for efficient and secure SQL database access.
Keywords
Readme
Prisma-package
Prisma-package is an npm package that simplifies database management across different microservices at Telaclaims. With Prisma-package, you can maintain database configurations and connections in one place and easily consume them in the rest of your services. Its integration with Prisma makes it ideal for efficiently and securely accessing and manipulating SQL databases.
Installation
You can install prisma-package using npm:
npm install @telaclaims-tech/prisma-packageSteps to generate a new package version
Right now the prisma package is just a mirror of the database generated models from the sequelize models migrated to the database. To maintain syncronization between the models and the prisma package we need to proceed with some specified steps:
- Pull all the new changes from an updated database using
npm run db:pull. This database must have the completed process related to the latest migrations run to pull the new schemas and structures - Make sure and check that
prisma/schema.prismahas all the changes you need (you can use the diff tool before make the commit) - Push the changes to the repository making a commit to your branch or to master.
- Run the script
npm run publish-pkgto make the needed changes to the version and publish the package. - After running the script a new package version should be published. You can check it on npm or try pull the new version on your service/project
Usage
To use Prisma-package in your project, you can import it as follows:
import Prisma from "@telaclaims-tech/prisma-package";
const { prisma } = await Prisma.createContext();Once you have imported the package and created a context, you can use its functions to manage your database configurations and connections.
Example
Here is an example of how you can use prisma-package to manage your database configurations and connections:
const { prisma } = await Prisma.createContext();
const users = await prisma.user.findMany();In this example, we create a context using the createContext function and then use the prisma object to query the database and retrieve a list of users.
Please note that you will need to have a .env file with the DATABASE_URL connection variable in order to use prisma-package.
Please note that it is important to keep your Prisma schema, models, and migrations up-to-date with your database. You can use the prisma migrate dev command to generate and apply migrations automatically based on changes to your schema. You can also use the prisma generate command to generate updated Prisma client code based on changes to your schema.
Scripts
Prisma-package provides two scripts that can be used to manage your Prisma schema and models:
db:introspect
The db:introspect script allows you to pull the latest schema from your database and update your Prisma schema accordingly. This is useful when you have made changes to your database schema that are not reflected in your Prisma schema.
To run the db:introspect script, simply run the following command:
npm run db:introspectThis will pull the latest schema from your database and update your Prisma schema accordingly.
db:generate
The db:generate script allows you to generate the latest Prisma models based on your Prisma schema. This is useful when you have made changes to your Prisma schema that require updated models.
To run the db:generate script, simply run the following command:
npm run db:generateThis will generate the latest Prisma models based on your Prisma schema.
License
Prisma-package is licensed under the MIT License.
