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

    Vladi Stevanovic

    10/25/2021, 3:53 PM
    🚨 Have you already secured your free ticker for Next.JS Conf? Prisma is one of the sponsors and our DevRel rockstars Daniel Norman and Mahmoud Abdelwahab will be speaking about Prisma 🤩 👉 Claim your free ticker here: https://nextjs.org/conf 👉 And you can learn more about Prisma + Next.js (and order free ✨ stickers ✨ ) here: https://www.prisma.io/nextjs
    🙌 2
    🦜 2
    prisma rainbow 2
    🤩 2
  • y

    Yaakov

    10/25/2021, 8:33 PM
    Is there any way to update a relation? The following is the explicit many-to-many example from the docs:
    Copy code
    model Post {
      id         Int                 @id @default(autoincrement())
      title      String
      categories CategoriesOnPosts[]
    }
    
    model Category {
      id    Int                 @id @default(autoincrement())
      name  String
      posts CategoriesOnPosts[]
    }
    
    model CategoriesOnPosts {
      post       Post     @relation(fields: [postId], references: [id])
      postId     Int // relation scalar field (used in the `@relation` attribute above)
      category   Category @relation(fields: [categoryId], references: [id])
      categoryId Int // relation scalar field (used in the `@relation` attribute above)
      assignedAt DateTime @default(now())
      assignedBy String
    
      @@id([postId, categoryId])
    }
    Suppose I want to do the following:
    Copy code
    await prisma.post.update({
      where: {
        title: 'Foo'
      },
      data: {
        categories: {
          category: {
            name: 'Updated category name'
          }
        }
      }
    });
    All I get is `"error": "Unknown arg
    categories
    in where.categories for type PostWhereUniqueInput. Did you mean
    set
    ?\n"` Is there any way for this to be accomplished?
    r
    • 2
    • 4
  • e

    Ethan Joffe

    10/25/2021, 9:05 PM
    how do i update a table and set one column to another columns value in the same row? ie update foo set x = y
    r
    • 2
    • 2
  • m

    mel

    10/25/2021, 10:07 PM
    In the second instalment of this tutorial (https://www.prisma.io/blog/fullstack-nextjs-graphql-prisma-2-fwpc6ds155#pagination), the final step has an instruction to update the resolver to add a results const. I don’t know where to put that const (it doesn’t fit with the resolver file as it is currently setup) and then the code provided for the index.tsx file does not define links. Has anyone figured out how to complete this step of the tutorial? How do I update the resolver and how do I define links in the index.tsx? Thank you.
    n
    m
    • 3
    • 14
  • j

    James Schull

    10/25/2021, 11:08 PM
    Hi, it's known that concurrent interactive transactions on the same rows can cause timeouts – however, I'm seeing timeouts even with only one interactive transaction at a time. Has this been noticed by anybody else?
    r
    • 2
    • 2
  • w

    Will

    10/26/2021, 3:36 AM
    Hi 🙂
    👋 2
  • w

    Will

    10/26/2021, 3:37 AM
    Is it also possible to get help here?
    r
    • 2
    • 1
  • c

    Chris Packett

    10/26/2021, 4:17 AM
    what’s the best way to create a repository pattern that is not dependent on prisma’s data structures? For instance, I want to create a repository with a “create” method:
    Copy code
    async create(data: Prisma.AutoCreateConfigurationCreateInput) {
      return await prismaClient.autoCreateConfiguration.create({
        data,
      });
    }
    The problem with the above code is that the method signature has a direct dependency on “prisma” which seems like an anti-pattern since the whole point of repositories are to abstract away the data access implementation details. Anyone have any good patterns they use here?
  • p

    Prince

    10/26/2021, 5:22 AM
    Hi guys, I am trying to add follower/following data to the db. What is the best approach to do it? It is throwing errors when I try adding relationship with the User model twice in the table.
    r
    • 2
    • 4
  • d

    Daniell

    10/26/2021, 7:46 AM
    Hello, does anyone know what could cause this issue? I have a server side rendered page in Next.js and a standalone Node.js server which only creates an instance of PrismaClient once (I am not using Next.js's server), I get this error right away when I visit the home page and Next.js makes a call to the standalone API
    Copy code
    Timed out fetching a new connection from the connection pool. (More info: <http://pris.ly/d/connection-pool>, Current connection limit: 3)
    r
    • 2
    • 14
  • o

    Octal pixel

    10/26/2021, 8:17 AM
    This is a question regarding Graphql + Next.js , in the recent video series why was the graphql API made using Next.js API routes and not a server, what benefits does it have over a server (apart from cost)
    v
    m
    • 3
    • 2
  • o

    Octal pixel

    10/26/2021, 8:18 AM
    https://www.prisma.io/blog/fullstack-nextjs-graphql-prisma-2-fwpc6ds155
  • t

    terion

    10/26/2021, 10:23 AM
    Are there any ways to properly use prisma client in multytenancy mode? E.g. overriding database connector in runutime? Currently I generate multiple clients for this and switch between them, but this is obviously memory-hungry way. Inspecting the generated client code but can't see how db parameters are even provided to query engine
    j
    • 2
    • 2
  • l

    Luis Kuper

    10/26/2021, 1:19 PM
    Hi there 👋 I have an issue regarding the combination of
    distinct
    &
    cursor-pagination
    . TLDR: How can i specify that distinct is applied before the cursor pagination steps (cursorId, skip, take) and not afterwards. Example: Having the following Model:
    Copy code
    model Comments {
      id       String  @id @default(uuid())
      author   User?   @relation(fields: [authorId], references: [id])
      authorId String?
      cursorId String  @unique
      text     String
    }
    and having that model filled with the following data:
    Copy code
    {
          authorId: "user1",
          cursorId: "0001",
          text:     "text1",
        },
        {
          authorId: "user2",
          cursorId: "0002",
          text:     "text2",
        },
        {
          authorId: "user3",
          cursorId: "0003",
          text:     "text3",
        },
        {
          authorId: "user4",
          cursorId: "0004",
          text:     "text4",
        },
        {
          authorId: "user1", // sidenote: this is the 2nd comment linked to user1
          cursorId: "0005",
          text:     "text5",
        }
    The objective is to fetch the comments in a cursor-paginated way and recieving items that are distinct on the field authorId. Considering 3 items per page, leads to the following query for the 2nd page:
    Copy code
    const res = await prismaClient.blogPost.findMany({
          distinct: ["authorId"],
          orderBy: { cursorId: "asc" },
          cursor: { cursorId: "0003" },
          skip: 1,
          take: 3,
        });
    This leads to the following res where the 2nd item is fetched although unfortunately in the first cursor-pagination fetch a item with that authorId "user1" has been fetched already before.
    Copy code
    {
          authorId: "user4",
          cursorId: "0004",
          text:     "text4",
        }
        {
          authorId: "user1", 
          cursorId: "0005",
          text:     "text5",
        }
    What i would like to have on that 2nd fetch is just the object with cursorId "0004". I assume this could be solved by the possibility of distinct being applied before the cursor pagination. Is there the possibility to do so? Thanks in advice.
  • y

    Yilmaz Ugurlu

    10/26/2021, 2:51 PM
    Has anyone received the following error message?
    Query createOneActivity is required to return data, but found no record(s).
    I just created a model and trying to create a record and receiving this error.. This is my model
    Copy code
    model Activity {
      createdAt      DateTime @default(now()) @map(name: "created_at") @db.Timestamptz(0)
      actionUserId   String   @map(name: "action_user_id") @db.Uuid
      affectedUserId String   @map(name: "affected_user_id") @db.Uuid
      event          String   @db.VarChar(64)
      entity         Json
    
      @@id([createdAt, actionUserId, affectedUserId, event])
      @@index(fields: [affectedUserId, createdAt], name: "actvt_fltr_idx")
      @@index(fields: [affectedUserId, createdAt, event], name: "actvt_fltr_evt_idx")
      @@map(name: "activity")
    }
    and this is the code that I’m using
    Copy code
    import { PrismaClient } from '@prisma/client';
    const prisma = new PrismaClient();
    
    const handler = async () => {
      const data = await prisma.activity.create({
        data: {
          event: 'test',
          actionUserId: '85a42af9-bb28-47b3-9ef2-699858c8bbea',
          affectedUserId: '85a42af9-bb28-47b3-9ef2-699858c8bbea',
          entity: { key: 'value' },
        },
      });
    
      console.log(data);
    };
    
    handler();
    r
    • 2
    • 10
  • j

    James Schull

    10/26/2021, 4:43 PM
    Hi – is it possible to use RAISE EXCEPTION in executeRawUnsafe? I am receiving a syntax error when using it, but it's the only way that I can think to make Prisma's transaction functionality work for our use case. We need to look up rows, perform service logic on those rows, and subsequently create or update multiple tables. We need the create/updates to be executed as a transaction, and we also need to use optimistic concurrency control to guard against race conditions between the find+create. The best way I can think to do this is to add raw SQL to the transaction that throws if the expected version has been incremented. Is this possible with Prisma's executeRawUnsafe API?
    r
    • 2
    • 2
  • l

    Luke Morris

    10/26/2021, 5:08 PM
    Hi all - playing around with the golang client. I'm trying to grab a list of users with a few related records. A user has many databases. I've queried them with
    db.User.Database.Some()
    A user has many alerts. I've queried them with
    db.User.Alert.Some()
    An alert has one notification. I've tried querying it with
    db.Alert.Notification.Some()
    , but
    Some
    isn't available here. If it's a "has one" relationship, should I be using another function instead?
    Copy code
    users, err := prisma.User.FindMany(
    		db.User.Alert.Some(
    			db.Alert.Notification.Some(),
    		),
    		db.User.Database.Some(),
    	).Exec(ctx)
    m
    l
    • 3
    • 9
  • c

    Chris Tsongas

    10/26/2021, 5:29 PM
    I'm curious when setting
    referentialIntegrity = "prisma"
    how does Prisma Client actually enforce referential integrity? I'm guessing it must make queries to validate operations before running them?
  • m

    Michael Hall

    10/26/2021, 6:13 PM
    Hi everyone, I am having some trouble creating game instances with 6 users in. The models are as follow
    Copy code
    model User {
      id String @id
      avatar String 
      username String
      discriminator String
      games Game[]
    }
    
    model Game {
      id      Int   @id @default(autoincrement())
      players User[] 
      team1   String[]
      team2   String[]
      result  Int?
    
      createdAt DateTime @default(now()) @db.Timestamp(6)
    }
  • m

    Michael Hall

    10/26/2021, 6:14 PM
    When I try to create the game instance it wont let me create the array of Users... How do I connect multiple players to the game?
    Copy code
    const playerQueue = queue.map((user) => ({
    			id: user.id,
    			username: user.username,
    			discriminator: user.discriminator,
    			avatar: user.avatarURL()!
    		}));
    
    		const test = await this.container.prisma.game.create({
    			data: {
    				players: {
    					create: playerQueue
    				},
    				team1: playerQueue.splice(0, 2).map((usr) => usr.id),
    				team2: playerQueue.splice(2, 5).map((usr) => usr.id)
    			}
    		});
    r
    • 2
    • 1
  • j

    Jaye

    10/26/2021, 6:17 PM
    i have some code that loops through a list of emails and creates users from it if conditions are met. there can be several hundred users. it looks like this:
    Copy code
    responses.map(r => {
    
                if (emailSchema.isValidSync(creatorEmail))
                  await db.user.upsert({
                    where: {
                      email: r.creatorEmail,
                    },
                    update: {},
                    create: {
                      email: r.creatorEmail,
                    },
                  })
    
                if (emailSchema.isValidSync(approverEmail))
                  await db.user.upsert({
                    where: {
                      email: r.approverEmail,
                    },
                    update: {},
                    create: {
                      email: r.approverEmail,
                    },
                  })
          })
    the user model has a unique constraint on the email column:
    Copy code
    model User {
      id            String    @id @default(cuid())
      email         String?   @unique
      // etc...
    }
    i intermittently get `Unique constraint failed on the fields: (
    email
    )` errors 😞 is this a race condition? if so, how can i fix it?
    r
    • 2
    • 4
  • e

    Elie Steinbock

    10/26/2021, 6:29 PM
    running into issues with: `PrismaClientRustPanicError: PANIC: called
    Option::unwrap()
    on a
    None
    value in query-engine/core/src/query_document/parser.rs25087` I see there’s one mention of it on GH issues and nothing beyond that. hard to reproduce
  • e

    Elie Steinbock

    10/26/2021, 6:30 PM
    anyway seen these strange PrismaClientRustPanicError errors before?
  • a

    Amit

    10/26/2021, 7:46 PM
    Hey, I know it's been asked before but I couldn't understand from previous responses how to solve this thing: I've a monorepo, I've two packages that both should represent Prisma client, each one with a different database (different RDS instance for that matter) and different schema. I need to use these two packages, call them
    @me/db1
    and
    @me/db2
    from every other package (
    @me/*
    ). This is Typescript so generating to
    src
    or the root of the package is not ideal, generating straight into
    dist
    will cause compilation to potentially fail, or make
    tsserver
    unhappy. Creating the packages in another repo, outside of the monorepo is kinda losing the entire point of monorepo. Did anyone solve something similar to that?
    l
    • 2
    • 4
  • f

    Florian Bress

    10/26/2021, 7:56 PM
    Hey!
  • e

    Ezequiel Pereira

    10/26/2021, 10:18 PM
    Hello, I’m willing to invest my free time to implement a Cassandra provider for Prisma. I love this database but there are not many good implementations for NodeJS/TypeScript, that’s why I think it’s a good fit to have it on Prisma. CQL is not that different from SQL, I’ve implemented a CQL builder a couple of years ago and I could start with the basic stuff without Materialized Views, Allow Filtering or Static Columns on this implementation. I commented recently on this ticket and I created a feature request for this more than a year ago on May 10, 2020. I did fork Prisma recently and I’m trying to get familiar with the codebase, but it doesn’t seem to have any kind of adaptor or specific files for each provider. It would be good if I could get a bit of guideness on where to look at.
  • t

    Tyler Matteo

    10/27/2021, 12:45 AM
    Hello, I'm considering using Prisma on some future projects and my team relies quite a bit on PostGIS for spatial features. I'm glad to see that support for them is on the roadmap but I understand that the team probably has a lot of complex features to tackle before then and so far it looks like there are some reasonable escape hatches with
    @Unsupported
    and
    queryRaw()
    . My question is has there been any open discussion as to what the Prisma Client API could look like for spatial features? I think it could be extremely powerful to have equivalents of PostGIS functions like
    ST_Contains
    and
    ST_Intersects
    in the Prisma client for doing spatial joins.
    r
    • 2
    • 1
  • d

    David Petrov

    10/27/2021, 2:21 AM
    how do i delete an entry from a many to many relation. Supposing i have User, Classroom, and userClassrooms
  • d

    David Petrov

    10/27/2021, 2:24 AM
    Trying something like
    Copy code
    await this.prisma.userClassrooms.delete({
          where: {
            user_id: user.id,
            classroom_id: classroomId,
          },
        });
    r
    • 2
    • 1
  • d

    Dia TM

    10/27/2021, 8:12 AM
    Hi Is it correct that I took prisma in libs/prisma/src/lib/schema.prisma with nestjs and nx How do I make migrations and run sids? I did this https://github.com/TemaOvchinnikov/olympus-social-network/blob/main/package.json
    "prisma": {
    "seed": "ts-node libs/prisma/src/lib/seed.ts",
    "schema": "./libs/prisma/src/lib/schema.prisma"
    `}`the syds don't work(
    "seed": "node --loader ts-node/esm libs/prisma/src/lib/seed.ts",
    works like this)🚲
    r
    • 2
    • 2
1...499500501...637Latest