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

    Ennabah

    08/10/2022, 9:57 AM
    Update: Rephrased the question in a reply. ------ Hi all I have a question about joining data from another database when querying a parent-children tree. For the sake of simplicity, I have mapped our actual model to a folder-file structure. Where each node in the tree can either be a folder or a file. This works perfectly fine even when querying the tree (we can ignore #4562 in this question) Now, if there’s another database (an existing one that we can’t change), contains data about each
    File
    . This data is changing every few seconds. With every query to
    prisma.directoryNode.findFirst
    , we need to join the data from the other database to the query. I have already connected to the remote database using
    postgres_fdw
    and can query the data with
    $queryRaw.
    Can anyone help us with performing a join from a remote database while using
    prisma.directoryNode.findFirst
    to maintain type safety. Performing a join using prisma’s type safety would be ideal if it’s supported.
    Copy code
    enum NodeType {
      FOLDER
      FILE
    }
    
    model DirectoryNode {
      id   Int      @id @default(autoincrement())
      type NodeType
    
      folder   Folder? @relation(fields: [folderId], references: [id])
      folderId Int?    @unique
    
      file   File? @relation(fields: [fileId], references: [id])
      fileId Int?  @unique
    
      children DirectoryNode[] @relation("directoryNode")
      parent   DirectoryNode?  @relation("directoryNode", fields: [parentId], references: [id])
      parentId Int?
    
      // timestamps
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    }
    
    model Folder {
      id   Int    @id @default(autoincrement())
      name String
    
      node DirectoryNode?
    
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    }
    
    model File {
      id             Int            @id @default(autoincrement())
      name           String
      extension      String
      defaultAppName String
      node           DirectoryNode?
    
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    }
    ✅ 1
    👀 1
    n
    • 2
    • 3
  • a

    Adam Boulila

    08/10/2022, 11:12 AM
    Is there a special method where i tell the Prisma Client i want the field to be updated with the current database time ?
    ✅ 1
    i
    n
    d
    • 4
    • 4
  • l

    Logan

    08/10/2022, 12:54 PM
    Copy code
    console.log(session.id);
    
        const userToken = await prisma.account.findFirst({
          where: { id: session?.id },
        });
        console.log(userToken);
    Hey all. Just found an issue with my prisma query. When trying to
    findFirst
    by
    id
    with a value that is
    undefined
    it returns the first document in the database. Surely it should only return something if the value
    id
    was found? In the code above,
    session.id
    is undefined. the
    console.log(userToken)
    returns the first account in the database.
    ✅ 1
    n
    • 2
    • 2
  • s

    Seb Powell

    08/10/2022, 12:59 PM
    Hello all, hoping someone might be able to help me with an issue I've run into with Nest.js, whereby it seems like Prisma (or Nest) is creating multiple connections to the DB on app boot (one for every module where we inject the Prisma service), which ultimately results in the following error:
    ✅ 1
    • 1
    • 1
  • s

    Seb Powell

    08/10/2022, 12:59 PM
    Error: Error in connector: Error querying the database: db error: FATAL: sorry, too many clients already
  • s

    Seb Powell

    08/10/2022, 1:00 PM
    This is what our project structure looks like:
  • s

    Seb Powell

    08/10/2022, 1:00 PM
  • s

    Seb Powell

    08/10/2022, 1:00 PM
    (I wrote a ticket up on the Nest.js GH as I'm not sure whether it's a Nest or Prisma issue: https://github.com/nestjs/nest/issues/10092)
  • s

    Seb Powell

    08/10/2022, 1:01 PM
    To me, it seems like we somehow need to be checking whether any connections exist before creating them (inside the .service files). But the docs / examples seem to suggest this is done automatically 🤷‍♂️
  • s

    Seb Powell

    08/10/2022, 1:02 PM
    Any pointers would be greatly appreciated!
  • b

    Bastien Etienne

    08/10/2022, 1:17 PM
    Hello, quick question i don't found on doc or i'm stupid probably second , on prisma request how can i do Something like this : i have 2 condition on where, i check user role and the service
    Copy code
    try {
        const result = await prisma.cibest_role.findUnique({
          where: {
            name: props.roleName,
            features: {
              service_name: props.featureName,
            },
          },
          select: {
            features: {
              select: {
                service_name: true,
                create: true,
                read: true,
                update: true,
                delete: true,
                icon: { select: { name: true } },
              },
            },
          },
        });
    ✅ 1
    n
    • 2
    • 4
  • r

    Richard Ward

    08/10/2022, 1:21 PM
    findUnique
    can only search on
    unique
    columns
  • r

    Richard Ward

    08/10/2022, 1:22 PM
    if
    features
    is not unique then try using
    prisma.cibest_role.findFirst
    or
    prisma.cibest_role.findMany
    instead
    ✅ 1
  • k

    kami gerami

    08/10/2022, 1:24 PM
    So I’m trying to create or update a lock. Using upsert. I basically want to create the lock if it does not exist for this particular user OR if it exists just update that one. Currently it changes other peoples locks if the dates (from, to) match.
    Copy code
    model Lock {
      id     String  @id @default(cuid())
      from   String  @unique
      to     String
      locked Boolean @default(false)
      User   User    @relation(fields: [email], references: [email])
      email  String
    
      @@unique([from, to, email]) // use can only create one entry with matching from, to and email.
    }
    
    
    model User {
      id            String       @id @default(cuid())
      name          String?
      email         String       @unique
      emailVerified DateTime?
      image         String?
      accounts      Account[]
      sessions      Session[]
      role          Role         @default(USER)
      timereport    Timereport[]
      Lock          Lock[]
    }
    
    model Timereport {
      id    String @id @default(cuid())
      date  String
      Event Event  @relation(fields: [event], references: [name])
      event String
      hours Float
      User  User   @relation(fields: [email], references: [email])
    
      email   String
      Project Project @relation(fields: [project], references: [name])
      project String
    
      @@unique([date, event, email]) // Do not allow multiple entries of same date + event + email
    }
    r
    • 2
    • 14
  • b

    Bastien Etienne

    08/10/2022, 1:24 PM
    i found on doc with findmany
  • r

    rcastell

    08/10/2022, 3:34 PM
    Why do i get an error when i type the variable? The type comming from schema prisma. If i remove the typing it works fine
    👀 1
    r
    • 2
    • 1
  • r

    rcastell

    08/10/2022, 3:36 PM
    This is the error: Property 'automatic_rates' does not exist on type 'quote_v2s'
    👀 1
    n
    v
    • 3
    • 4
  • s

    Slackbot

    08/10/2022, 3:48 PM
    This message was deleted.
    j
    • 2
    • 1
  • r

    Rain

    08/10/2022, 5:25 PM
    Hi there, I am testing creating a hundred thousand records using createMany, checking on the memory usage, my container uses a lot of memory for this. It took more than 1GB RAM for this operation. Is this normal ? I have to batch the creation to prevent out of memory. I am using prisma 3.15.1 I am using nested createMany
    Copy code
    prisma.user.create({ data, Post: { createMany: {data: postData}});
    ✅ 1
    l
    n
    • 3
    • 6
  • p

    prisma chobo

    08/10/2022, 5:44 PM
    is prisma python client official?
    ✅ 1
    w
    n
    • 3
    • 4
  • n

    nick

    08/10/2022, 6:34 PM
    hiya, am currently seeing if it is simple to load a nested relation through a many-to-many schema a la https://github.com/prisma/prisma/discussions/14748
    ✅ 1
    n
    • 2
    • 1
  • d

    Dave Rupert

    08/10/2022, 10:12 PM
    👋 Howdy, just wanted to say I finally hopped in here because I was wondering if I could measure query performance with Prisma, saw the
    4.2.0
    announcement with metrics and telemetry and that was a very serendipitous thing. Thanks for all the hard work.
    ✅ 1
    👋🏼 1
    👋 2
    n
    • 2
    • 1
  • r

    Raja Singh

    08/10/2022, 11:33 PM
    Hey
    n
    • 2
    • 1
  • j

    Justin F

    08/11/2022, 12:30 AM
    Does full text search completely work with postgres? I read some time ago that indexes were not working at the moment. Has this issue been resolved?
    ✅ 1
    n
    • 2
    • 1
  • k

    Kinjal Raykarmakar

    08/11/2022, 6:57 AM
    Hello! We've got a use case where our database schema has to be changed. But those changes can't be executed without resetting the. However, resetting the production database isn't our plan 🙂 Was going through this thread: https://github.com/prisma/prisma/discussions/10031 This thread is still unanswered. RedwoodJS is not something we're using. hence we're looking for some sort of standalone solution. Does anyone have any leads on this front? Any help would be appreciated. Thanks!
    👀 1
    r
    n
    • 3
    • 3
  • j

    Jeffr

    08/11/2022, 7:17 AM
    hello guys;
    👋 3
  • j

    Jan D'Hollander

    08/11/2022, 10:54 AM
    quick question here (not sure if it’s the right place), but I’m having some issues using Decimals in Sqlite. I basically want to store percentage values with 2 digits behind the comma max.
    👀 1
    r
    j
    • 3
    • 21
  • v

    vassbence

    08/11/2022, 1:21 PM
    Hi! Does anyone have experience with running large transactions (200k updates) on RDS instances? Dumping the DB and running the prisma transaction locally finishes in around 2 minutes, while doing the same thing with RDS haven't finished yet (it would likely take hours). We don't get any errors it's just that it takes super long. A bit more context: The transaction is basically running a migration, it's quite complex so it's written in TS+prisma instead of raw sql. An alternative solution seems like that we stop the application for a while, dump the prod DB, run the migration locally then restore it to production. We can work with this, it's just that I'm curious about what's up with doing the whole thing over the wire, what could be the issue.
    👀 1
    n
    • 2
    • 1
  • e

    Enzot

    08/11/2022, 2:20 PM
    Hello, I have question about limit for
    findMany.
    I have db with 30000 records and I am only able to take 5000 of them. If I try get more I have error from
    tokio-runtime-worker
    . It is bug or feature?
    ✅ 1
    n
    • 2
    • 6
  • h

    Heinz Gericke

    08/11/2022, 2:38 PM
    Hello everyone, new Junior ReactJS Developer here. I've been tasked with learning how to use Prisma and MySQL for a NextJS based Production CRM that uses MySQL and WHMCS. If anyone has worked with Prisma and WHMCS I would really appreciate any help or advice.
    ✅ 1
    👀 1
    r
    • 2
    • 5
1...606607608...637Latest