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

    Naresh Bhatia

    10/29/2021, 2:22 AM
    Hi, just starting out with Prisma. Is it possible to model a one-to-one relationship with the same PK in both tables? The examples in docs produce a FK in one table pointing to a PK in another.
    r
    • 2
    • 5
  • n

    Naresh Bhatia

    10/29/2021, 3:10 AM
    Also it is not clear to me, how I would seed the database with the one-to-one relationship. The seeding example shows related objects being created as part of the parent object. However, I have json files for each table separately. So I would prefer loading each table in a separate loop. Is that possible?
    r
    • 2
    • 1
  • c

    Chris Tsongas

    10/29/2021, 4:32 AM
    Is there a difference between importing generated types from
    .prisma/client
    vs
    @prisma/client
    ? Both seem to work.
    r
    • 2
    • 1
  • g

    Gelo

    10/29/2021, 5:54 AM
    Full text search not working already added to previewFeatures and run prisma generate
    r
    • 2
    • 4
  • y

    Yerzhan

    10/29/2021, 9:48 AM
    hi there, I’m getting this error in prisma studio. it works fine on my intel mac, but doesn’t work on M1. did anyone encounter the same?
    Copy code
    Message: Error in Prisma Client request: 
    Invalid `prisma.user.findMany()` invocation:
      connect ECONNREFUSED ::1:55237
    r
    • 2
    • 7
  • d

    Dev__

    10/29/2021, 10:10 AM
    hello, how can I round a Decimal in prisma to 2 decimals
    Copy code
    3.6666666666666666667
    to
    3.67
    r
    • 2
    • 6
  • h

    Harun

    10/29/2021, 11:12 AM
    Hi guys, I am trying to create unique fields on Postgresql. The idea is, if organizationId is provided, then the group should be unique. If not, then it should be unique without counting organizationId. The issue i am having, is if there is discount provided without organizationId, and same discount WITH organizationId is attached. Then it will throw constraint error. Can i create unique fields where the group would be different if there is organizationId or not?
    n
    • 2
    • 1
  • p

    P V

    10/29/2021, 12:17 PM
    Hello! I'm trying to use prisma.$on to log queries, but it show me several requests/logs with the same timestamp. Is this normal?
    r
    • 2
    • 3
  • c

    Christophe Rudyj

    10/29/2021, 1:15 PM
    I have a lot of trouble figuring out the 1 to 1 and 1 to many relation i made this schema then I have my graphql derived from that
    Copy code
    prisma
    // This is your Prisma schema file,
    // learn more about it in the docs: <https://pris.ly/d/prisma-schema>
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    generator client {
      provider = "prisma-client-js"
    }
    
    model Games {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
      short_hand String   @unique @db.VarChar(255)
      name       String   @unique @db.VarChar(255)
      in_boxes   Box[]
      set        Sets[]
    }
    
    model User {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
      username   String   @unique @db.VarChar(255)
      password   String   @db.VarChar(255)
      role       Role     @default(USER)
      first_name String?  @db.VarChar(255)
      last_name  String?  @db.VarChar(255)
      store      String?  @db.VarChar(255)
      boxes      Box[]
    
    }
    
    model Store {
      id        Int      @id @default(autoincrement())
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
      name      String   @unique @db.VarChar(255)
    }
    
    model Box {
      id                Int      @id @default(autoincrement())
      createdAt         DateTime @default(now())
      updatedAt         DateTime @updatedAt
      box_number        String   @db.VarChar(100)
      box_second_number String?   @db.VarChar(100)
      set               String   @db.VarChar(255)
      set_list          Sets     @relation(fields: [set], references: [name])
      gameid            Int?     @default(1)
      game              Games?   @relation(fields: [gameid], references: [id])
      User              User?    @relation(fields: [userId], references: [id])
      userId            Int?
    }
    
    model Sets {
      id        Int      @id @default(autoincrement())
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
      name      String   @unique @db.VarChar(255)
      code      String   @unique @db.VarChar(255)
      children  String[]
      in_boxes  Box[]
      game      String?  @db.VarChar(255)
      gamerel   Games?   @relation(fields: [game], references: [short_hand])
      edition   String?
    }
    
    enum Role {
      USER
      ADMIN
      CHRIS
    }
    Basically a user will have boxes that they own ( The boxes has a Game Type and contains a parent Set which Has it own set code and contain set children (array) The game type it self has only name and shortcode My main issue is that when I try to create a set with the resolver code
    Copy code
    graphql
    //the graphql
    mutation {
    	  createBox (input:{box_number:"001", secondary_number:"A", game:{name:"yu"}, set:"Crucibile of War Unlimit"}) {
    	    box_number
    	    set
    	    game
    	    id
    	  }
    }
    `
    the resolver
    Copy code
    ts
       createBox: async (_: any, { input }: any, context: Context) => {
          const find = await context.prisma.games.findFirst({
            where: {name: {contains:input.game[0].name,
            mode:"insensitive"}}
            }
          );
          console.log(find);
          console.log(input.set);
          return await context.prisma.box.create({
            data: {
    
              box_number: input.box_number,
              box_second_number: input.secondary_number,
              gameid: find?.id,
              set: {connect: {
                  name: input.set
                },
              },
    
                },
    
     
    
          });
        },
    I get
    Copy code
    75 return await context.prisma.box.create(",
                "  Foreign key constraint failed on the field: `Box_set_fkey (index)`",
                "    at cb
    I'm really confused on how to make it work
    r
    • 2
    • 16
  • p

    per

    10/29/2021, 1:48 PM
    Hi there, I’m currently working on a small app where the user can create a team that either consist of one player or two players. When I create the team I use
    connect
    to create a relation to the already existing
    player
    in the database, which works perfectly. I can’t seem to find how to make this
    connect
    conditional though. The player 1 will always be there, but player 2 is not always provided (if the team only consists of only one player). Prisma stops record creation that is sees that player 2 is not specified of course. How can I solve this issue? Code below
    Copy code
    export default async function createTeam(
      req: NextApiRequest,
      res: NextApiResponse
    ) {
      const teamData = JSON.parse(req.body)
      const team = await prisma.team.create({
        data: {
          player1: {
            connect: {
              id: teamData?.player1?.id,
            },
          },
          player2: {
            connect: {
              id: teamData?.player2?.id,
            },
          },
          groups: {
            connect: {
              id: 'group1-id-test',
            },
          },
        },
      })
  • a

    Austin Zentz

    10/29/2021, 2:30 PM
    could probably do something like
    Copy code
    const data = {
          player1: {
            connect: {
              id: teamData?.player1?.id,
            },
          },
          groups: {
            connect: {
              id: 'group1-id-test',
            },
          },
        };
    if (teamData?.player2) {
      data.player2 = {
            connect: {
              id: teamData?.player2?.id,
            },
          }
    }
    const team = await prisma.team.create({
        data
    });
    👍 2
  • j

    Julien Goux

    10/29/2021, 8:08 PM
    Hello all. Did anyone tried measuring the cost of using Prisma in lambda in term of cold start?
  • j

    Julien Goux

    10/29/2021, 8:11 PM
    Is the data-proxy binary version exclusive to the Prisma platform or could it be used to connect to a connection pooler like pgbouncer ?
  • p

    p0wl

    10/30/2021, 9:29 AM
    Safari Desktop does not like your countdown 🙂 it's reproducable, no matter if private browsing or not. Safari Version 15.0 (16612.1.29.41.4, 16612). No errors in console or failing xhr requests.
    v
    • 2
    • 2
  • w

    Wingy

    10/30/2021, 2:35 PM
    Anyone know how I could insert 120k rows into an sqlite table? If I call
    create({ data: ... })
    on every record I get this issue:
    Copy code
    [Ingest] [ship-kills] 793828176027320321n failed PrismaClientUnknownRequestError: 
    Invalid `this.GalaxyInfo.prisma.kills.create()` invocation in
    /home/wingy/Code/Personal/Discord Bots/galaxy-info-v2/dist/ingest/shipKills.js:138:64
    
      135 if (!firstMessage || messages.map(message => message.id).includes(mostRecentKillId)) {
      136     for (const kill of alreadyParsed) {
      137         try {
    → 138             await this.GalaxyInfo.prisma.kills.create(
      Error occurred during query execution:
    ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteFailure(Error { code: DatabaseCorrupt, extended_code: 11 }, Some("database disk image is malformed"))) })
        at cb (/home/wingy/Code/Personal/Discord Bots/galaxy-info-v2/node_modules/@prisma/client/runtime/index.js:38541:17)
        at async fetchOldKills (/home/wingy/Code/Personal/Discord Bots/galaxy-info-v2/dist/ingest/shipKills.js:138:29) {
      clientVersion: '3.3.0'
    }
    Is this too much for sqlite? Would I be better off using postgres?
    ✅ 1
    • 1
    • 2
  • y

    Yazid Daoudi

    10/30/2021, 5:28 PM
    Hi everybody. ! How can i make a many to many relation for the same table. ? For exemple, I've a User table and i want to make a Friends table as : a user has many friends as user
    r
    • 2
    • 3
  • a

    aspect

    10/30/2021, 10:13 PM
    Are there any updates on this issue? https://github.com/prisma/prisma/issues/9553
  • a

    aspect

    10/30/2021, 10:13 PM
    It's been bugging me for days now.
  • a

    A DSJ

    10/31/2021, 5:55 PM
    Hello Guys, Sorry but i'm having a real hard time to read the doc about the updateMany, partially because some pieces are written in Typescript and it confuses me (as I don't know TS) Maybe somebody can point me to the right direction. I have several Item records on postgres that I would like to update at once. I would like to do it with an array of objects but I'm missing a piece.
    Copy code
    await prisma.Item.updateMany({
              data: [...updatedItems],
            })
    Maybe an identifier ? PK are ID's that are present inside ;y objects, but I don't know how to let prisma see those ID and update the right records (maybe its automatic ?)
    m
    r
    • 3
    • 4
  • a

    A DSJ

    10/31/2021, 5:56 PM
    I get this error : Argument data: Got invalid value
  • a

    A DSJ

    10/31/2021, 5:59 PM
    I tried with
    Copy code
    data: updatedItems,
    And I get the same error
  • p

    Perry Raskin

    10/31/2021, 6:59 PM
    I have a certain API endpoint that runs a bunch of queries (due to some looping). Even though my Next.js app has a global Prisma client (as recommended in the docs), my 20/20 Heroku connection limit is being reached only by me hitting that single endpoint. What can I do to solve this? I’m fairly certain that upgrading to a tier with more connections isn’t the long-term solution
    r
    • 2
    • 11
  • c

    Chris Packett

    10/31/2021, 8:21 PM
    Does prisma always store dates in UTC? If so, why doesn’t it store the “Z” at the end of the timestamp in the db?
  • m

    Moh

    10/31/2021, 9:20 PM
    Hi all, quick question about transactions. Is it possible to run a transaction where we can get the ID of the newly created entity for the next query in a transaction? So the equivalent to the SQL of:
    Copy code
    SELECT SCOPE_IDENTITY()
    r
    • 2
    • 1
  • k

    koriner

    10/31/2021, 10:43 PM
    Hi folks 🙂 Can someone help me with this error? I’m just learning prisma and following a tutorial, but getting this error here:
    Copy code
    Error validating model "Directory": Ambiguous self relation detected. The fields `parent` and `directories` in model `Directory` both refer to `Directory`. If they are part of the same relation add the same relation name for them with `@relation(<name>)`.
    r
    • 2
    • 1
  • j

    John Smeeth

    11/01/2021, 4:08 AM
    hi all, Can i order by of an sum aggregate? this is my code but it not work, it works with count as in document https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#groupby-and-ordering
    Copy code
    const groupLeader = await ctx.prisma.transaction.groupBy({
              by: ['userId'],
              where: {...},
              _sum: {
                quantity: true,
              },
              orderBy: {
                _sum: {
                  quantity: 'desc',
                },
              },
            })
    r
    • 2
    • 2
  • j

    John Smeeth

    11/01/2021, 4:09 AM
    Can anybody give me an advise? thank you
  • k

    KJReactor

    11/01/2021, 10:44 AM
    I'm now using Prisma v 3.3.0 with the MongoDB and I'm getting an "authentification failed" error for SCRAM. I checked in the db and the credentials I used are correct. I event copied the credentials from the env file and pasted into mongo shell (I'm using a local installation of MongoDB) and I got it just fine. Here is the connection URL I'm using: ``"mongodb://clientTest:clientTest@localhost:27017/testDB?maxPoolSize=2&amp;retryWrites=true&amp;w=majority"`` Am I doing something wrong? SOLVED: Checking out the logs showed user was not found in the current db :)
    ✅ 1
  • y

    Yossef Wakslicht

    11/01/2021, 11:18 AM
    Does anyone have examples with mocha tests + prisma + mongodb? How do you drop the database in the end for example?
    k
    • 2
    • 1
  • y

    Yaakov

    11/01/2021, 1:11 PM
    Prisma currently supports these 5 databases: • PostgreSQL • MySQL • MongoDB • SQL Server • SQLite Assuming I had no preference and could could go with either of these databases, which would be the most recommended choice based on short-term and long-term Prisma support?
    r
    a
    • 3
    • 5
1...501502503...637Latest