https://www.prisma.io/ logo
Join Slack
Powered by
# orm-help
  • r

    Richard Scarrott

    10/03/2022, 8:58 AM
    Hi there, has there been any past discussion about implementing request-level dataloader (caching + batching) in prisma client e.g.
    Copy code
    prisma.user.findUnique('usr_123'); // DB query
    
    // Somewhere else (potentially in a different tick)
    prisma.user.findUnique('usr_123'); // Another DB query :(
    ✅ 1
    n
    • 2
    • 3
  • ł

    Łukasz Usarz

    10/03/2022, 9:44 AM
    Hi there, I wonder if manually editing migrations generated by Prisma is considered as bad practice or can cause any problems
    ✅ 1
    n
    • 2
    • 2
  • l

    Lloyd Richards

    10/03/2022, 2:55 PM
    greetings! I have an issue that i managed to solve but not in the most elegant way. If someone has the 'correct' way to implement two prisma clients on a serverless functions, it would be amazing: The Problem: I have a GraphQL server that takes data from two MySQL servers (Prime and Legacy) and wanted to use Prisma as the ORM for both. The Issue: While i was able to get a second Prisma Client working by creating a new
    schema.prisma
    and
    DATABASE_URL
    and setting up a second
    @internal/prisma/client
    on my graphQL context. The issue came when i tried to deploy this to Cloud Functions as each time i would get an error saying that
    @internal/prisma/client
    was not found in the node_module. i tried several possible solutions like creating an alias for the legacy prisma client or for both but it never worked. The _temp Solution: In the end i figured i could just build the second prisma client outside of the node_module and commit it with the rest of my code. The result was something like this: Structure
    Copy code
    .
    ├── functions
    │   ├── @internal          # This is the Legacy @PrismaClient
    │   ├── node_module        # (.gitignore) In here is the default @PrismaClient
    │   ├── prisma
    │   │   └── schema.prisma  # The Prime Schema for CloudSQL
    │   ├── prisma_legacy
    │   │   └── schema.prisma  # The Legacy Schema for MySQL Server
    │   ├── src                # Rest of the functions and graphql code first
    │   ├── package.json
    │   └── ...
    └── ...
    Legacy schema.prisma
    Copy code
    generator client {
      provider      = "prisma-client-js"
      output        = "../@internal/prisma/client"
      binaryTargets = ["debian-openssl-1.1.x"]
    }
    
    datasource db {
      provider = "mysql"
      url      = env("LEGACY_DATABASE_URL")
    }
    
    ...        # Rest of the schema
    If someone knows how to correctly alias the prisma client do i can have something like:
    Copy code
    "dependencies": {
       "@prime/prisma/client" : "npm:@prisma/client@4.4.0",
       "@legacy/prisma/client" : "npm:@prisma/client@4.4.0",
       ...
    }
    👀 1
    a
    • 2
    • 5
  • l

    Lars Ivar Igesund

    10/03/2022, 7:42 PM
    I am testing prisma on a minor support application. As I want to use this as a learning experience towards upgrading the main application from Prisma 1, I want to use a mongodb also for this support application. Since it will have minimal users and traffic, I want to try out/use the new MongoDB Atlas serverless offering. The prisma docs state that any mongodb connected to requires replica sets, but the connection string given from the atlas serverless instance does not announce replica sets (but their support assistant claims that the offering has such). I assume this is due to how the serverless version operates (presumably there is some proxying towards the actual db instances), so I guess my question here is - What is the actual requirements for the Prisma mongo connector in terms of those mentioned replica sets?
    ✅ 1
    a
    • 2
    • 2
  • s

    Sebastian Gug

    10/03/2022, 8:57 PM
    if I mark a property, for example, email as String? -- isn't that optional? The resulting TS class when imported from the client does not have email as an optional property then
    ✅ 1
  • s

    Sebastian Gug

    10/03/2022, 8:58 PM
    ah
    export class UserModel implements Prisma.UserCreateInput {
    this works
  • v

    ven v

    10/03/2022, 9:08 PM
    \
    n
    • 2
    • 1
  • t

    Tomasz Koszykowski

    10/03/2022, 10:36 PM
    Hello 🙂 I am using https://github.com/tc39/proposal-temporal (https://www.npmjs.com/package/@js-temporal/polyfill) polyfil to deal with dates, unfortunately Prisma forces me to use Dates. As Temporal is still in Stage 3 I don’t expect that it should be supported now, but maybe you have idea how to do it better than casting Dates to Temporal (every time I read from the db) and Temporal to Dates (everytime I write to the db). Possible solutions: 1. Support Temporal 🙂 2. Allow strings as dates (saw few issues about it like https://github.com/prisma/prisma/issues/4328 -> design decision) 3. Custom field mapper ps: I really recommend Temporal 🙂
    ✅ 1
    🙌 1
    💯 1
    r
    • 2
    • 1
  • s

    shawng

    10/03/2022, 10:44 PM
    Are there any repos/examples in the wild that uses Prisma + NestJS with a domain model layer? We are looking for a better way to dedupe our business logic, hopefully something other than individual functions like:
    Copy code
    checkIfUserIsActive(prisma_user){
      return prisma_user.is_active;
    }
    Thanks in advance!
    👀 1
    n
    t
    v
    • 4
    • 7
  • b

    Brothak

    10/04/2022, 4:56 AM
    How do I set statement timeout for prisma? Execute raw doesn’t support multiple statements nor does it support query timeout https://github.com/prisma/prisma/issues/12419
    ✅ 1
    n
    • 2
    • 9
  • p

    Perez cato Cato perez

    10/04/2022, 5:46 AM
    Hello Please how do I check if a field is empty of null using Prisma
    ✅ 1
    j
    • 2
    • 17
  • f

    Francis Shonubi

    10/04/2022, 8:16 AM
    Hi everyone 👋, I am using prisma with docker for local development and I wanted to know your workflow for development. I read in the prisma docs that
    prisma db push
    should be used for prototyping so you can easily change things on the go. I ran that and the local prisma client got updated but I am having
    TypeError: Cannot read properties of undefined
    in my docker container, I am not having an errors in my code editor and I am getting auto completion. I tried building the container again, still the same error. I tried
    rm -rf node_modules && npm i && docker container prune
    then
    docker compose up --build
    , still the same TypeError. I not very good at docker so I can't really tell what the problem is.
    👀 1
    j
    v
    • 3
    • 41
  • b

    Ben Liger

    10/04/2022, 9:20 AM
    Hi there, is there a way to query connections that have not yet been added as a relation to a type? ie if I wanted to query a list
    User
    s that have not yet been added to the
    friendList
    of a particular user?
    Copy code
    model User {
      friendList       User[]
    }
    
    // I would like to get a list of users where user A has not yet connected them to their friendList
    ✅ 1
    n
    • 2
    • 8
  • b

    Barnaby

    10/04/2022, 10:49 AM
    handled it manually, but seems like a minor bug in Prisma's SQL code generator
    n
    v
    • 3
    • 3
  • s

    Sebastian Gug

    10/04/2022, 11:24 AM
    So I have my session model
    Copy code
    model Session {
      id String @id @default(uuid())
    
      user      User     @relation(fields: [userId], references: [id])
      userId    String
    But then the create input expects to have a User provided? Isn't that data that will be joined on the user? what's the correct way of defining this? The type error in question:
    Copy code
    Class 'SessionModel' incorrectly implements interface 'SessionCreateInput'.
      Property 'user' is missing in type 'SessionModel' but required in type 'SessionCreateInput'.
    👀 1
    j
    r
    v
    • 4
    • 51
  • j

    Joey

    10/04/2022, 4:26 PM
    is there any way to select a field, and force it to return with a specific value? for two of my fields i want it to return 0 no matter what:
    Copy code
    select: {
                  members: true,
                  organizationInvites: 0,
                  organizationRequests:0
    },
    any way to achieve that without just setting the values manually after the query?
    👀 1
    ✅ 1
    r
    n
    • 3
    • 4
  • b

    Boo

    10/04/2022, 5:42 PM
    Whats a good way to ignore an entire relation instead of doing something like this?
    Copy code
    NOT: {
              posts: {
                some: {
                  postId: {
                    gte: 0,
                  },
                },
              },
            },
    👀 1
    a
    v
    • 3
    • 10
  • d

    David Hancu

    10/04/2022, 6:16 PM
    Full-text search with fuzzy matching with Prisma Util is done! The middleware is quite massive, but you just have to import it then forget about it, it will be generated automatically when you create your schema.
    🚀 4
  • j

    Joey

    10/04/2022, 6:43 PM
    typescript question, what is the actual type for a prisma model.update’s data object? I’m trying to create a utility function for it where I can just pass in an id and the update data.
    const updateModel = (id: string, data: Partial<Model>) =>db.model.update({ where: { id }, data });
    When hovering the data object it says the type is
    Partial<Model>
    but this throws a type error when trying to include a connect/disconnect on the relationship
    ✅ 1
    n
    • 2
    • 2
  • s

    Sebastian Gug

    10/04/2022, 6:43 PM
    what is
    UserCreateNestedOneWithoutSessionsInput'
    -- that prisma sets for the resulting session model in this scenario:
    Copy code
    model Session {
      id        String    @id @default(uuid())
      user      User      @relation(fields: [userId], references: [id])
      userId    String
      createdAt DateTime? @default(now())
      updatedAt DateTime? @default(now())
    }
    👀 1
    v
    a
    • 3
    • 3
  • s

    Sebastian Gug

    10/04/2022, 7:35 PM
    https://stackoverflow.com/questions/73952832/prisma-client-generated-type-for-create-input-has-weird-type-requirement-for-rel --- made an SO thread where I explained a lot better what I mean
    n
    • 2
    • 2
  • k

    Kevin Lanthier

    10/04/2022, 8:11 PM
    How can I get my hands on this ?
    d
    n
    • 3
    • 3
  • a

    András Bácsai

    10/04/2022, 9:03 PM
    👋 Can someone help me about investigating a super high memory usage (500MB-700MB) of Prisma Engine in production? Without Prisma, it is 100MB.
    ✅ 1
    n
    • 2
    • 5
  • j

    Jonathan Marbutt

    10/05/2022, 3:04 AM
    How are most people implementing row level security? with prisma and postgres and nextjs
    💬 1
    n
    • 2
    • 5
  • y

    Yunbo

    10/05/2022, 4:35 AM
    relation
    connect
    when do i use it? let's say i have a model
    Copy code
    Profile
    {
      id     number;
      name   string;
      posts  Post[];
    }
    
    Post
    {
      id          number;
      message     string;
      profileId   number;
      profile     Profile @relation(fields: [profileId], references: [id])
    }
    and in code,
    Copy code
    prisma.post.create({
      data: {
        message: 'hello',
        profileId: 1,
      }
    })
    it's not exact example but when i'm coding, sometimes it works, sometimes i had to use
    connect
    (in other scenarios)
    Copy code
    prisma.post.create({
      data: {
        message: 'hello',
        profile: {
          connect: {
            id: 1,
          }
        }
      }
    })
    i can not seem to find a documentation or resource about
    connect
    could anyone tell me when to use
    connect
    ?
    ✅ 1
    j
    n
    • 3
    • 8
  • j

    Jarupong

    10/05/2022, 6:44 AM
    your user does not have permission to migration?
    v
    • 2
    • 3
  • m

    Marten Tamm

    10/05/2022, 8:33 AM
    Hi everyone! How many of you are using Prisma data proxy in a production environment? Have you seen some significant improvements in your app's performance?
    ✅ 1
    n
    • 2
    • 4
  • d

    David Hancu

    10/05/2022, 9:18 AM
    Hi everyone! Do you have any features that you're dying to see in Prisma but are still not implemented or on the roadmap? I'd love to hear your suggestions, since I need feature ideas for Prisma Util. It can be of any nature, including schema changes, client features or additions to the query engine. These are the current ones so far: https://github.com/prisma/prisma/issues/15625 (Proposal will be created later today) https://github.com/prisma/prisma/issues/15466 (Proposal will be created later today) https://github.com/prisma/prisma/issues/15390 (Proposal will be created either today or tomorrow) https://github.com/prisma/prisma/issues/15384 (Proposal will be created later today) https://github.com/prisma/prisma/issues/15381 (Proposal will be created after more information is received) https://github.com/prisma/prisma/issues/15188 (No proposal needed) These are not yet planned, but I'm still thinking of a solution: https://github.com/prisma/prisma/issues/15269 https://github.com/prisma/prisma/issues/15236 https://github.com/prisma/prisma/issues/15113
    prisma rainbow 2
    👀 2
  • j

    Jose Rangel

    10/05/2022, 9:40 AM
    Hello Prisma Community, I'm currently writing some basic unit tests with Prisma, following the documentation on Prisma Unit Testing and using the Singleton approach. But it seems that my unit test is actually connecting to the real database and I can't write proper unit tests like this. Could you help me with this? I'm using Prisma within Next.js and I have a connection to a Postgres DB Here is a simplified version of my code (sorry for the long post but I wanted to add any code that might be needed)
    Copy code
    // API handler 
    import { NextApiRequest, NextApiResponse } from 'next';
    import { PrismaClient, Product } from '../../../../prisma/.generated/client';
    
    const prismaClient = new PrismaClient();
    
    const handler = async (req: NextApiRequest, res: NextApiResponse) => {
      const {lang, country, slug} = req.query;
    
      try {
        const product: Product = await prismaClient.product.findFirst({
          where: {
            slug: slug,
            locale: lang,
            country: country,
          },
        });
    
        if (product) {
          res.status(200).json({ product });
        } else {
          res.status(404).json({
            status: 404,
            err: `Product not found`,
          });
        }
      } catch (err) {
        res.status(500).json({ err: err });
      } finally {
        await prismaClient.$disconnect();
      }
    };
    
    export default handler;
    Copy code
    // client.ts
    import { PrismaClient } from '@src/prisma/.generated/client'; // importing from the generated Prisma Client to have Intellisense functionality
    
    const prisma = new PrismaClient();
    export default prisma;
    Copy code
    // singleton.ts
    import { PrismaClient } from '@src/prisma/.generated/client';
    import { DeepMockProxy, mockDeep, mockReset } from 'jest-mock-extended';
    import prisma from './client';
    
    jest.mock('./client', () => ({
      __esModule: true,
      default: mockDeep<PrismaClient>(),
    }));
    
    beforeEach(() => {
      mockReset(prismaMock);
    });
    
    export const prismaMock = prisma as unknown as DeepMockProxy<PrismaClient>;
    Copy code
    // unit.spec.ts
    import { NextApiRequest, NextApiResponse } from 'next';
    import { Product } from '@src/prisma/.generated/client';
    import { createMocks, RequestMethod } from 'node-mocks-http';
    import handler from '../../../pages/api/[language-country]/p/[slug]';
    import { prismaMock } from './__mocks__/singleton';
    
    describe('/api/[language-country]/p/[slug] API Endpoint', () => {
      const lang = 'xx';
      const country = 'xx';
      const slug = 'slug';
    
      function mockRequestResponse(method: RequestMethod) {
        const { req, res }: { req: NextApiRequest; res: NextApiResponse } = createMocks({ method });
        req.query = { 'lang': `${lang}`, 'country': `${country}`, slug: `${slug}` };
        return { req, res };
      }
    
    
      it('should return 200 if product found by lang, country, slug', async () => {
        const mockData: Product = {
          // Product fields with mock data
        }
    
        const { req, res } = mockRequestResponse('GET');
    
        // Mocking findFirst, which is used in the handler() function
        prismaMock.product.findFirst.mockResolvedValue(mockData);
    
        // Run handler() function that calls the Prisma function findFirst()
        await handler(req, res);
    
        // Expectation would be that the statusCode is 200 because I'm saying in the code that the return of mocked findFirst() is the mocked Product
        // It returns 404 because with the params given in req, there are no products in the actual database
        expect(res.statusCode).toBe(200);
      });
    });
    ✅ 1
    n
    • 2
    • 2
  • l

    Lucian Buzzo

    10/05/2022, 10:34 AM
    Hello team! I’m currently building an audit logging feature that requires the user’s ID to be recorded alongside the model they updated. I though I could do this with prisma middleware, however it seems that I can’t pass in context to middleware. I see that there is discussion on this feature here https://github.com/prisma/prisma/issues/6882#issuecomment-1175427037 Does anyone know of a workaround for this issue? I’d considered wrapping the prisma client, but AFAICT this would mean reconnecting with
    prisma.$connect()
    on every request, which is not ideal.
    ✅ 1
    n
    • 2
    • 2
1...628629630...637Latest