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

    chrisdhanaraj

    03/28/2021, 2:10 AM
    šŸ‘‹ I'm trying to learn some Prisma concepts, and just curious if
    connect
    is just an abstraction? (https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries/#connect-an-existing-record)? i.e., I let's say I have
    Copy code
    modal Author {
      id
      posts.     Post[]
    } 
    
    modal Post {
      id
      authorId.    Int
      author.      Author.   @relation(fields: whatever)
    }
    Let's say I create a new Author and want to swap some posts to them. Is there a functional difference between
    Copy code
    prisma.author.create({
      data: {},
      posts: connect{}
    }
    vs
    Copy code
    prisma.author.create({ data}
    prisma.posts.updateMany({
      where: {
        authorId
      }, 
      data: {}
    }
    r
    • 2
    • 5
  • m

    Mykyta Machekhin

    03/28/2021, 11:23 PM
    Hello everyone! Friends, at what stage is the situation with errors in the prisma now? It is very difficult to manage, which makes development much more difficult and forces you to write wonderful things that you would not want to see in your code. I saw that I’m not the only one who had similar problems https://github.com/prisma/prisma/issues/5040. Is the question moving? And if so, what is the most up-to-date information on how it will look in the end and in which version is the change expected?
    r
    • 2
    • 1
  • i

    Ian Ray

    03/29/2021, 1:30 AM
    Hey, I started marching down the route of writing a ā€œprettify modelsā€ tool that would be a step after
    prisma introspect
    . I wanted to double check this doesn’t already exist. raw introspect output might yield
    Copy code
    ...
    model table_name {
      field_name Int @annotations(for()) @days
    }
    ...
    prettified output (specifically with
    snake_case
    table/field names improved)
    Copy code
    ...
    model TableName {
      fieldName Int @annotations(for()) @days @map("field_name")
    
      @@map("table_name")
    }
    ...
    Before I go any further, does this already exist in the ecosystem? I couldn’t find anything in
    @prisma/sdk
    r
    • 2
    • 3
  • n

    Natalia

    03/29/2021, 2:21 PM
    typescript Big day tomorrow! fast parrotWe are hosting the 5th edition of TypeScript Berlin Meetup. Our superstar speakers: • Valentin Kononov - Runtime Type Safety in Typescript • Michael Arnaldi - Write Efficient & Testable code with effect-ts • Maciej Sikora - Elm in TypeScript, pattern matching and beyond You'll be able to win Prisma swag in the quiz and a free ticket to Functional Programming with TypeScript workshop will be given to the author of best question asked! All the attendees can purchase the access with a 20% discount. You can find out more and RSVP here or

    set up a YouTube reminderā–¾

    . See you all there! šŸ¤—
    šŸ’Æ 6
    🦜 6
    typescript 5
  • n

    Nick

    03/29/2021, 11:00 PM
    Hello, I'm porting a side project from Prisma 1 to Prisma 2 and I'm trying to get a self referential many-to-many relationship working. The model looks like -
    Copy code
    model User {
      id        Int @id @default(autoincrement())
      name      String
      email     String @unique
      friendedBy  User[]   @relation("Friends", references: [id])
      friended  User[]   @relation("Friends", references: [id])
    }
    And the generated postgres tables look like -
    Copy code
    CREATE TABLE public."User" (
      email text NOT NULL,
      name text NOT NULL,
      id integer NOT NULL
    );
    ALTER TABLE
      public."User"
    ADD
      CONSTRAINT "User_pkey" PRIMARY KEY (id)
    
    CREATE TABLE public."_Friends" ("B" integer NOT NULL, "A" integer NOT NULL);
    
    CREATE UNIQUE INDEX "_Friends_AB_unique" ON "_Friends"("A", "B");
    CREATE INDEX "_Friends_B_index" ON "_Friends"("B");
    ALTER TABLE "_Friends" ADD FOREIGN KEY ("A") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
    ALTER TABLE "_Friends" ADD FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
    The trouble I'm having is adding friends to a user. This is what I'm trying -
    Copy code
    await prisma.user.update({
        where: {
          id: input.id,
        },
        data: {
          friends: {
            create: { A: input.id, B: input.friendId },
          },
        },
      })
    It doesn't work and I suspect I might need a connect in there. Any suggestions?
  • n

    Nick

    03/29/2021, 11:19 PM
    I also tried to just add the record directly to the join table but prisma doesn't recognise
    _friends
    -
    Copy code
    await prisma.friend.create({
        data: {
          connect: [
            {
              id: input.id,
            },
            {
              id: input.friendId,
            },
          ],
        },
      })
  • n

    Nick

    03/29/2021, 11:37 PM
    I switched the file to typescript to give me the command completion which helped a lot. This successfully inserts into the join table -
    Copy code
    await prisma.user.update({
        where: {
          id: input.id,
        },
        data: {
          friended: {
            connect: {
              id: input.friendId,
            },
          },
        },
      })
    Now I just need to figure out how to query on the friends for a user. I thought that I could just use a query like this -
    Copy code
    type User {
        id: Int!
        name: String!
        email: String!
        friended: [Int]
        friendedBy: [Int]
      }
    
      type Query {
        users: [User!]!
      }
    But I just get nulls back for
    friended
    and
    friendedBy
  • n

    Nick

    03/30/2021, 3:55 AM
    I've figured it out. Just in case it's useful to anyone . . .
    Copy code
    model User {
      id        Int @id @default(autoincrement())
      name      String
      email     String @unique
      games     UserGame[]
      friends   User[] @relation("Friends")
      friendOf  User[] @relation("Friends")
    }
    Copy code
    type User {
        id: Int!
        name: String!
        email: String!
        games: [UserGame]!
        friends: [User]
        friendOf: [User]
      }
    
      type Query {
        user(email: String): User
        users: [User!]!
      }
    
      input CreateUserInput {
        name: String!
        email: String!
      }
    
      input UpdateUserInput {
        name: String
        email: String
      }
    
      input FriendInput {
        id: Int!
        friendId: Int!
      }
    
      type Mutation {
        createUser(input: CreateUserInput!): User
        addFriend(input: FriendInput!): User
        removeFriend(input: FriendInput!): User
      }
    Copy code
    export const user = ({ email }) => {
      return db.user.findUnique({
        where: { email },
        include: { friends: true, friendOf: true },
      })
    }
    
    export const users = () => {
      return db.user.findMany({ include: { friends: true, friendOf: true } })
    }
    
    export const User = {
      games: (_obj, { root }) =>
        db.user.findUnique({ where: { id: root.id } }).games(),
    }
    
    export const addFriend = ({ input }) => {
      return db.$transaction([
        db.user.update({
          where: {
            id: input.id,
          },
          data: {
            friends: {
              connect: {
                id: input.friendId,
              },
            },
          },
        }),
        db.user.update({
          where: {
            id: input.friendId,
          },
          data: {
            friends: {
              connect: {
                id: input.id,
              },
            },
          },
        }),
      ])
    }
    
    export const removeFriend = ({ input }) => {
      return db.$transaction([
        db.user.update({
          where: {
            id: input.id,
          },
          data: {
            friends: {
              disconnect: {
                id: input.friendId,
              },
            },
          },
        }),
        db.user.update({
          where: {
            id: input.friendId,
          },
          data: {
            friends: {
              disconnect: {
                id: input.id,
              },
            },
          },
        }),
      ])
    }
    Copy code
    mutation {
      addFriend(input: { id: 4, friendId: 3 }) {
        id
      }
    }
    
    mutation {
      removeFriend(input: { id: 4, friendId: 3 }) {
       id 
      }
    }
    
    query  {
       users {
        id,
        name,
        email
        friends {
          id
          name
        }
        friendOf {
          id,
          name
        }
      }
    }
    šŸ’Æ 1
    r
    • 2
    • 1
  • c

    cfree

    03/30/2021, 6:24 AM
    the info object can't be used to resolve relations automatically any more, instead you'll need to implement your type resolvers to ensure that relations get resolved properly.
    Are there any examples of this anywhere? Ref: https://www.prisma.io/docs/guides/upgrade-guides/upgrade-from-prisma-1/upgrading-prisma-binding-to-sdl-first/
    a
    n
    • 3
    • 2
  • m

    Marko

    03/30/2021, 12:03 PM
    Hello! I currently have issues with Prisma that is deployed on Google App Engine. There is clearly a memory leak and I get a lot of errors from prisma -
    Error in PostgreSQL connection: Error { kind: Closed, cause: None }
    (going to attach log in the thread). I am using a single prisma client to access everything and am using version
    2.19.0
    and node 12. Can't find any issues, so any help would be appreciated.
    r
    • 2
    • 3
  • n

    Natalia

    03/30/2021, 1:51 PM
    typescriptĀ TypeScript Berlin Meetup starts in 2 hours!Ā Our superstar speakers: • Valentin KononovĀ -Ā Runtime Type Safety in Typescript • Michael ArnaldiĀ -Ā Write Efficient & Testable code with effect-ts • Maciej SikoraĀ -Ā Elm in TypeScript, pattern matching and beyond You'll be able to win Prisma swag in the quiz and aĀ free ticket toĀ Functional Programming with TypeScript workshopĀ will be given to the author of best question asked! All the attendees can purchase the access with a 20% discount. You canĀ find out more and RSVP hereĀ orĀ 

    set up a YouTube reminderā–¾

    . See you all there!Ā šŸ¤—
    šŸ’Æ 2
    typescript 2
    fast parrot 3
  • n

    Natalia

    03/30/2021, 4:01 PM
    Live now!

    https://www.youtube.com/watch?v=fdeWbTwYQ-Eā–¾

  • t

    Tomas Diaz

    03/30/2021, 8:57 PM
    Hi! I have a circle ci configuration, and today it started failing ? (Maybe it was wrong all the time, but at least yesterday I didn’t get this error lol). Has anyone encountered a similar issue?
  • t

    Tomas Diaz

    03/30/2021, 8:59 PM
    I see the last publication in npm was 4h ago. Maybe something broke? 🤷
  • t

    Tomas Diaz

    03/30/2021, 9:16 PM
    Mh, now it works 🤷 , so.. anyway lol
    šŸ™Œ 1
  • e

    Ethan Zoller

    03/31/2021, 12:58 AM
    I've been thinking about building a shared Prisma client through an internal npm package. So I can maintain one schema/client but use it throughout different services. I'm thinking it through and I struggle to see if it's possible. How can I run a client in development with a development DB and a development-specific DB (experimental schema) without having to push to main?
    j
    • 2
    • 17
  • t

    Torrino

    03/31/2021, 9:04 AM
    Been using Sequelize for the past year, just recently found out about Prisma 2. So excited to migrate my project over 😊
    fast parrot 7
    prisma rainbow 6
    šŸ‘‹ 4
    m
    • 2
    • 4
  • t

    Torrino

    03/31/2021, 9:27 AM
    Another thing I've been meaning to ask; youtube is really lacking proper Prisma 2 tutorials and guides. Are there any plans for the official Prisma youtube channel to release create such videos covering a potential project from start to finish? (of course, the official documentation is absolutely amazing but also seeing some of those things in action would definitely lower the beginner learning curve)
    m
    n
    • 3
    • 6
  • a

    Alistair Smith

    03/31/2021, 2:29 PM
    Congrats on the new release team!
    šŸ™Œ 7
    prisma green 6
    fast parrot 6
    šŸ’Æ 7
  • j

    John Cantrell

    03/31/2021, 7:37 PM
    is there an easy way to see docs from older version of prisma (2.11) or does anyone know if the mode: 'insensitive' existed back then and works for where equals (not contains like example)?
  • m

    MartĆÆn

    03/31/2021, 9:07 PM
    Does Prisma include the netmask npm package? @nikolasburk you might want to read this if it does: https://news.ycombinator.com/item?id=26620538
    j
    • 2
    • 2
  • g

    Gabriel Chase

    04/01/2021, 2:19 AM
    hello, is this the correct way to import generated models / inputs / resolvers?
    *import* { User } *from* 'prisma/generated/type-graphql/models'
    *import* { UserCreateInput } *from* 'prisma/generated/type-graphql/resolvers/inputs'
    There are times i see when people use
    @generated
    which links to
    /node_modules/@generated
    I'm just wondering which one is standard and why is the
    User
    from
    prisma/generated.../models
    different from
    @generated/.../models
    ?
    • 1
    • 1
  • e

    Etel

    04/01/2021, 11:33 AM
    Hey <!channel>! 🌸 🌳 To start off the spring time and to give back, we’re running a new initiative in April we’re calling Tweets for Trees! šŸ™Œ With the recent release of PrismaĀ Migrate, all three aspects (Client, Migrate, and Studio) of Prisma are production ready. We’ve loved seeing what people have been writing andĀ posting on Twitter, and we thought we could use the opportunity to do something more. šŸŒ* Earth Day is coming up on the 22nd, Prisma will be planting a tree for every tweet about Prisma we see in April. Every tweet taggingĀ @prismaĀ in the month of April will be eligible.* ā‡ļø How It Works • Weekly, we’ll round up all of the tweets that mention and order that number of trees throughĀ Tree-Nation • We’ll then let everyone know how many trees we’ve planted at the end of each week this month • We’ll just be counting original tweets that contain @prisma, rather than any conversation that includes @prisma in the replies šŸ’š Join In: Spread the word about Prisma, and tweet using @Prisma.
    🌲 25
    🌓 33
    šŸ‘ 1
    prisma green 17
    šŸ‡µšŸ‡­ 3
    🐸 3
    šŸ„— 6
    šŸ 8
    prisma cool 10
    šŸ™†ā€ā™‚ļø 2
    šŸŒ 16
    🌳 13
    🟩 6
    šŸ§Ÿā€ā™€ļø 4
    🦜 4
    šŸ§šā€ā™‚ļø 2
    šŸ’š 43
    southafrica parrot 11
    🄬 6
    āœ… 8
    šŸ“— 6
    🟢 5
    šŸ‡°šŸ‡· 3
    šŸ‡»šŸ‡Ŗ 2
  • n

    Natalia

    04/01/2021, 2:58 PM
    What's New In Prisma (2.20.0) livestream starting in 2 minutes! fast parrot

    https://www.youtube.com/watch?v=2CDHn-Maij0ā–¾

    šŸš€ 5
  • j

    James Lee

    04/01/2021, 7:13 PM
    anyone have experience mocking Prisma in Jest? I've been using
    jest-mock-extended
    and using
    mockDeep
    to create typed mocks. However, after upgrading to latest 2.20.1 from 2.19.0, I'm receiving a typescript error.
    Copy code
    Type of property 'OR' circularly references itself in mapped type '{ [K in keyof { AND?: Enumerable<WorkplaceScalarWhereWithAggregatesInput>; OR?: Enumerable<WorkplaceScalarWhereWithAggregatesInput>; ... 12 more ...; updatedAt?: string | ... 1 more ... | DateTimeWithAggregatesFilter; }]: Or<...> extends 1 ? { ...; }[K] extends infer TK ? GetHavingFields<...> : never : {} extends Fi...'.
    šŸ‘€ 1
    šŸ‘ 1
    n
    j
    j
    • 4
    • 11
  • e

    El

    04/01/2021, 10:27 PM
    Hi there, could anyone help me out with how should I approach this? I'm trying to replace (disconnect - connect) a relation of
    MessageRead
    to `Message`:
    Copy code
    model Message {
      id             String               @id @default(uuid())
      content        String
      createdAt      DateTime             @default(now()) @map("created_at")
      sender         User                 @relation(fields: [senderId], references: [id])
      senderId       Int                  @map("sender_id")
      read           MessageRead?
    
      @@map("message")
    }
    
    model MessageRead {
      id            String                        @id @default(uuid())
      seenAt        DateTime                      @default(now()) @map("seen_at")
      seenMessage   Message                       @relation(fields: [seenMessageId], references: [id])
      seenMessageId String                        @map("seen_message_id")
      user          User                          @relation(fields: [userId], references: [id])
      userId        Int                           @map("user_id")
    
      @@map("message_read")
    }
    MessageRead
    keeps track of the
    User
    latest read message. I'm currently trying to figure out why this doesn't update the connection of
    MessageRead
    `seenMessage`:
    Copy code
    await this.prisma.messageRead.upsert({
      where: {
    	id
      },
      update: {
    	seenAt: new Date(),
    	seenMessage: {
    	  connect: {
    		id: message.id,
    	  },
    	},
      },
      create: {
    	user: {
    	  connect: {
    		id: user.id,
    	  },
    	},
    	seenMessage: {
    	  connect: {
    		id: message.id,
    	  },
    	},
      },
    });
    r
    • 2
    • 7
  • i

    Imad at

    04/02/2021, 5:03 PM
    guys i have a little issue, I'm following this guide and when i check prisma studio i see user table but without email and with this issue i can't create any post, Please help
  • i

    Imad at

    04/02/2021, 5:09 PM
    that's the error that i got
  • i

    Imad at

    04/02/2021, 5:09 PM
    PrismaClientValidationError:
    `Invalid
    prisma.post.create()
    invocation:`
    {
    data: {
    title: 'test',
    content: 'test',
    author: {
    connect: {
    email: null
    ~~~~
    }
    }
    }
    }
  • i

    Isidoro Ferreiro

    04/02/2021, 9:24 PM
    Hey, At our organisation we use the Prisma client in a few different projects, whenever we changed our db schema or updated Prisma dependencies (new great features are shipped every 2 weeks) we had to do so in multiple projects. Ended up just creating our prisma client in its own separate package and wrote an article about it, hope it can be useful for anyone in the same situation. Open to any comments/suggestions!
    šŸ’Æ 7
1...425426427...637Latest