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

    Jakub Figlak

    03/16/2022, 7:34 PM
    Hello everyone! Another question from me. I have organization model like so:
    Copy code
    model Organization {
      id        String   @id @default(cuid())
      name      String
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    
      // Relation fields
      members User[]
    }
    I'm gonna create a route to create an organization that accepts body:
    Copy code
    name: string
    memberIds: string[]
    So basically I want to create relations from the
    many
    side of the
    many-to-one
    relation (user can be a member of only one organization at the given point in time). And here's my question - what is the best way to ensure that? Do I need to query for all users, check if they're already members of other organization and if they're, reject an entire request? Or is there a simpler way?
    a
    • 2
    • 1
  • a

    Aderito Timane

    03/16/2022, 8:37 PM
    Hey guys, Really awesome having been referred to Prisma by a colleague. I'm absolutely loving it 🙂 I have a query, which is why I'm here. Consider the following SQL Script:
    Copy code
    CREATE TABLE [Movie] (
      [id] int PRIMARY KEY,
      [title] nvarchar(255)
    )
    
    CREATE TABLE [User] (
      [id] int PRIMARY KEY,
      [username] nvarchar(255)
    )
    
    CREATE TABLE [Theater] (
      [id] int PRIMARY KEY,
      [theatre_name] nvarchar(255)
    )
    
    CREATE TABLE [Schedule] (
      [id] int PRIMARY KEY,
      [sdt] datetime,
      [movieId] int REFERENCES Movie (id),
      [userId] int REFERENCES User (id),
      [theatreId] int REFERENCES Theater (id)
    )
    versus the equivalent prisma.schema
    Copy code
    model Movie {
      id       Int        @id @default(autoincrement())
      title    String
      Schedule Schedule[]
    }
    
    model User {
      id       Int        @id @default(autoincrement())
      name     String
      Schedule Schedule[]
    }
    
    model Theatre {
      id       Int        @id @default(autoincrement())
      name     String
      Schedule Schedule[]
    }
    
    model Schedule {
      id        Int      @id @default(autoincrement())
      movieId   Int
      theatreId Int
      userId    Int
      date      DateTime
      movie     Movie    @relation(fields: [movieId], references: [id])
      theatre   Theatre  @relation(fields: [theatreId], references: [id])
      user      User     @relation(fields: [userId], references: [id])
    }
    I notice that all Theatre, User and Movie have to reference Schedule in Prisma. However I don't have to do similar when it comes to SQL. Is there a way to achieve this SQL simplicity? I'm open to learning about the reason for this design if there are better reasons I should rather follow this format. However, I have a simple approach to design the database where I'm happy to be making multiple calls for related data within the BFF. Further, I have some tables that have two or three relationships related to them and it becomes a less nice to read so much information stuck into just one model.
    🙌 1
    a
    • 2
    • 2
  • e

    Eric N.

    03/17/2022, 4:15 AM
    Hi! Is there a plan to support data migration on top of the existing schema migration? For example, I need to populate a new column with default data. Something like prisma db seed, but on the existing database. Even just a way to execute a one-off script will be helpful.
  • e

    Eric N.

    03/17/2022, 4:17 AM
    The only workaround I can think of is create an endpoint so I can run javascript prisma code in the server when I call that endpoint, but this sounds dangerous and hacky. I desperately need this feature. Please say you have a plan to release this 😭
    c
    a
    • 3
    • 7
  • j

    Julian

    03/17/2022, 7:51 AM
    Hey guys I am trying to use full text search with postgres, but it only seems to work for entire words. Is it also possible to return partial results? Like fuzzy search?
    n
    • 2
    • 10
  • j

    Joshua Snyder

    03/17/2022, 10:48 AM
    Whoever it was, thanks for the fix to the Data Platform for BigInt fields 🎉 😍
    🙌 1
  • m

    Mellonaut

    03/17/2022, 1:25 PM
    I’ve got an issue which I can’t wrap my head around. I’m using Prisma with SvelteKit (vite & typescript). All works fine in
    dev
    but, running deploy returns this error in the browser:
    Uncaught TypeError: Failed to resolve module specifier ".prisma/client/index-browser". Relative references must start with either "/", "./", or "../".
    I am instantiating Prisma in
    $lib/prisma.ts
    like this:
    Copy code
    import Prisma, * as PrismaAll from '@prisma/client'
    const pc = Prisma?.PrismaClient || PrismaAll?.PrismaClient
    export const prisma = new pc()
    and importing it in there from my endpoints. I’m using
    adapter_vercel
    to deploy to
    vercel
    Any idea what might be the issue here?
    • 1
    • 1
  • a

    Ayrton Fidelis

    03/17/2022, 2:22 PM
    Hello! I need help figuring out how to extract a report with prisma. I have a table of workers and I need to count how many registers have been created each month. I have a
    createdAt
    date that I think I should group by, but I need it to be grouped by the year-month of this date, ignoring the day/time. With Postgres I think the
    DATE_TRUNC('month', createdAt)
    would be perfect but I'm not allowed to group by that on Prisma. I even tryied to cast it to
    Prisma.WorkerScalarFieldEnum
    but in the runtime it told me this wasn't allowed. Really would appreciate any guidance someone could provide me to achieve that, specially if I don't have to change the database schema for that 😅 Here's what my best attempt looks like:
    a
    • 2
    • 1
  • m

    Mischa

    03/17/2022, 3:26 PM
    I need to store some user tokens securely in postgres. Any suggestions for best practices? One idea: encrypt/decrypt the token using a key stored in KMS, only certain lambdas have access to the key.
    n
    • 2
    • 1
  • r

    Rafael

    03/17/2022, 8:05 PM
    Hey! Is there still a plan to release an official nexus prisma plugin?
    n
    • 2
    • 1
  • s

    superbunches

    03/17/2022, 8:22 PM
    After a successful migration where I updated my schema with a new model, and a corresponding related field to an existing model, I’m getting this error:
    Copy code
    Invalid `prisma.book.findMany()` invocation:
    
    {
      include: {
        moods: true,
        ~~~~~
    ?   pairings?: true,
    ?   _count?: true
      }
    }
    
    
    Unknown field `moods` for include statement on model Book. Available options are listed in green. Did you mean `_count`?
    This doesn’t make sense to me because
    npx prisma migrate dev
    went fine, I’ve seeded my database using the new model name, and I’ve confirmed in postgres that the new table (
    Mood
    ) is there. Why would I get this error with the new field name and not the old field name? Running prisma 3.11.0 & @prisma/client 3.11.0
    n
    • 2
    • 8
  • t

    Travis Beck

    03/17/2022, 9:18 PM
    Is there any way in prisma to aggregate a value from a json column? I basically want to build this sql query with prisma:
    Copy code
    select
        user_id,
        sum(coalesce((properties->>'duration')::integer, 0)) as connection_duration
    from
        events
    where
        doc_id = '123'
        and event = 'disconnect'
    group by
        user_id
    I guess an interface I would want is something like this, but I think prisma would need to know more about the types in the json to be able to give it back to me:
    Copy code
    const events = await this.prisma.event.groupBy({
      by: ['userId'],
      where: {
        docId: '123',
        event: 'disconnect',
      },
      _sum: {
        'properties->>duration': true
      },
    })
    Are there any reasonable workaround here, or do I just need to use a raw query?
    a
    • 2
    • 3
  • b

    Bamada

    03/17/2022, 9:40 PM
    Hello here, I’m using this query to add a new entry to my DB table. But sometimes I can have a duplicated error due to a unique constraint
    (user, team)
    on the
    memberships
    table. My aim is to use something like
    INSERT IGNORE INTO ....
    Is there a better way to do that?
    Copy code
    await prisma.membership.create({
          data: {
            permission: membership.permission.toUpperCase() as any,
            role: membership.role,
            state: MembershipState.JOINED,
            joinedAt: membership.createdAt,
            requestedAt: membership.updatedAt,
            user: {
              connect: {
                username: membership.user.username
              }
            },
            team: { connect: { slug: membership.team.slug } }
          }
    Thanks in advance
    n
    • 2
    • 3
  • o

    Orcioly Andrade Alves

    03/17/2022, 10:20 PM
    Boa noite pessoal, Como omitir o retorno do Password para o cliente com o Prisma? Fiz uma rota GET com retorno dos dados do usuário, mas quero omitir o Password. Como proceder?
    n
    • 2
    • 1
  • d

    Damian M

    03/18/2022, 12:29 AM
    I want to move from postgres to mysql so our team can use planetscale. Since scalar lists arent supported in mysql, whats the best way of handling moving a postgres db with scalar lists to mysql?
    n
    t
    • 3
    • 3
  • g

    Geert van Dijk

    03/18/2022, 11:14 AM
    Hey all, hope this is the correct place. I'm deploying a keystone.js (using prisma) app to DigitalOcean using the app platform. It builds, but when it starts up it immediately fails saying "PrismaClientConstructorValidationError: Unknown datasource postgresql provided to PrismaClient constructor.Available datasources: sqlite". Locally runs fine with either sqlite and postgres, and the locally running version also connects fine to my digitalocean postgres server. Am I missing some setting or dependency that I'm overlooking?
    n
    • 2
    • 2
  • c

    Cezar Rodrigues

    03/18/2022, 12:06 PM
    Hi, does anyone can help me with some ManyToMany Relationship problem? 🙂
    v
    • 2
    • 2
  • o

    Oleg Rudak

    03/18/2022, 12:40 PM
    Hello everyone I try to use @@fulltext search in MySQL DB:
    Copy code
    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["dataProxy", "referentialIntegrity", "fullTextSearch", "fullTextIndex"]
    }
    
    model User {
      username            String?
      email               String?
    
      @@fulltext([username, email])
      @@fulltext([username])
      @@fulltext([email])
    }
    Migration:
    Copy code
    -- CreateIndex
    CREATE INDEX `User_username_email_idx` ON `User`(`username`, `email`);
    
    -- CreateIndex
    CREATE INDEX `User_username_idx` ON `User`(`username`);
    
    -- CreateIndex
    CREATE INDEX `User_email_idx` ON `User`(`email`);
    Also I have run
    yarn prisma db push
    But I still get error P2030:
    Cannot find a fulltext index to use for the search
    when trying to search by any field:
    Copy code
    return await prisma.user.findMany({
        where: {
          username: input?.username && { search: input.username },
          email: input?.email && { search: input.email },
          type: input?.type,
        },
        select: {
          ...getSharedSelectableFields(),
        },
        take: input?.take,
        skip: input?.skip,
      });
    Why this can happen? Prisma version: 3.8.1
    • 1
    • 1
  • j

    Jason Kleinberg

    03/18/2022, 2:15 PM
    For Prisma Day 2019, Lydia Hallie talked about integration testing with Prisma, and specifically using
    db-testing-pool
    . I haven’t been able to find it. Does anyone know what she was talking about? Alternatively, I could use some advice on integration testing with Prisma in a way that won’t have our test data collide.

    https://youtu.be/vdYf_hv60h0▾

    l
    j
    • 3
    • 3
  • a

    aj

    03/18/2022, 8:21 PM
    How can I tell prisma studio which env to point?
    n
    • 2
    • 1
  • m

    Mischa

    03/19/2022, 1:19 PM
    I am using aurora serverless postgres with Prisma right now for my application. I need to release it to the public soon, and the prisma cold starts make my app slow enough to be unusable. In order to make it faster, I'm evaluating my options. Would my best hope be to convert my DB from aurora serverless to public aurora and use the data proxy? Can I set up some sort of tunnel from the internet to my aurora DB inside my VPC? Since I think part or most of the cold start time is related to the parsing of my dmmfString, will data proxy even help? Also just discovered I can't combine interactive transactions and data proxy which is a problem. I'm happy to spend some time myself trying to speed up the prisma node client initialization if it's something I can help with but I'd need someone to point me in the right direction. I need to get this fixed. Any other suggestions?
    l
    c
    e
    • 4
    • 8
  • d

    David Marr

    03/19/2022, 6:51 PM
    I'm trying to figure out how the starter project can execute
    ts-node ./script.ts
    successfully, since it doesn't appear to define
    type: 'module'
    in package.json and it uses top-level
    import
  • d

    David Marr

    03/19/2022, 6:51 PM
    when i try to to the same thing in a basic remix project, it fails. Thinking there must be some difference in ts-config.json that I'm missing
  • d

    David Marr

    03/19/2022, 7:16 PM
    apparently
    module: "CommonJS"
    inside ts-config.json fixes it
    🙌 1
  • l

    Ludde Bror

    03/20/2022, 8:13 AM
    model Order {
    id             Int         @id @unique @default(autoincrement())
    products       Product[]   @relation(references: [id])
    }
    model Product {
    id             Int         @id @unique @default(autoincrement())
    orders         Order[]     // Why do I need this here? I don't really care about this, I only care about the above, products in an order. Can I get rid of this line somehow?
    }
    Another thing, how can I reference a product in an order entry, and at the same time set some additional information about it, such as the quantity of a referenced product?
    a
    • 2
    • 1
  • j

    Jawad Sefiani

    03/20/2022, 11:02 PM
    Does anyone know why Prisma doesn't allow to save an array of arrays as JSON (PostgreSQL)?
    a
    • 2
    • 11
  • f

    Fenibo fubara

    03/21/2022, 4:53 PM
    Hi friends any one here can guide me on how to use Prisma with kubernetes?
    n
    j
    • 3
    • 23
  • h

    Henry Luu

    03/21/2022, 5:14 PM
    Hi team, I'm using Prisma with our product, for one query I got
    Other side is closed
    error in the response. I tried so hard but couldn't find any root causes in our code. I found this closed issue from Github, but we didn't call
    $disconnect
    like the guy who created the bug did https://github.com/prisma/prisma/issues/5888 Can you help guide me about this issue please? 🙏 If I didn't call
    $disconnect
    , could anything else cause the error of
    Other side is closed
    in Prisma response?
    😟 1
    ❤️ 1
    n
    • 2
    • 6
  • a

    Atticus Curtis

    03/21/2022, 6:55 PM
    hello
  • a

    Atticus Curtis

    03/21/2022, 6:56 PM
    if anybody has time, could they check out: https://github.com/prisma/prisma/discussions/12450
    s
    n
    • 3
    • 2
1...555556557...637Latest