npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prisma-repo

v0.3.12

Published

Generating repository pattern using Prisma ORM faster and easier

Downloads

1,638

Readme

Prisma Repo

:warning: The repo is move to another repo :warning:

Starting from version 0.3.12 the repo is no longer maintained. This package is move to another repo (@krsbx/prisma-repo) with (hopefully) better development flow. If you like to maintain this repo go ahead make a fork of this repo and add things that you like in your fork.

Generating repository pattern for Prisma ORM faster and easier


:warning: Change to Class Base From Function Base :warning:

Starting from version 0.3.0 instead of extending the class by creating the instance for each models, we decide to create an abstract class that use a lot of static functions/method so it can be use without creating the instance.

What is this?

A package that will make your life easier for using Repository Pattern while using Prisma ORM

Why make this?

I like to use repository pattern in Sequelize, but when I saw Prisma support TypeScript I fell in love with it. Unfortunately, it's hard to use a repository pattern in prisma and to fix those issue this package exists.

Should I use this?

Depends on what you need, if you doesnt care to have a lot of hassle to code almost a same things for all your services, then you dont need this package. But, if you are someone who doesn't want to struggle to build your own way to use the repository pattern in Prisma or if you just as lazy as me to generate the same repository for each models, then this package is for you.

How to use

  1. Install prisma-repo as dev dependencies
npm i -D prisma-repo
  1. Generate all the repositories
npx prisma-repo --repositories

Flags

  • Generate all repositories
npx prisma-repo --repositories
  • Generate model structures files
npx prisma-repo --model-structures
  • Generate the base repository only
npx prisma-repo --base-repository
  • Generate specific model repository
npx prisma-repo --modelname <model-name>

Config files

Accepted File Name/Formats

repository.setting.json

repository.setting.js

repository.setting.ts

Config files settings (JavaScript)

// Language: javascript
// Path: repository.setting.js

const config = {
  extendExpress: false, // default false
  overwrite: false, // default false
  repositoryPath: 'src/repository', // default 'src/repository'
  typesPath: 'src/types', // default 'src/types'
  prismaLogger: true, // default false
};

module.exports = config;

Config files settings (TypeScript)

// Language: typescript
// Path: repository.setting.ts

import { PrismaRepoConfig } from 'prisma-repo';

const config: PrismaRepoConfig = {
  extendExpress: false, // default false
  overwrite: false, // default false
  repositoryPath: 'src/repository', // default 'src/repository'
  typesPath: 'src/types', // default 'src/types'
  prismaLogger: true, // default false
};

export default config;

Config files settings (JSON)

// Path: repository.setting.json

{
  "extendExpress": false, // default false
  "overwrite": false, // default false
  "repositoryPath": "src/repository", // default 'src/repository'
  "typesPath": "src/types", // default 'src/types'
  "prismaLogger": true // default false
}

Problem with extendExpress options

When this enabled, it will extends request object in express. Problem that will happen if this was triggered is that it will conflict with other modules, if it was reserved words like file and files which conflicting with multer. Other thing to consider as well is that if you use include options in prisma and it will conflict with the types that we extend with extendExpress options.

Possible values

Will extends express Request interface so it can be extends with the models name like req.user or req.users

extendExpress: boolean | {
  include: string[]; // model types to Include
  exclude: string[]; // model types to Exclued
}

Determnie whether prisma-repo should overwrite the existed files or not

overwrite: boolean | {
  repository: boolean;
  baseRepository: boolean;
}

Determine where to put the repository files. By default it will be in src/repository

repositoryPath: string;

Determine where to put the extended express definition files. By default it will be in src/types

typesPath: string;

Will enable logging in prisma instance in models.ts. By default it will not show any logger (false)

prismaLogger: boolean | {
  query: boolean;
  info: boolean;
  warn: boolean;
  error: boolean;
} | ('query' | 'info' | 'warn' | 'error')[];