@a_team/prisma
v3.2.0-win
Published
- This package contains a shared Prisma schema, organized into [multiple files](https://www.prisma.io/blog/organize-your-prisma-schema-with-multi-file-support), to be used across multiple projects. - By centralizing the schema definitions, we ensure consi
Downloads
3,576
Readme
A.Team prisma library
- This package contains a shared Prisma schema, organized into multiple files, to be used across multiple projects.
- By centralizing the schema definitions, we ensure consistency and reduce duplication of effort:
- Consistency: We are targeting the same MongoDB database. If we use different schema definition files, there's a risk of having inconsistent model definitions, which could lead to conflicts and data overrides.
- Efficiency: A single schema definition can reduce redundant work. Currently, the schema file has over 300 lines, and this could easily grow to 1000+ lines as we onboard more collections. By working collaboratively on a single schema definition, we can streamline our efforts and improve the overall quality.
Installation
- To install this package, add the following optional dependencies (where
X.Y.Z
represents the version):
"optionalDependencies": {
"@a_team/prisma-win": "npm:@a_team/[email protected]",
"@a_team/prisma-macos": "npm:@a_team/[email protected]",
"@a_team/prisma-linux": "npm:@a_team/[email protected]"
}
- Add the following script as
postinstall
& change per need in your service:
const fs = require('fs');
const path = require('path');
const getPlatformPackage = () => {
switch (process.platform) {
case 'darwin':
return '@a_team/prisma-macos';
case 'win32':
return '@a_team/prisma-win';
default:
return '@a_team/prisma-linux';
}
};
const platformPackage = getPlatformPackage();
const nodeModulesPath = path.join(__dirname, '..', 'node_modules');
const sourcePath = path.join(nodeModulesPath, platformPackage);
const targetPath = path.join(nodeModulesPath, '@a_team/prisma');
if (fs.existsSync(sourcePath)) {
if (fs.existsSync(targetPath)) {
fs.rmSync(targetPath, { recursive: true, force: true });
}
fs.renameSync(sourcePath, targetPath);
console.log(`Renamed ${platformPackage} to @a_team/prisma`);
} else {
console.error(`Platform-specific package ${platformPackage} not found`);
process.exit(1);
}
- The script above will link the required OS dependency as the main one.
Usage
- To use the library:
import { ATeamPrismaClient } from '@a_team/prisma';
export class DbClient extends ATeamPrismaClient {
constructor(connectionUrl: string) {
super(connectionUrl);
}
async onModuleInit() {
await this.connect();
}
async onModuleDestroy() {
await this.disconnect();
}
}
Playground
- The playground is a dedicated space where you can test and experiment with the prisma client and schema.
- It contains various scripts that demonstrate how to interact with your database models.
- Before running any playground scripts, make sure to set up your environment variables. First, copy the
.env.sample
file to.env
:
cp .env.sample .env
- Then, fill in the required environment variables in the
.env
file. - To run a playground script, use the following command:
npx ts-node playground/missionSpec.ts
Publishing a new version
Pull the latest changes on the
main
branch and push the following tag to the repository:git tag v<major>.<minor>.<patch> # matches v0.0.1 git push origin tag v<major>.<minor>.<patch> # runs the publishing process
This tag creates the new package versions needed and pushes them towards the npm repository,
A
release
on thegithub
repository is generated,A slack notification is sent to the required channel with the release changes.