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

    Julian

    06/13/2022, 2:43 PM
    Hey, I am trying to do a raw query but it does not seem to work. If I run this:
    Copy code
    const amountMale = await this._prismaService.$queryRaw`
    	SELECT 
    		COUNT(profile) as count
    	FROM "public"."User" AS user, "public"."Profile" AS profile
    	WHERE user.profileId = profile.id
    	WHERE profile.gender = MALE
    `
    I get the following error:
    Copy code
    Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near "user"`
    It is solved by removing the
    AS user
    and
    AS profile
    parts, but then it gives an error on
    WHERE User.profileId = Profile.id
    saying the
    .
    is an invalid character. Is there any way to solve this? Prisma version is 3.13, using Postgresql
    ✅ 1
    r
    n
    • 3
    • 3
  • m

    mans

    06/13/2022, 3:00 PM
    Hi guys, I am using Prisma in one of my applications, but I have a problem I cant figure out. The application is a webshop, but I cant figure out how to let a user buy a single product multiple times. Can someone help me? Here is my model so far:
    Copy code
    model Product {
      id          Int      @id @default(autoincrement())
      createdAt   DateTime @default(now())
      updatedAt   DateTime @updatedAt
      name        String   @unique @db.VarChar(255)
      description String?
      price       Float
      published   Boolean  @default(true)
      // een relatie van alle orders met dit product erin
      orders      Order[]
    }
    
    model Order {
      id         Int       @id @default(autoincrement())
      clientName String
      email      String
      placedAt   DateTime  @default(now())
      status     Status    @default(PLACED)
      Products   Product[]
    }
    Nvm i figured it out
    ✅ 1
  • m

    Moin Akhter

    06/13/2022, 6:32 PM
    Hello devs actually i have a question i have a project based on sessions.Such as as an advisor i will provide availability time of mine for every day such as on monday my avalability is 2:pm - 5:pm on tuesday my availability is 12:pm - 10pm now any person who want to take my advise can book for my advise according to availibilty time of the day and no conflict should arise between bookings such as if advisor availability on monday is 2:pm - 5:pm and some one make a booking for 15minutes from 2:pm - 2:15pm on monday than no other booking should be done on monday 2:pm - 2:15pm do we have any tools for these kind of scnerio or libraries etc and what approach can be the best approach to resolve these issues on backend. Thanks in advance.. ☺️
    ✅ 1
    n
    • 2
    • 3
  • p

    prisma chobo

    06/13/2022, 6:39 PM
    PLEASE PLEASE. you've got to help me for this. I can't find docs as well 😞 😞 Im using Mongodb and
    Copy code
    prisma.agent.findMany({
          where: {
            teamId: id,
            deletedAt: null (undefined)
          },
        });
    
    my schema is like so
    
    model Agent {
      id                    String            @id @default(auto()) @map("_id") @db.ObjectId
      teamId                String
      deletedAt             Int?
    }
    
    This always empty array whether deletedAt is set or deletedAt is null or undefined...
    a
    ✅ 1
    n
    • 2
    • 2
  • p

    prisma chobo

    06/13/2022, 6:39 PM
    How can I filter Agent that deletedAt is set???
    ✅ 1
    n
    v
    • 3
    • 3
  • j

    Jack Wright

    06/13/2022, 7:38 PM
    Hi, I am quite new to Prisma and I have a simple question! What is the different between a model and a type in the schema?
    ✅ 1
    n
    • 2
    • 1
  • j

    Jack Wright

    06/13/2022, 7:47 PM
    Ah nevermind, I was on Prisma v1 documentation. 😛
    👍 2
  • j

    Jack Wright

    06/13/2022, 9:38 PM
    How would I achieve multple relations linked to the same column for user? For example, an author to something is linked to the users table by a one-to-one where it is owned and also linked by one-to-many where the item has multiple likes from users.
    Copy code
    model User {
      id        Int     @id @default(autoincrement())
      firstname String
      lastname  String
      username  String  @unique
      email     String  @unique
      password  String
      tel       String?
      country   String?
      bio       String?
      mealIds   Meal[]
    }
    
    model Meal {
      id    Int    @id @default(autoincrement())
      name  String @unique
      about String
    
      Owner        User  @relation(fields: [ownerId, likedUserIds], references: id) <--- Prisma does not like this
      ownerId      Int
      likedUserIds Int[]
    }
    ✅ 1
    n
    • 2
    • 2
  • m

    Mehul Gogri

    06/13/2022, 10:01 PM
    Hello, My Prisma Cloud Compute is on version 21.08.529 and trying to upgrade to the latest version. I am looking for upgrade steps. Please help.
    ✅ 1
    n
    • 2
    • 3
  • m

    matt murphy

    06/14/2022, 10:49 AM
    Hey guys, I'm looking for some assistance with Prisma MongoDB. I currently have a
    Ticket
    model and a
    TicketTag
    model, pretty much building a support ticketing system, however, I wish to add tags. pretty much how it's documented to implement such a feature is to use a many-to-many implementation as so:
    Copy code
    model Ticket {
      id                String          @id @default(auto()) @map("_id") @db.ObjectId
      title             String
      editedAt          DateTime?
      createdAt         DateTime
      ticketTags        TicketTag[]        @relation(fields: [ticketTagIds], references: [id])
      ticketTagIds      String[]         @db.ObjectId
      user              User             @relation(fields: [userId], references: [id])
      userId            String           @db.ObjectId
    }
    
    model TicketTag {
      id                String          @id @default(auto()) @map("_id") @db.ObjectId
      title             String
      description       String?
      attributes        Json
      editedAt          DateTime?
      createdAt         DateTime
      tickets           Ticket[]        @relation(fields: [ticketIds], references: [id])
      ticketIds         String[]         @db.ObjectId
    }
    But it seems incredibly unoptimized to stack for example 50,000 tickets into the
    ticketIds
    field on the
    TicketTag
    , as I'm aware MongoDB has a 16MB document limit. My question is, is how can I get only
    Ticket
    to store the
    ticketTagIds
    without also doing the same on
    TicketTag
    model
    ✅ 1
    n
    • 2
    • 3
  • m

    McKay Bonham

    06/14/2022, 12:21 PM
    Hi, I'm hosting a MERN stack on my server and I can't get the backend to talk with the MongoDB. Based on Googling the error I'm getting, the issue might be Prisma specific, although I'm not sure about that. Even if it's not Prisma specific, maybe someone here will be kind enough to help me through? 🙂 Database URL in my .env file:
    <mongodb://mongo_db_admin>:<password for mongo_db_admin>@127.0.0.1/<database name>?retryWrites=true&w=majority&ssl=true
    I've tried many variations on this URL, including putting a port after the hostname. I'm presenting the version that seems to get furthest before throwing an error.
    ✅ 1
    m
    n
    • 3
    • 8
  • m

    Matthew Drooker

    06/14/2022, 12:54 PM
    Hi. Does anyone have a good recommendation for how to just export/create a SDL file from a Prisma model? Im using graphql-compose for many functions in my servers…and to start, just need the SDL from Prisma to use the same library. I am using Postgres for the first time, as I usually use Mongoose(and Mongo). Graphql-compose has a great plug in that creates all the resolvers/types from/for Mongoose, so trying to find something like it with Prisma. Thanks
    ✅ 1
    n
    • 2
    • 4
  • j

    Julian

    06/14/2022, 1:29 PM
    Hi, is there a way to search across multiple fields but get the best result? For example, I have columns
    firstName
    ,
    lastName
    ,
    street
    ,
    houseNumber
    , and if I only provide a name
    John Doe
    it should return all John Doe's. But if I search for
    John Doe Mainroad 15
    it should only return the John Doe on Mainroad 15. I currently have a
    OR: []
    clause with
    contains
    /`search` conditions, but because of the
    OR
    it also returns all entires with house number 15. But with
    AND
    it would not return any result, so I can't use that either.
    ✅ 1
    n
    • 2
    • 3
  • g

    Gert

    06/14/2022, 3:57 PM
    Any Devs in here seeking to join a blockchain startup? Part/ Full Time, Remote. Dm me.
    ✅ 1
    n
    • 2
    • 1
  • r

    Rahul Taing

    06/14/2022, 4:02 PM
    I am getting this type error when I create a prisma client mock using mockDeep. any suggestions on how this can be resolved. most of this is copy-paste from singleton unit test example on the docs.
    Copy code
    error TS2345: Argument of type '() => { __esModule: boolean; default: { $on: CalledWithMock<void, ["beforeExit", (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 8 more ...; readonly prismaExampleTable: any; } & PrismaClient<...>; }' is not assignable to parameter of type 'MockModuleFactory<{ __esModule: boolean; default: { $on: CalledWithMock<void, ["beforeExit", (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 8 more ...; readonly prismaExampleTable: any; } & PrismaClient<...>; }>'.
          Type '{ __esModule: boolean; default: { $on: CalledWithMock<void, ["beforeExit", (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 8 more ...; readonly prismaExampleTable: any; } & PrismaClient<...>; }' is not assignable to type '{ __esModule: boolean; default: { $on: CalledWithMock<void, ["beforeExit", (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 8 more ...; readonly prismaExampleTable: any; } & PrismaClient<...>; } & { ...; }'.
            Type '{ __esModule: boolean; default: { $on: CalledWithMock<void, ["beforeExit", (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 8 more ...; readonly prismaExampleTable: any; } & PrismaClient<...>; }' is not assignable to type '{ __esModule: true; }'.
              Types of property '__esModule' are incompatible.
                Type 'boolean' is not assignable to type 'true'.
    👀 1
    a
    • 2
    • 5
  • j

    Jack Pordi

    06/14/2022, 4:14 PM
    Does explicitly setting multiple
    binaryTarget
    s cause the client building step to bundle all of those binaries in? I’m having this error:
    Copy code
    Query engine library for current platform \"linux-musl\" could not be found.\nYou incorrectly pinned it to linux-musl\n\nThis probably happens, because you built Prisma Client on a different platform.
    Even though my
    binaryTarget
    included both
    native
    and
    linux-musl
    ✅ 1
    • 1
    • 1
  • g

    Germa Vinsmoke

    06/14/2022, 4:34 PM
    Hey everyone. Need help with a small thing. I want to know how we can do the connection in between many to many when records already exists in both the tables.
  • g

    Germa Vinsmoke

    06/14/2022, 4:51 PM
    Got the answer, it wasn't mentioned explicitly in the docs but found it.
    🚀 2
    ✅ 1
    n
    • 2
    • 1
  • m

    Matias

    06/14/2022, 4:59 PM
    Hi folks! I have a question about.... prisma1 (sorry, I know but I can't update that project now and it's a simple question). I made a change in my database and then I executed prisma1 instrospect. Do I need to execute prisma1 deploy to see the changes? Because my graphql API doesn't reflect the changes (new column on a table)
    ✅ 1
    l
    n
    • 3
    • 3
  • a

    Atharva Bhange

    06/14/2022, 6:58 PM
    In my Dockerfile i have a
    RUN
    command of
    npx prisma generate
    when i build my image i am getting error
    Error: Get config: Unable to establish a connection to query-engine-node-api library
    The base image of my dockerfile is
    node:16-slim
    my prisma schema ha
    Copy code
    generator client {
      provider      = "prisma-client-js"
      binaryTargets = ["native"]
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    Any Ideas why this is happening ?
    👀 1
    a
    • 2
    • 5
  • l

    lawjolla

    06/14/2022, 7:27 PM
    Quick question… can
    findMany
    preserve id ordering? E.g. …
    Copy code
    const getUser = await prisma.user.findMany({
      where: {
        id: { in: [22, 91, 14, 2, 5] },
      },
    })
    and guarantee the order of the users is always 22, 91, etc? I can only come up with a manual solution, but I’m not sure how performant it is against Prisma’s findMany, e.g.
    Copy code
    const getUsers = (await Promise.all(ids.map(id => prisma.user.findUnique({ where: { id }})))
    ✅ 1
    a
    j
    • 3
    • 5
  • e

    e

    06/14/2022, 8:50 PM
    Hey everyone I'm trying to deploy NestJS + Prisma to Lambda with Serverless, but I'm running into issues with the typePaths.
  • e

    e

    06/14/2022, 8:51 PM
    I'm using serverless-webpack-prisma and my code looks like
    Copy code
    typePaths:
            process.env.NODE_ENV !== "production" || process.env.IS_OFFLINE
              ? ["**/*.graphql"]
              : ["*.graphql"],
  • e

    e

    06/14/2022, 8:55 PM
    Serverless offline works fine, but I tried a bunch of combinations for production with no luck.
    Copy code
    "errorMessage": "No type definitions were found with the specified file name patterns: \"*.graphql\".```
    ✅ 1
    n
    • 2
    • 4
  • m

    Moin Akhter

    06/14/2022, 11:37 PM
    Hello everyone i'm using multer and gcp buckets for uploading images but as we knew that normally for uploading large video i have seen a practice that first via multer we parse and store big file in a temporary folder and than stream over this temporary file and upload to bucket is there is any other way to skip this storing file in temporary folders of os and than streaming to bucket?Plz let me know thanks in advance.
    ✅ 1
    n
    t
    • 3
    • 29
  • g

    Gelo

    06/15/2022, 2:25 AM
    Hmm weird.. Is this a prisma bug or mongodb?
    ✅ 1
    j
    n
    j
    • 4
    • 4
  • i

    Ian Alexander Abac

    06/15/2022, 3:33 AM
    👋 Hello, team!
    n
    • 2
    • 1
  • o

    Okan Yıldırım

    06/15/2022, 8:16 AM
    Heyy, is there any difference between these? I did not understand it
    ✅ 1
    a
    n
    • 3
    • 5
  • b

    Berian Chaiwa

    06/15/2022, 9:52 AM
    Hello here. Anyone already put
    PrismaClientKnownRequestError
    into some nice
    json
    object like :
    {code: "P2002",message:"some msg"}
    ? Can be helpful to reuse when looking up these error codes. If not, I will type them all out 🙂
    ✅ 1
    n
    p
    • 3
    • 8
  • j

    Joonatan

    06/15/2022, 1:51 PM
    Does anyone know how to pass dates to Prisma.queryRaw? If I just write it like this:
    SELECT * FROM "Example" WHERE "date" > '2020-10-10'
    it works fine. But how to pass the date as variable? I have tried it like this:
    _let_ fromStr = dayjs(from).format("YYYY-MM-DD");
    `Prisma.queryRaw`SELECT * FROM "Example" WHERE "date" > '${fromStr}'`` and also without the single quotes but it throws “ERROR: invalid input syntax for type date: \“$1\“” each time
    ✅ 1
    a
    • 2
    • 2
1...586587588...637Latest