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

    joao.santos

    11/10/2021, 6:57 AM
    Hi guys Im trying to seed a database, but the second message from User 2 is never created, what Im i doing wrong?? Do I need to create a message instead of trying to do all together? I simplified this, I wanted to create much more for testing.... Heres the code: SCHEMA:
    model Users {
     
    id            Int             @id @default(autoincrement())
     
    email         String          @unique
     
    name          String          @db.VarChar(255)
     
    conversations Conversations[]
     
    messages      Messages[]
    }
    model Conversations {
     
    id       Int        @id @default(autoincrement())
     
    name     String     @db.VarChar(255)
     
    messages Messages[]
     
    users    Users[]
    }
    model Messages {
     
    id             Int           @id @default(autoincrement())
     
    message        String        @db.Text
     
    userId         Int
     
    user           Users         @relation(_fields_: [userId], _references_: [id])
     
    conversationId Int
     
    conversation   Conversations @relation(_fields_: [conversationId], _references_: [id])
    }
    SEED:
    Copy code
    wait prisma.users.create({
        data: {
          email: '<mailto:user1@user.com|user1@user.com>',
          name: 'User 1',
          conversations: {
            create: {
              name: 'Conversation 1',
              messages: {
                create: {
                  message: 'Message 1',
                  userId: 1,
                },
              },
            },
          },
        },
      })
    
      await prisma.users.create({
        data: {
          email: '<mailto:user2@user.com|user2@user.com>',
          name: 'User 1',
          conversations: {
            connectOrCreate: {
              where: { id: 1 },
              create: {
                name: 'Conversation 1',
                messages: {
                  create: {
                    message: 'Message 2',
                    userId: 2,
                  },
                },
              },
            },
          },
        },
      })
    ✅ 1
    m
    • 2
    • 5
  • m

    manuel

    11/10/2021, 9:52 AM
    gm!
  • m

    manuel

    11/10/2021, 9:53 AM
    What's the easiest way to get row level security to work with prisma?
  • m

    manuel

    11/10/2021, 9:53 AM
    meaning I have two different usergroups who should query different rows from a table.
  • m

    manuel

    11/10/2021, 9:54 AM
    is the easiest version just add an enum to the row where I add these usergroups and check in the query the usergroup
    r
    • 2
    • 1
  • m

    manuel

    11/10/2021, 9:54 AM
    ?
  • l

    Lars Ivar Igesund

    11/10/2021, 9:57 AM
    I see that it takes about 3 seconds to instantiate the JS/TS prisma client (Prisma 1) on a GCP cloud function. Since these (and similarily cloud run instances) are recycled fairly often, is there any best practice advice on how to structure this to avoid such delays?
    m
    • 2
    • 15
  • j

    James

    11/10/2021, 10:43 AM
    Does anyone know of a github project that nicely demonstrates a "enterprise" level Prisma app? Something large enough to warrant some level of organisation into modules or domains.
    m
    n
    • 3
    • 16
  • s

    Stephen Osei-Bonsu

    11/10/2021, 11:53 AM
    Hi, I am using Prisma createMany() to create multiple records, with each having a single related record but it seem not to work, from the docs. Can anyone help with how to go around it please? Thanks
    e
    • 2
    • 2
  • s

    Stephen Osei-Bonsu

    11/10/2021, 11:55 AM
    Example I am creating multiple restaurant menus, and each of the menu is creating a related record of price in another table. Thanks🙏🏼
  • u

    user

    11/10/2021, 1:11 PM
    Prisma Chats with Tasin Ishmam

    https://www.youtube.com/watch?v=dls7swbphHA▾

    In this video, Marketing Associate Intern Nika Music interviews Tasin Ishmam. Tasin is a Developer Success Engineer at Prisma's developer relations team. He is currently working on a GraphQL tutorial series on how to use GraphQL and TypeScript in the backend, which will be released in the coming months. The pair talk about company culture and give advice for coming into the tech world. You can connect with Tasin here: Twitter: https://twitter.com/tasinishmam Website: https://tasinishmam.com/ 00:39- Intro 02:25 - Getting started w/ tech world 03:15 - Differences between university and company environments 04:52 - Biggest challenge 06:22 - Favorite part of working at Prisma 08:20 - Most exciting project 11:05 - Most exciting technology 12:00 - Preferred stack 12:40 - Advice for people entering tech world
  • j

    Jaye

    11/10/2021, 2:16 PM
    allo - i'm looking to use cursor pagination with a list of chronological results (oldest first). i think i want to do something like:
    Copy code
    await prisma.thing.findMany({
              take: perPage,
              orderBy: {
                createdAt: "desc",
              },
              skip: cursor ? 1 : undefined,
              cursor: {
                createdAt: cursor,
              },
            }),
    ...but prisma doesn't like this because
    createdAt
    isn't a unique field alternatively, i could use
    id
    as the cursor like in the example, but i am using `cuid`s:
    Copy code
    model Thing {
      id                 String       @id @default(cuid())
      // other stuff...
      createdAt          DateTime     @default(now())
      updatedAt          DateTime     @updatedAt
    }
    what's the best approach?
    r
    • 2
    • 1
  • n

    n

    11/10/2021, 2:27 PM
    is there a way to
    deleteMany()
    including relationships, like you have a
    User
    which has many
    Address
    and I want to delete the user and all of their addresses? or do you have to cascade delete each in a transaction? 🤷
    s
    c
    r
    • 4
    • 5
  • y

    Yazid Daoudi

    11/10/2021, 3:51 PM
    Hii all, i have this case : Users <-->Animals<-->Pathologies A user have 1 or many animals, an animal have 0 or many pathologies. How can i easly create a user with many animals including 0 or many pathologies ? Thanks !
    r
    • 2
    • 1
  • n

    Noel Martin Llevares

    11/10/2021, 4:00 PM
    Is the
    schema.prisma
    still required at runtime? Can I exclude the
    prisma
    directory?
    n
    r
    • 3
    • 4
  • r

    Raif Harik

    11/10/2021, 6:01 PM
    Hi, I'm totally stuck, it's a TypeScript thing, but maybe someone can help me. I'm trying to do this
    type FullBattery = Prisma.PromiseReturnType<typeof batteryRepository.getFullBatteryById>;
    Problem is my batteryRepository takes PrismaClient and returns a map of functions as a good repo should. So I don't know how to get the dang getFullBatteryById function out so I can do the typeof on it.
  • r

    Raif Harik

    11/10/2021, 6:02 PM
    also the batteryRespository has a type of course and that type has getFullBatteryId defined on it but it's return Promise<Battery> | undefined> which is not the right type because it should be "FullBattery" as defined above.
  • s

    Saimon Moore

    11/10/2021, 6:31 PM
    Hello, Not sure if this is the right channel but: We're seeing a very weird behaviour with upsert (v3.0.2 of @prisma/client) and I'm wondering if someone here can provide some pointers.
    r
    • 2
    • 8
  • j

    János Háber

    11/10/2021, 10:56 PM
    Hi guys, I try to use prisma with typegraphql but I got a
    Copy code
    Looks like you've forgot to provide experimental metadata API polyfill. Please read the installation instruction for more details.
    ✅ 1
  • j

    János Háber

    11/10/2021, 10:58 PM
    I found a page where write: "Ok, it turned out that the order of imports is important... Apparently it has to be imported BEFORE importing enum types..." But where can I fix the import?
  • j

    János Háber

    11/10/2021, 11:03 PM
    Here is the whole exception
    Copy code
    Looks like you've forgot to provide experimental metadata API polyfill. Please read the installation instruction for more details.
    Error: Looks like you've forgot to provide experimental metadata API polyfill. Please read the installation instruction for more details.
        at Object.ensureReflectMetadataExists (D:\Work\blickpunkt\v3\node_modules\type-graphql\dist\metadata\utils.js:42:15)
        at new MetadataStorage (D:\Work\blickpunkt\v3\node_modules\type-graphql\dist\metadata\metadata-storage.js:27:17)
        at Object.getMetadataStorage (D:\Work\blickpunkt\v3\node_modules\type-graphql\dist\metadata\getMetadataStorage.js:6:87)
        at Object.registerEnumType (D:\Work\blickpunkt\v3\node_modules\type-graphql\dist\decorators\enums.js:6:26)
        at Object.<anonymous> (D:\Work\blickpunkt\v3\node_modules\@generated\type-graphql\enums\SortOrder.js:29:13)
        at Module._compile (node:internal/modules/cjs/loader:1101:14)
        at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
        at Module.load (node:internal/modules/cjs/loader:981:32)
        at Function.Module._load (node:internal/modules/cjs/loader:822:12)
        at Module.require (node:internal/modules/cjs/loader:1005:19)
  • j

    János Háber

    11/11/2021, 12:25 AM
    Ahh I figured out:
    Copy code
    import 'reflect-metadata';
    💯 1
  • k

    Kelly Copley

    11/11/2021, 1:07 AM
    Does anyone here know how to specify an
    @default
    for an enum list field?
    r
    • 2
    • 2
  • v

    Valerii Petryniak

    11/11/2021, 2:45 AM
    Hello. Is there a way to generate sql from prisma file? I know there is cli prisma migrate but it only creates sql step by step. Thank you:)
    r
    • 2
    • 1
  • m

    Matt Young

    11/11/2021, 5:29 AM
    I have a typescript problem
  • m

    Matt Young

    11/11/2021, 5:30 AM
    I have my order by clause as orderBy: [{last_name: 'ASC'}, {first_name: 'ASC'}]
  • m

    Matt Young

    11/11/2021, 5:31 AM
    my error is showing Type 'string' is not assignable to type 'SortOrder'.ts(2345)
  • m

    Matt Young

    11/11/2021, 5:31 AM
    I don't get it
  • m

    Matt Young

    11/11/2021, 5:31 AM
    in typescript how are we supposed to supply the sort order?
    b
    r
    • 3
    • 11
  • m

    Matt Young

    11/11/2021, 5:53 AM
    const where = {         social_sec_no: filter.ssn,         birth_date: filter.birthDate,         last_name:  filter.lastName,         location: {             some: {             state: {equals: filter.state},             city: {equals: filter.city}            }         }}; let orderBy = [{last_name:'ASC'},{first_name:'ASC'}];       var searchBy = {           skip: filter.pageSize * filter.page,           take: filter.pageSize * 1,           where: where,           orderBy: orderBy       };       console.log(
    searchBy = ${JSON.stringify(searchBy)}
    );       const results = await this.prisma.person.findMany(searchBy); (edited)
1...505506507...637Latest