https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# prisma-client
  • f

    Fred The Doggy

    01/31/2022, 2:35 AM
    of dataproxy
  • f

    Fred The Doggy

    01/31/2022, 2:35 AM
    but no dice
  • f

    Fred The Doggy

    02/01/2022, 12:25 AM
    I have
    Copy code
    datasource db {
      provider = "mysql"
      url      = env("DATABASE_URL")
    }
    
    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["dataProxy"]
    }
    to be exact, and am getting
    Copy code
    error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.
      -->  schema.prisma:6
    l
    n
    • 3
    • 7
  • a

    Avi Block

    02/02/2022, 7:28 AM
    is it possible to do something like query based on two concated fields? or do I have to drop down to raw sql for that?
    n
    • 2
    • 1
  • b

    Baptiste Arnaud

    02/02/2022, 9:49 AM
    Hi! Is it really not possible to do something like:
    Copy code
    model Typebot {
      id        String           @id @default(cuid())
      publishedTypebotId String? 
      publishedTypebot Typebot? @relation("PublishedUnpublished", fields: [publishedId], references: [id])
      typebot          Typebot?  @relation("PublishedUnpublished", onDelete: Cascade)
    }
    I get:
    Copy code
    Error parsing attribute "@relation": The relation field `typebot` on Model `Typebot` must not specify the `onDelete` or `onUpdate` argument in the @relation attribute. You must only specify it on the opposite field `publishedTypebot` on model `Typebot`.
    I'd really like to delete the
    publishedTypebot
    if
    typebot
    is deleted
  • a

    Austin Zentz

    02/02/2022, 2:10 PM
    just need to do it on the other model -- so where you have your model PublishedUnpublished, that's where the onDelete: Cascade goes
  • b

    Barnaby

    02/02/2022, 8:07 PM
    prisma generate
    in a monorepo is throwing
    error Running this command will add the dependency to the workspace root rather than the workspace itself, which might not be what you want - if you really meant it, make it explicit by running this command again with the -W flag (or --ignore-workspace-root-check).
    How to tell Prisma to pass this flag to its yarn invocation?
  • b

    Barnaby

    02/02/2022, 8:16 PM
    had to fix this by force-installing
    @prisma/client
    and
    prisma
    in CI before generating code - I'd prefer a workflow where generated code is committed to the repo and not generated on CI - apparently this is advised against though
  • b

    Ben Ezard

    02/02/2022, 11:59 PM
    As per the Nest.js docs, I wait for the Nest app to close before letting Prisma terminate:
    Copy code
    enableShutdownHooks(app: INestApplication) {
      this.$on('beforeExit', async () => {
        await app.close();
      });
    }
    This code is important to us (since if Prisma terminates the process before Nest can gracefully shutdown, we end up with a whole bunch of leftover resources that need to be manually cleaned up), and as such I'm looking to write a test for it...but I'm unsure how to go about that - does anyone have any suggestions please? Previously I'd have mocked the implementation of
    $on()
    , but
    3.9.0
    made that readonly so that's not possible anymore (Jest only allows readonly properties to be mocked if they're not a function)
  • m

    Mischa

    02/04/2022, 11:34 AM
    any way to do
    SELECT DISTINCT ON
    ? - https://www.postgresql.org/docs/14/sql-select.html#SQL-DISTINCT
  • y

    Yaakov

    02/04/2022, 2:25 PM
    Hi is there a way to get the Prisma model name by passing a table name?
    Copy code
    model UserCategory {
      id Int @id @default(autoincrement())
    
      @@map("user_categories")
    }
    
    // Returns UserCategory
    prisma.findModelByTableName('user_categories')
  • s

    Slackbot

    02/04/2022, 2:35 PM
    This message was deleted.
    m
    a
    • 3
    • 9
  • m

    Mischa

    02/04/2022, 3:37 PM
    Untitled.ts
  • m

    Mischa

    02/04/2022, 3:37 PM
    Copy code
    INSERT INTO "CandidateSkill"
              ("candidateId", "skillId", "seniority")
              VALUES ($1, $2, $3),($4, $5, $6)
              ON CONFLICT ("candidateId", "skillId") DO UPDATE
              SET "seniority"=EXCLUDED."seniority"
    Raw query failed. Code:
    22021
    . Message: `db error: ERROR: invalid byte sequence for encoding “UTF8”: 0x00
  • m

    Mischa

    02/04/2022, 3:37 PM
    I checked and all the values are strings as expected and nothing is NULL or anything like that. Would love to know where this 0x00 is coming from.
    • 1
    • 1
  • m

    Mischa

    02/04/2022, 4:19 PM
    I created a discussion https://github.com/prisma/prisma/discussions/11640
  • n

    Nivv

    02/05/2022, 6:53 AM
    Hey! I'm just starting with prisma and was wondering if there was any way to use date manipulations? For example if I have event records that are timestamped, and I want to group them by week, is there a prisma equivalent of DATE_TRUNC?
    n
    s
    • 3
    • 4
  • r

    RedS

    02/05/2022, 2:27 PM
    Hi, I'm creating records like this without a problem, but when I want to delete them nothing happens.
    Copy code
    this.db[t].upsert({
          where: {
            guildId,
          },
          update: {
            channelId,
            content,
          },
          create: {
            guildId,
            channelId,
            content,
          },
        });
    
    
    
        this.db[t].delete({
          where: {
            guildId,
          },
        });
    • 1
    • 4
  • y

    Yaakov

    02/07/2022, 1:20 PM
    Good morning, I'm looking for a way to automatically add the
    updated_by
    ID before each update. The currect user can be obtained from
    req.user.id
    . The correct approach seems to be using Prisma middleware, however
    prisma.$use
    does not seem to provide access to the
    req
    object! Any ideas??
    Copy code
    prisma.$use(async (params, next) => {
    
      if (params.action === 'update') {
    
        const models = prisma._dmmf.datamodel.models;
    
        let model = models.find(m => m.name === params.model);
    
        let updatedAtField = model.fields.find(f => f.name === 'updated_by');
    
        if (updatedAtField) {
          params.args.data['updated_by'] = NEED ACCESS TO req.user.id;
        }
      }
    
      return next(params);
    });
  • h

    Hervé - Product at Prisma

    02/09/2022, 11:16 AM
    We’d appreciate your input here! Thank you
  • t

    Topi Pihko

    02/09/2022, 3:47 PM
    Hi! Any tips how to separate raw query to a separate function and populate it with parameters? Eg. queryCollection.ts:
    export function getEmailQuery(email: string): string {
    return `SELECT * FROM User WHERE email = ${email}`; }
    If I call as following:
    await this.prisma.$queryRaw` ${getEmailQuery("email@email.com")}`;
    Prisma gives error :
    Raw query failed. Code:
    42601
    . Message:
    db error: ERROR: syntax error at or near "$1"
    a
    • 2
    • 3
  • b

    Benjamin Smith

    02/10/2022, 7:16 PM
    Is there a better way to write this query? I'm trying to get: • Number of responses with matching campaignId ◦ Number of those responses that have a score >= 9 ◦ Number of those responses that have a score <= 6
    Copy code
    const [nResponses, nPromoters, nDetractors] = await prisma.$transaction([
        prisma.response.count({
            where: {
                campaignId
            }
        }),
        prisma.response.count({
            where: {
                campaignId,
                score: {
                    gte: 9
                }
            }
        }),
        prisma.response.count({
            where: {
                campaignId,
                score: {
                    lte: 6
                }
            }
        })
    ]);
    • 1
    • 1
  • o

    Opesanya Adebayo

    02/15/2022, 7:42 PM
    I have two tables: users and posts. A user has many posts. Can I eager load the user records from posts, such that as I fetch the posts, they come with the corresponding user’s record on the users table? I'm using Prisma with Postgres
    j
    • 2
    • 1
  • y

    Yaakov

    02/17/2022, 3:20 PM
    What is the recommended way of storing currency? Would normally use
    Decimal
    , but it loses its precision. Example: Value 97.85 turns into 97.8499999999999900
    t
    • 2
    • 7
  • j

    Josh Kelly

    02/18/2022, 10:58 PM
    Is it possible to sort by two columns? Given this collection:
    Copy code
    [
      {
        nickname: null,
        lastName: 'Smith'
      },
      {
        nickname: 'Billy',
        lastName: 'White',
      }
    ]
    If i’m calling
    findMany
    and i want to
    orderBy
    but i want to do something like
    [nickname || lastName]: 'asc'
    and then Billy would be the first item in the response as Smith comes after Billy.
  • j

    Jonas Damtoft

    02/19/2022, 10:05 AM
    Hey, hoping someone can assist me with a quick issue I have with the Prisma schema.. I am trying to model a character, it has to have a many to many self relation. But it says it is missing the ‘opposite’ relation field. When I format, it adds a
    Character
    field that references a new
    characterId
    field, why? I want an implicit relations table.
    Copy code
    model Character {
      id          String      @id @default(cuid())
      name        String
      friends     Character[] @relation("CharacterFriends")
    }
    I think my current solution will be this:
    Copy code
    model Character {
      id              String    @id @default(cuid())
      name            String
      friends         Friends[] @relation("friend")
      friends_ignored Friends[] @relation("friend_ignored") @ignore
    }
    
    model Friends {
      character        Character @relation("friend", fields: [characterId], references: [id])
      characterId      String
      ignoredCharacter Character @relation("friend_ignored", fields: [ignoredId], references: [id])
      ignoredId        String
    
      @@id([characterId, ignoredId])
    }
    Is there a better way? I also need to make sure I both insert and delete two records whenever I update this, as the friendship should always be mutual.
  • s

    Sreenivas Dunna

    02/21/2022, 5:05 AM
    Hi team, I want to add createdby and updatedby automatically from session variable for auditing purpose. can someone please help me to how can I achieve with the prisma and nestjs?
  • n

    nikos l

    02/23/2022, 2:15 PM
    hello, I try to use updateMany query method and I want to update as well the relation.
    Copy code
    await this.prisma.test.updateMany({
          where: {
            status: 'active',
            endsAt: {
              lt: new Date(),
            },
          },
          data: {
            status: 'expired',
            and here the relation...
          },
        });
    n
    • 2
    • 2
  • n

    nikos l

    02/23/2022, 2:15 PM
    is that possible?
  • a

    Adhithyan YT

    02/25/2022, 5:30 AM
    hi everyone, I have some issues with prisma client. In my node project i am using express and postgres db . i am facing
    Cannot read properties of undefined (reading 'create')
    this error when call my API anyone can help me with this
1...161718...23Latest