Giter Site home page Giter Site logo

prisma-proxy's Introduction

About

Got frustrated with all the try catch, try catch, try catch, well you get the idea.

Limitations

  • Although limitations, they are only limitations for the proxy implementation. \
    • prisma proxy respect the original prisma client and makes no direct modifications to it.
    • So you can still use the prisma client as is alongside the proxy!
  • Only works for callable methods e.g. prisma.table.create(), prisma.table.findMany() (but not prisma.table.fields)
  • Additional .lastError property, so if you happen to have a table/collection with this name, it will not longer work on the proxy client.
  • Not soo much a limitation as it's kinda the point of this package, but errors are no longer thrown (so don't try catching em, or you'll be catching thin air).
    • After you call a method e.g. prisma.users.findMany() you can check prisma.lastError to see if there was an error
    • If there was no error prisma.lastError will be null
    • when you make another call prisma.lastError will be immediately overwritten, so you must always check for errors immediately after the original call

Normal Usage (without proxy)

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

let posts, postsError;
try {
    posts = await prisma.posts.findMany();
}
catch(error){
    //Deal with error here
    postsError = error;
}

if(postsError){
    //Or deal with error here
}

Proxy Usage

import { PrismaClient } from '@prisma/client';
import { proxyPrisma, type ProxyPrisma } from 'prisma-proxy';

// The type in case you need it
type ProxyPrismaClient = ProxyPrisma<PrismaClient>;

const prismaOG: PrismaClient = new PrismaClient();
const prisma: ProxyPrismaClient = proxyPrisma(prismaOG);

// Use prisma proxy as you would regularly for callable methods
const posts = await prisma.posts.findMany();

if(prisma.lastError){
    //Deal with error
}

prisma-proxy's People

Contributors

yusaf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.