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

    Onkel Tem

    02/18/2022, 12:39 PM
    I already have some type definitions, and would like to mate them with Prisma. For example, I have a few enums (which are in fact - sets of strings) and I need to constrain prisma schema with them
  • o

    Onkel Tem

    02/18/2022, 12:39 PM
    How can I do that?
  • o

    Onkel Tem

    02/18/2022, 12:43 PM
    For example:
    Copy code
    model Inout {
      id Int ...
      name String
      muxType ???
    }
    and I have this type definition for MuxType:
    Copy code
    enum MuxType {
        Sdi = <any> 'sdi',
        Ts = <any> 'ts',
        Essence = <any> 'essence'
    }
    (Btw, how to set proper language for the code block?)
    n
    • 2
    • 2
  • o

    Onkel Tem

    02/18/2022, 12:44 PM
    Also, is there a way to extend existing schema with another file?
    n
    • 2
    • 4
  • o

    Onkel Tem

    02/18/2022, 12:52 PM
    One more question. Are there type discriminators? Or is there way to emulate subcategory-behavior?
  • o

    Onkel Tem

    02/18/2022, 1:02 PM
    Maybe I don't get something, but it doesn't seem to be possible to declare a simple extension for a relation...
  • o

    Onkel Tem

    02/18/2022, 3:04 PM
    Like this: https://dbfiddle.uk/?rdbms=mysql_8.0&amp;fiddle=21e7aeea085095012131774d41f32753 Is it possible to declare a scheme for this?
  • j

    Jacob Evans

    02/18/2022, 3:41 PM
    All the best to the Speakers from Prisma today at Node Congress!!
  • z

    zomars

    02/18/2022, 4:39 PM
    §
  • d

    Deepak Guptha S

    02/18/2022, 5:29 PM
    Hello, I have a SQL query example, I need to perform in Prisma Example:
    Copy code
    SELECT * FROM table1 
    WHERE '2011-01-01' BETWEEN table1.startdate AND table1.enddate
    How I can perform this operation in Prisma ?
    👀 1
    t
    • 2
    • 2
  • v

    Volcanic Island

    02/19/2022, 1:28 AM
    Anyone get Prisma working with an older (unsupported vers.) SQL Server like 2012? I can't connect from WSL2 to SQL Server 2012 running on the Windows host .
  • j

    James Carter

    02/19/2022, 6:26 AM
    Hey Everyone! I have a requirement which needs the same table schema but with different table names. They're differentiated based on say network. I know one method is to add a network column to differentiate entries but that slows down lookups. I have read of
    @@map
    attribute to specify table name of a schema to connect to, but I cannot have two or more
    @@map
    attributes in one schema (read table) definition. Any solution for this?
  • p

    per

    02/19/2022, 8:00 AM
    Hey there! I’m trying to figure out how to create many entries without knowing exactly how many beforehand. Example: I’m creating a match which has a number of
    sets
    . But it can have 2 or 3
    sets
    depending on how the match went. So how do I create this? If I don’t provide a third set, the query fails. See the
    createMany
    below:
    Copy code
    const match = await prisma.match.create({
          data: {
            group: {
              connect: {
                id: groupId,
              },
            },
            team1: {
              connect: {
                id: team1id,
              },
            },
            team2: {
              connect: {
                id: team2id,
              },
            },
            sets: {
              createMany: {
                data: [
                  {
                    setNumber: 1,
                    gamesTeam1: team1_set1,
                    gamesTeam2: team2_set1,
                    setWinnerId: set1Winner,
                  },
                  {
                    setNumber: 2,
                    gamesTeam1: team1_set2,
                    gamesTeam2: team2_set2,
                    setWinnerId: set2Winner,
                  },
                  {
                    setNumber: 3,
                    gamesTeam1: team1_set3,
                    gamesTeam2: team2_set3,
                    setWinnerId: set3Winner,
                  },
                ],
              },
            },
            winner: {
              connect: {
                id: matchWinner,
              },
            },
            date: '2022-01-18T08:56:38.152Z',
          },
        })
    e
    • 2
    • 11
  • o

    Onkel Tem

    02/19/2022, 11:52 AM
    I don't understand what makes this https://www.prisma.io/docs/concepts/components/prisma-schema/relations/one-to-one-relations 1-to-1?
    • 1
    • 2
  • o

    Onkel Tem

    02/19/2022, 11:58 AM
    Do I have to provide a back reference? What if it's not there? For instance, consider an example:
    Copy code
    model Inout {
      id             Int             @id @default(autoincrement())
      name           String
      inoutConfigSdi InoutConfigSdi?
      inoutConfigEth InoutConfigEth?
    }
    
    model InoutConfigSdi {
      id         Int    @id @default(autoincrement())
      portNumber String
      inout      Inout  @relation(fields: [inoutId], references: [id])
      inoutId    Int    @unique
    }
    
    model InoutConfigEth {
      id      Int    @id @default(autoincrement())
      address String
      inout   Inout  @relation(fields: [inoutId], references: [id])
      inoutId Int    @unique
    }
    Here
    Copy code
    inoutConfigSdi InoutConfigSdi?
      inoutConfigEth InoutConfigEth?
    look superfluous, as Input can have only ONE type of Config - either Sdi or Eth. But I don't see any way to declare it. Any ideas?
  • k

    Kasir Barati

    02/20/2022, 11:09 AM
    Hello #1 Is there any hard rule
    for string_1
    in the
    @unique(map: 'string_1')
    , Or it is just a simple string that is up to me to choice a meaningful string? #2 Is the
    string_1
    used to name the generated index for the field/s?
    ✅ 1
  • a

    Adrian

    02/20/2022, 12:35 PM
    Why do the implicit join's tables look like this? It looks awful. I can't see any reason why there is the need to do this when even TypeORM with all its defects, creates proper join tables
    👍 1
  • h

    Hussein

    02/20/2022, 1:37 PM
    Hello, how can I perform a nested update on many to many relationships without adding where clause
    n
    • 2
    • 1
  • γ

    Γιώργος Κραχτόπουλος

    02/20/2022, 3:55 PM
    Is there a way to query
    @id
    fields of type
    Int
    , instead of only a
    number
    a
    string
    too?
    n
    • 2
    • 3
  • f

    face boy

    02/20/2022, 5:52 PM
    but i provided an argument for "where" what the heck is this error talking about
  • f

    face boy

    02/20/2022, 5:52 PM
  • f

    face boy

    02/20/2022, 6:22 PM
    nvm figured it out life is good
    🙌 1
  • s

    Sardorkhuja Tukhtakhodjayev

    02/20/2022, 8:28 PM
    hey guys! is it possible to import auto generated input types? e.g. I have model Hoste, and prisma generates
    HostelCreateInput
  • j

    Jaye

    02/20/2022, 8:38 PM
    i’d like to use full-text search on a postgres
    jsonb
    column. prisma doesn’t seem to support this, although postgres does, giving good results is this coming any time soon? or, failing that, is there any way to add something like this to a
    .findMany
    without rewriting all my queries in raw sql (since they’re already quite big and complex):
    Copy code
    SELECT * FROM "Work"
    
    WHERE to_tsvector(answers) @@ websearch_to_tsquery('my search phrase');
  • f

    Fenris Play

    02/21/2022, 9:29 AM
    Hi guys, can someone tell me how to use @relation for an array of id? I get an error
    Key columns "ownersIds" and "id" are of incompatible types: integer[] and integer.
    l
    • 2
    • 1
  • h

    Harrys Kavan

    02/21/2022, 2:03 PM
    What would be the return type if https://github.com/prisma/prisma-examples/blob/dev/typescript/rest-nestjs/src/app.controller.ts#L54 would return all users including their Posts? Currently I only see
    UserModel
    and
    PostModel
    . But how would that look for a relation query?
    • 1
    • 1
  • o

    Olyno

    02/21/2022, 4:04 PM
    Hi 👋 i'm looking for @janpio about link the #announcements channel with ours on discord 😃
  • o

    Olyno

    02/21/2022, 4:05 PM
    I'm coming from Vladi
  • a

    Adrian

    02/21/2022, 4:18 PM
    Copy code
    async findUnique<T extends Prisma.UserArgs.include>(
        where: Prisma.UserWhereUniqueInput,
        include?: T
    ): Promise<Prisma.UserGetPayload<{ include: T }>> {
        // TODO: Fetch user from Azure AD B2C
        return this.prisma.user.findUnique({
            where: where,
            include: include ?? userWithRolesAndAvatarAndPosters.include,
            // ...userWithRolesAndAvatarAndPosters,
        })
    }
    Any idea of how to make the return type of my function dynamic based upon the include argument?
    🥲 1
  • t

    Tommy Adeniyi

    02/21/2022, 7:00 PM
    👋 Hello, team! Im happy to discover this tool but trying to use it I need help. I am trying to use Oauth in Nextjs with google and git hub but I keep getting into this error with the adaptor
    Copy code
    Unknown arg `access_token` in data.access_token for type AccountUncheckedCreateInput. Did you mean `accessToken`? Available args:
    type AccountUncheckedCreateInput {
      id?: Int
      type: String
      provider: String
      providerAccountId: String
      refreshToken?: String | Null
      accessToken?: String | Null
      expiresAt?: Int | Null
      tokenType?: String | Null
      scope?: String | Null
      idToken?: String | Null
      sessionState?: String | Null
      oauthTokenSecret?: String | Null
      oauthToken?: String | Null
      userId: Int
    }
    Unknown arg `expires_at` in data.expires_at for type AccountUncheckedCreateInput. Did you mean `expiresAt`? Available args:
    type AccountUncheckedCreateInput {
      id?: Int
      type: String
      provider: String
      providerAccountId: String
      refreshToken?: String | Null
      accessToken?: String | Null
      expiresAt?: Int | Null
      tokenType?: String | Null
      scope?: String | Null
      idToken?: String | Null
      sessionState?: String | Null
      oauthTokenSecret?: String | Null
      oauthToken?: String | Null
      userId: Int
    }
    Unknown arg `token_type` in data.token_type for type AccountUncheckedCreateInput. Did you mean `tokenType`? Available args:
    type AccountUncheckedCreateInput {
      id?: Int
      type: String
      provider: String
      providerAccountId: String
      refreshToken?: String | Null
      accessToken?: String | Null
      expiresAt?: Int | Null
      tokenType?: String | Null
      scope?: String | Null
      idToken?: String | Null
      sessionState?: String | Null
      oauthTokenSecret?: String | Null
      oauthToken?: String | Null
      userId: Int
    }
    Unknown arg `id_token` in data.id_token for type AccountUncheckedCreateInput. Did you mean `idToken`? Available args:
    type AccountUncheckedCreateInput {
      id?: Int
      type: String
      provider: String
      providerAccountId: String
      refreshToken?: String | Null
      accessToken?: String | Null
      expiresAt?: Int | Null
      tokenType?: String | Null
      scope?: String | Null
      idToken?: String | Null
      sessionState?: String | Null
      oauthTokenSecret?: String | Null
      oauthToken?: String | Null
      userId: Int
    }
    
     {
      message: '\n' +
        'Invalid `p.account.create()` invocation in\n' +
1...547548549...637Latest