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

    Jonathan Gotti

    05/12/2022, 1:44 PM
    Hi all, silly question or perhaps a feature request, but is there any way to avoid some generators when building for production ? We use some doc and dbml generators but we don't want them to run at build time.
    n
    • 2
    • 3
  • j

    Jonathan Selander

    05/12/2022, 1:47 PM
    i'm making a liveness endpoint for my prisma app - is there any way to determine if there is an open connection to my postgres db?
    n
    • 2
    • 1
  • c

    Chris Bitoy

    05/12/2022, 2:39 PM
    Good day @Nurul , I just got out of a meeting with my manager who corrected me about how I set up my
    PrismaClient
    . Although I didn’t quite agree because I have seen online people (including folks at Prisma) set it up the same way I did on multiple tutorial videos. I usually set it up like this in every single file that I needed to use Prisma:
    Copy code
    import { PrismaClient } from '@prisma/client';
    const prisma = new PrismaClient();
    However, he insisted that
    "the best practice is to create the prisma client once and import it - this way you're not recreating database connections if multiple files use prisma, etc"
    Can you advice on how best to set it up - still learning
    ✅ 1
    n
    • 2
    • 4
  • y

    Yaakov

    05/12/2022, 3:08 PM
    Is there any way to do a
    CROSS JOIN
    in Prisma?
    n
    • 2
    • 1
  • s

    shahrukh ahmed

    05/12/2022, 4:23 PM
    Hi. I am unable to clear the field completely and paste data in Prisma studio. Whenever I try to have a blank field to paste something, the value of "null" keeps overriding things. Happens only in JSON field.
    n
    • 2
    • 1
  • c

    Chris Bitoy

    05/12/2022, 9:13 PM
    So I am using Prisma as an ORM on my project to communicate with the database that I set up with AWS. Not happy with the AWS service I am now switching my database to
    <http://railway.app|railway.app>
    - which is working out well for me. However, I set up a Prisma
    data proxy
    on my app with the AWS connection string, and now that I don’t seem to want/ need it anymore I removed it but getting an error:
    Copy code
    error - InvalidDatasourceError: Datasource URL should use Prisma:// protocol. 
    If you are not using the Data Proxy, remove the data proxy from the preview features in your 
    schema and ensure that PRISMA_CLIENT_ENGINE_TYPE environment variable is not set to data proxy.
    Since getting the error I have removed
    previewFeatures = ["dataProxy"]
    from the
    prisma.schema
    file to make it look like this (back to what it was before configuring with dataproxy):
    Copy code
    generator client {
          provider = "prisma-client-js"
    }
    
    datasource db {
          provider = "postgresql"
          url= env("DATABASE_URL")
    }
    but the error still persists, how do I fix this?
    s
    n
    • 3
    • 3
  • t

    Tricked dev

    05/12/2022, 10:04 PM
    h
    n
    • 2
    • 1
  • k

    KIM SEI HOON

    05/13/2022, 4:00 AM
    Hello, I’m using Prisma ORM + hasura well. I want to store the seed data in the database in the empty state. I am using hasura + PostgreSQL. The way I want to proceed is as follows. DB Drop -> hasura Meta / Migration Apply -> Seed script run -> done How can I do DB Drop? Thank you, friends!
    r
    n
    • 3
    • 2
  • w

    Wiput Pootong

    05/13/2022, 10:22 AM
    Hi, I'm facing this issue randomly https://github.com/prisma/prisma/issues/13352 Version 3.13.0 on Node 14 AWS Lambda
    🙏 2
    n
    k
    • 3
    • 4
  • t

    Thom

    05/13/2022, 12:32 PM
    Hey, given I have two models defined in my schema with a many-to-many relationship (e.g. Property and Tag). How would I go about retrieving all Property’s that have at least all Tags with tag ids from an array?
    n
    • 2
    • 9
  • c

    Chris Bitoy

    05/13/2022, 1:03 PM
    Hi all, I just did a
    prisma.findMany
    and got this error:
    Copy code
    error - Error: Error serializing `.categories[0].createdAt` returned from `getServerSideProps` in "/".
    Reason: `object` ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types.
    How do I fix this?
    n
    • 2
    • 2
  • m

    Martin Pinnau

    05/13/2022, 1:05 PM
    Hi, I'm trying to get prisma 3.14 running with mongodb, nexus-plugin-prisma and graphql-yoga. The docs (https://www.prisma.io/docs/guides/upgrade-guides/upgrade-from-prisma-1/upgrading-prisma-binding-to-nexus) point to the old version of graphql-yoga, v2 is available via
    yarn add @graphql-yoga/node
    . If I migrate to graphql-yoga v2 I get the error that nexus is needed, but this breaks nexus-plugin-prisma. Could someone please help me ? 😉 This is my index.ts:
    Copy code
    require("dotenv").config();
    import { PrismaClient } from "@prisma/client";
    import * as path from "path";
    import { nexusSchemaPrisma } from "nexus-plugin-prisma/schema";
    import { makeSchema } from "@nexus/schema";
    import { createServer } from "@graphql-yoga/node";
    import { checkEnv } from "./src/utils";
    import { getClaims } from "./src/auth";
    import config from "./config";
    import { Query, Mutation } from "./src/types";
    
    checkEnv(config.requieredEnvs);
    
    const schema = makeSchema({
      types: [Query, Mutation],
    
      plugins: [
        nexusSchemaPrisma({
          experimentalCRUD: true,
        }),
      ],
    
      outputs: {
        schema: path.join(__dirname, "./src/generated/schema.graphql"),
        typegen: path.join(__dirname, "./src/generated/nexus.ts"),
      },
    });
    
    const serverOptions = {
      port: process.env.MAIL_PORT || 4000,
    };
    
    const server = createServer({
      schema,
      context: async (req) => {
        return {
          ...req,
          PrismaClient,
          claims: await getClaims(req),
          options: serverOptions,
        };
      },
    });
    
    server.start();
    console.log(`🚀  Server is running on <http://localhost>:${serverOptions.port}`);
    n
    • 2
    • 1
  • c

    Chris Bitoy

    05/13/2022, 4:00 PM
    Hello friends, I have small problem that you can help figure out. I have a
    User model
    with enum roles: 1. Admin 2. siteUser 3. Moderator If I want one
    siteUser
    to be able to select and add (multiple)
    Moderators
    as their favs, I could do a one-many relationship, but because they are both in the ‘User model’ it’s a little challenging - How can I implement this logic in my
    prisma.schema
    file?
    r
    c
    • 3
    • 3
  • j

    Jason Kleinberg

    05/13/2022, 7:11 PM
    Does anyone here do automated integration testing with Prisma? I’m having issues with overwhelming it with connections.
  • s

    Shahid Mawji

    05/13/2022, 7:21 PM
    Hi friends, is it possible to use an interactive transaction across modules? We have a NextJS that imports a single prisma client through our app, but found that when we call another helper (that also uses calls prisma) the call fails. Heres a rough example:
    Copy code
    import { prisma } from "../prisma";
    
    
    await prisma.$transaction(async (prisma) => {
        
        const booking = await prisma.bookingGroup.create(..)
        EmailService.sendEmail(booking) //If this function also has a prisma call, the transaction fails
    
    });
    I'm unsure if theres a best practice we should be following here (we're looking to keep our code concise but this seems to be a limitation of abstracting out logic if it involves the database)
  • j

    Jason Kleinberg

    05/13/2022, 7:53 PM
    @Shahid Mawji The problem is that inside the callback function, you need to use the transaction client that is passed into the callback.
  • j

    Jason Kleinberg

    05/13/2022, 7:54 PM
    You’ll have to have a way to use the same instance.
    ✅ 1
    s
    • 2
    • 1
  • a

    Angel C

    05/14/2022, 1:50 AM
    Hi - new user here. When deploying to prod I plan to have my deploy script call dotenv -e .env -e .env.production -- npx prisma migrate deploy But then I read I need to call resolve too? So does resolve update files that I have to check back in? Or does resolve update the migrations table? Because my production server does not have github upload rights for the migrations folder, I do a git clone on each prod push. Is it customary to call the resolve from the production server after deploy or do most people call resolve from the development branch? Do I have to wait for the deploy to happen or can I just do resolve locally after pushing migrations to prod? If there is a blog article or help file explaining the deploy process that would be very helpful.
    n
    • 2
    • 2
  • o

    Omar

    05/14/2022, 2:38 AM
    Hey, Any updates on this https://github.com/prisma/prisma/issues/5030 ? Because some packages are switching to ESM forcing everybody to switch to ESM too. So, right now we're stuck in the middle! I can't use older versions of course due to feature support and security vulnerabilities
    n
    • 2
    • 3
  • a

    Aaron Waller

    05/14/2022, 10:51 AM
    How can I return all posts from the user? but only the post array not the user itself.
    return prisma.user.findUnique({
    where: {
    id: args.id,
    },
    select: {
    posts: true
    },
    })
    The return type of the query is [Posts!] and I get this error
    Expected Iterable, but did not find one for field \"Query.testQuery\"
    o
    • 2
    • 2
  • c

    chrisdrackett

    05/14/2022, 8:07 PM
    just started a project with prisma cloud and was surprised it seems to list random peoples github accounts in the dropdown? https://cloud.drackett.com/W3oOxG
    v
    • 2
    • 1
  • c

    chrisdrackett

    05/14/2022, 8:07 PM
    feels like a bug/privacy issue…
  • s

    Slackbot

    05/15/2022, 2:37 PM
    This message was deleted.
    r
    • 2
    • 2
  • a

    Alexis

    05/15/2022, 2:40 PM
    Copy code
    const user = {
        id: 0102932023202,
        profile: {
            // This would be JSONB
        },
        inventory: [] // This is also JSONB
        badges: [] // This is also JSONB
    }
    n
    • 2
    • 1
  • o

    Oleg Komarov

    05/15/2022, 2:58 PM
    Is there a node prisma template repository that could be forked to submit reproducible issues?
    r
    • 2
    • 3
  • a

    Aaron Waller

    05/15/2022, 3:45 PM
    Can I connect an existing User record to an existing Post record? I want to have a simple favorites feature.
    Copy code
    model User {
      uid String @id @default(uuid())
      username String? @db.VarChar(24) @unique  
      favorites Post[]
    
    model Post {
      id             Int     @id @default(autoincrement())
      title           String  @db.VarChar(255)
      favoritedBy User[]
    }
    How does the mutation look like for adding a favorite to the user ?
    😕 1
    n
    • 2
    • 2
  • a

    Alisher BugDeveloper

    05/15/2022, 4:26 PM
    Hi everyone! I am trying to get my NestJS - Prisma - GraphQL application up and running, can anyone recommend some boilerplate for that ? or example github project ? Everything seems so complicated so far. Thank you in advance 🙂
    o
    • 2
    • 2
  • a

    Aaron Waller

    05/15/2022, 6:20 PM
    Is the
    Copy code
    connect
    keyword only used for explicit m-n relations or also implicit ones?
    m
    • 2
    • 2
  • m

    Motdde

    05/15/2022, 11:29 PM
    Hello Everyone, I am curious to know if there is a better way to construct a dynamic OrderWhereInput in the snippet below?
    Copy code
    async function handler(req: NextApiRequest, res: NextApiResponse<Response>) {
      await verifyUserToken(req, res)
    
      const automobileQuery = req.query.automobile.toString().split(',')
    
      if (automobileQuery.length > 2) {
        throw new CustomError(
          400,
          'automobile URL parameter expects a maximum of two values'
        )
      }
    
      let values: VehicleType[] | undefined
    
      if (automobileQuery.includes('BIKE')) {
        if (values === undefined) values = []
        values.push(VehicleType.BIKE)
      }
      if (automobileQuery.includes('CAR')) {
        if (values === undefined) values = []
        values.push(VehicleType.CAR)
      }
    
      let vehicleType = undefined
    
      let orders = await prisma.order.findMany({
        where: {
          vendorId: null,
          trackingStatus: 'READY_FOR_PICKUP',
          vehicleType: { in: values },
        },
      })
    
      return res.json({
        status: true,
        data: { orders },
      })
    }
    j
    • 2
    • 4
  • j

    Jacob Lloyd

    05/16/2022, 4:26 AM
    I’m having an URGENT issue.
1...573574575...637Latest