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

    Matt Young

    11/11/2021, 6:09 AM
    any pointers would be huge
    r
    • 2
    • 1
  • l

    Leo Romanovsky

    11/11/2021, 9:16 AM
    👋 I recently read this excellent write up 
    Lessor Known PostgreSQL Features
     https://hakibenita.com/postgresql-unknown-features#prevent-setting-the-value-of-an-auto-generated-key it was a top post on hacker news: https://news.ycombinator.com/item?id=29163319 One of the solid pieces of advice it has was to use an alternative primary key column type:
    Copy code
    CREATE TABLE sale (
        id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
        sold_at TIMESTAMPTZ,
        amount INT
    );
    This blocks users from being able to write directly to the 
    id
     field of a schema like above with an error:
    Copy code
    db=# INSERT INTO sale (id, sold_at, amount) VALUES (2, now(), 1000);
    ERROR:  cannot insert into column "id"
    DETAIL:  Column "id" is an identity column defined as GENERATED ALWAYS.
    The
    Copy code
    @db.Int @default(autoincrement())
    Generates the
    SERIAL
    column in postgres - is it possible to specify a custom column type?
    Copy code
    model User {
      id   String  @id 'INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY'
      test String?
    }
    r
    • 2
    • 1
  • p

    Petr Homoky

    11/11/2021, 10:10 AM
    Hey prisma guys! Does anyone has a working demo of prisma with latest Nextjs 12? In build I keep getting
    Cant resolve
    errors…

    https://homoky-files.fra1.digitaloceanspaces.com/2021/Screen-Shot-2021-11-11-11-09-32.32.png▾

    - I use prisma in
    getStaticProps
    . Previously I had version 10.0.4 of Next and it worked. I use monorepo and Prisma is separate lib.
    r
    • 2
    • 3
  • o

    Oleg Yarin

    11/11/2021, 11:19 AM
    Hey Prisma Team! Is there a way to get freshly created ids when using
    createMany
    ?
    ✅ 1
    r
    • 2
    • 1
  • e

    Erik Vitger Beuschau

    11/11/2021, 12:58 PM
    Is it expected/normal to see a 14MB increase in Vercel serverless function’s bundle size after adding Prisma? I’ve tried to only add
    @prisma/client
    and generate it using
    npx prisma generate
    to see if I could avoid adding
    @prisma
    but didn’t see any change.
    r
    • 2
    • 2
  • p

    Paul

    11/11/2021, 2:11 PM
    I have a bug with Prisma. I'm getting:
    Copy code
    Uncaught (in promise) Error:
    Invalid `prisma.groupChatChannelGroup.findMany()` invocation:
    
      Value out of range for the type. The column `lastRead` contained an invalid datetime value with either day or month set to zero.
    But the column doesn't exist in the table. I check out index.d.ts and I find this:
    Copy code
    export type GroupChatChannelGroupByOutputType = {
        id: Buffer
        ...
        lastRead: Date
        ...
        _count: GroupChatChannelCountAggregateOutputType | null
        _avg: GroupChatChannelAvgAggregateOutputType | null
        _sum: GroupChatChannelSumAggregateOutputType | null
        _min: GroupChatChannelMinAggregateOutputType | null
        _max: GroupChatChannelMaxAggregateOutputType | null
      }
    lastRead: Date shouldn't exist. How can I debug where this gets made? Thanks
    r
    • 2
    • 5
  • u

    user

    11/11/2021, 3:10 PM
    Databases Access in Serverless Environments with the Prisma Data Proxy Databases connection management in serverless functions is a major issue for many developers. The Prisma Data Proxy (Early Access) solves this problem by managing a connection pool.
  • e

    ezeikel

    11/11/2021, 3:32 PM
    Hey all 👋 is there a way to conditionally do a
    connect
    ? This doesn't seem to work:
    Copy code
    location: {
              connect: existingLocation
                ? {
                    id: existingLocation?.id,
                  }
                : {},
              create: location,
            },
    ✅ 1
    r
    • 2
    • 6
  • c

    Carlos Moreira

    11/11/2021, 6:15 PM
    Hello guys, I have a doubt about the size of the Prisma Client inside a docker container in a microservice architecture, some of the microservices depends on Prisma, so the final image after building the docker image is getting more than 200mb only from the Prisma Client (node_modules/.prisma with 93mb and node_modules/@prisma with 115mb), do you guys know a better way to deal with this dependency of the Prisma Client in a microservice architecture?
    s
    • 2
    • 2
  • r

    Roger

    11/11/2021, 6:25 PM
    I just have to say this .. Prisma is amazing!!! What's being created by the team is outstanding. The utility of Prisma is just off the chain. With MongoDB finally at a significant place in basically an unpaid advocate within the organizations that I contract. Thank you Team Prisma!!
    🙌 1
    fast parrot 1
  • t

    Tron Vo

    11/11/2021, 9:20 PM
    Is there a relation between the number of query engines running to the connection pool setting or should the number of running query engine instances generally be fixed to a one?
    r
    • 2
    • 2
  • c

    Chris Tsongas

    11/12/2021, 12:29 AM
    When creating a record, is there now a way to include relations in the return value? Or would I have to make a separate query?
    j
    • 2
    • 1
  • m

    Moh

    11/12/2021, 1:10 AM
    Hi all, I have an enum in my prisma schema like the below:
    Copy code
    enum paddock_slope_enum {
      One__0____7__ @map("One (0° - 7°)")
      Two__8____15__ @map("Two (8° - 15°)")
      Three__16____25__ @map("Three (16° - 25°)")
      Four___26__ @map("Four (>26°)")
    }
    The generated enum becomes:
    Copy code
    export const paddock_slope_enum: {
      One__0____7__: 'One__0____7__',
      Two__8____15__: 'Two__8____15__',
      Three__16____25__: 'Three__16____25__,
      Steep_Hill___26__: 'Steep_Hill___26__'
    };
    This is unexpected for me as I would have expected the values of the enum keys to be the map values in the schema? So my findMany GET API is returning the values with all the underscores - why is that? And can I get around it to get the value of the map?
    r
    • 2
    • 3
  • c

    Chris Tsongas

    11/12/2021, 6:47 AM
    Wondering if there's a straightforward way to delete a possibly orphaned record after disconnecting it? I have many-to-many user tagging and after disconnecting a tag from a user, I need to delete the tag if it's no longer referenced by other users. This is trivially easy with raw SQL but I couldn't find a way to do the delete with Prisma in one step:
    Copy code
    prisma.$transaction([
          prisma.user.update({
            where: { id: input.userId },
            data: {
              tags: {
                disconnect: [{ id }],
              },
            },
          }),
          prisma.$executeRaw`DELETE FROM "Tag" WHERE id NOT IN (SELECT "B" FROM "_UserToTag")`,
        ])
    m
    • 2
    • 1
  • s

    Siemen Blok

    11/12/2021, 10:11 AM
    Does anyone have any experience with writing unit tests in NestJS with Prisma?
    ✅ 2
    • 1
    • 3
  • s

    Siemen Blok

    11/12/2021, 12:00 PM
    I'm trying to create unit tests in NestJS with Prisma and found some examples and with the documentation on Prisma. Now trying to get it all working I'm running into some issues. context.ts
    Copy code
    import { PrismaClient } from '.prisma/client';
    import { mockDeep } from 'jest-mock-extended';
    import { DeepMockProxy } from 'jest-mock-extended/lib/cjs/Mock';
    
    export type Context = {
      prisma: PrismaClient;
    };
    
    export type MockContext = {
      prisma: DeepMockProxy<PrismaClient>;
    };
    
    export const createMockContext = (): MockContext => {
      return {
        prisma: mockDeep<PrismaClient>(),
      };
    };
    I'm getting the following error:
    Copy code
    Type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; } & PrismaClient<...>' is not assignable to type 'DeepMockProxy<PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>>'.
          Type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; } & PrismaClient<...>' is not assignable to type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; }'.
            The types of '$on.calledWith' are incompatible between these types.
              Type '(...args: [eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules...' is not assignable to type '(...args: [eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/cjs/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_mod...'.
                Types of parameters 'args' and 'args' are incompatible.
                  Type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/cjs/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules/jest-...' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules/jest-mock...'.
                    Type '[eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<void>) => void>]' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<...>) => void>]'.
                      Type '[eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<void>) => void>]' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void]'.
                        Type at position 0 in source is not compatible with type at position 0 in target.
                          Type '"beforeExit" | Matcher<"beforeExit">' is not assignable to type '"beforeExit"'.
                            Type 'Matcher<"beforeExit">' is not assignable to type '"beforeExit"'.
    
        15     prisma: mockDeep<PrismaClient>(),
               ~~~~~~
    
          context.ts:10:3
            10   prisma: DeepMockProxy<PrismaClient>;
                 ~~~~~~
            The expected type comes from property 'prisma' which is declared here on type 'MockContext'
    Does anyone know why? Or how I can fix this?
    • 1
    • 1
  • f

    Furkan Demirbilek

    11/12/2021, 12:27 PM
    hey 🖐️
    👋 2
  • v

    Vladi Stevanovic

    11/12/2021, 1:49 PM
    🎲 Care to cast your vote? 👀 We're very curious to see the results & your feedback! https://twitter.com/prisma/status/1459152858000113664
  • o

    Oleg Komarov

    11/12/2021, 6:13 PM
    Does Prisma support filtering with IN by tuples, e.g.:
    Copy code
    SELECT * FROM table
    WHERE (letter, number) IN (('T', 7), ('R', 2))
    where table is:
    Copy code
    number | letter
      7    |   'T'
      2    |   'R'
      4    |   'T'
    if not, joined workaround?
    m
    r
    • 3
    • 5
  • m

    Moaaz

    11/12/2021, 8:25 PM
    Question: Would it be possible to generate models using the Prisma Generator Specification? Looking to implement versioning for each data model defined in schema, and the idea was to write a generator that writes a
    Version
    model for each model. E.g.
    Copy code
    model User {
      id: Int
      name: String
    }
    generated model:
    Copy code
    model UserVersion {
      id: Int
      data: Json 
      userId Int
      user User @relation(fields: [userId], references: [id])
    }
    j
    • 2
    • 5
  • w

    Wade McDaniel

    11/12/2021, 11:06 PM
    Greetings, and of course an associated question! Hurray, another question, just like you wanted! I'm trying to get Prisma1 to play along side Prisma2, and I have a Prisma2 schema that looks like this:
    Copy code
    model User {
      id     String  @id @default(cuid()) @db.Char(30)
      email  String  @db.MediumText
      admin  Admin?
    }
    model Admin {
      id     String  @id @default(cuid()) @db.Char(30)
      name   String  @db.MediumText
      userId String  @db.Char(30)
      user   User    @relation(fields: [userId], references: [id], onUpdate: Restrict)
    }
    And in a Prisma1 GraphQL Playground I run this:
    Copy code
    mutation ($data: UserCreateInput!) {
      createuser(data: $data) {
        id
        email
      }
    }
    variables
    {
      "data" {
        "email": "<mailto:diety@supremebeing.org|diety@supremebeing.org>"
        "admin": {
          "create": {
            "name": "me"
          }
        }
      }
    }
    And I get an error about
    (conn=3216) Field 'userId' doesn't have a default value
    I also checked in MySQL and the foreign key constraint in
    Admin
    for
    userId
    references
    id
    in
    User
    Why isn't Prisma1 inserting
    userId
    into
    Admin
    when I create a user with a nested create for
    Admin
    ? Is that something that Prisma1 can't do?
  • a

    Awey

    11/13/2021, 8:35 AM
    Copy code
    model User {
      id        Int       @id @default(autoincrement())
      createdAt DateTime  @default(now())
      email     String    @unique
      username  String    @db.VarChar(50)
      password  String
      ...
    }
    
    model Message {
      id        Int      @id @default(autoincrement())
      createdAt DateTime @default(now())
      subject   String
      body      String
    }
    I'm having trouble understanding how to best setup the relationships for a 1 on 1 private messaging system. I'd like for it to work similar to how Reddit handles private messages. Could someone point me in the right direction please.
    r
    • 2
    • 6
  • p

    Phil Bookst

    11/13/2021, 9:43 AM
    when using planetscaledb, should we modify the connection_limit parameter since default is
    Copy code
    num_physical_cpus * 2 + 1
    but using planetscale we can use up to 10k concurrent requests
  • p

    peter

    11/13/2021, 10:49 AM
    How would you query the last 10 recent posts in a database, get the post title, total user votes and if current id has voted? Schema looks like reddit, e.g. Users <-> Votes <-> Posts
  • b

    Bjørn Atle Isaksen

    11/13/2021, 12:18 PM
    Question on Prisma 2 middleware. The name of the model comes in params.model. How can I check if that model contains a specific property ? If we use the docs as an example, how could I check if language was actually defined as a property on 'Post' before setting it?
    Copy code
    prisma.$use(async (params, next) => {
      if (params.model == 'Post' && params.action == 'create') {
        params.args.data.language = contextLanguage
      }
    
      return next(params)
    })
  • k

    Kristofer Pervin

    11/13/2021, 4:56 PM
    Hi there! I was wondering if anyone knows of a good way to replicate this package or this implementation with NextJS, MySQL, and Prisma? Would Prisma be willing to expand on the Seed feature to allow for this kind of migration?
  • m

    Moaaz

    11/14/2021, 3:03 AM
    SDK question: Why does DMMF not include any data associated to defined
    @@index
    Writing a plugin that does versioning to store history of changes on a data model – for each
    Datamodel
    , would like to define a
    DatamodelVersion
    model which specifies some fields for storing history and some references to
    Datamodel
    In addition would like to add
    versions: DatamodelVersion
    to the original
    Datamodel
    schema. But in doing so, losing any
    @@index
    that is defined on the original
    Datamodel
    schema.
    j
    r
    • 3
    • 7
  • a

    Akshay Kadam (A2K)

    11/14/2021, 10:52 AM
    I just added a new model to existing data:
    Copy code
    model Settings {
      id       String @id @default(cuid())
      timezone String @default("UTC")
      user     User[]
    }
    It threw migration error so I used
    --create-only
    but don't know how to fix it. I've been redirected to https://pris.ly/d/migrate-resolve but don't see anything there that helps me. The error is:
    Copy code
    Applying migration `20211114104346_create_settings`
    Error: P3018
    
    A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
    
    Migration name: 20211114104346_create_settings
    
    Database error code: 23502
    
    Database error:
    ERROR: column "settingsId" of relation "User" contains null values
    
    DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("23502"), message: "column \"settingsId\" of relation \"User\" contains null values", detail: None, hint: None, position: None, where_: None, schema: Some("public"), table: Some("User"), column: Some("settingsId"), datatype: None, constraint: None, file: Some("tablecmds.c"), line: Some(5815), routine: Some("ATRewriteTable") }
    How do I fix it?
    r
    • 2
    • 8
  • l

    ldlework

    11/14/2021, 2:29 PM
    Hello, I am wondering if anyone knows what the status of the Code-first Prisma schema AST/SDK project is?
  • p

    Peter Kellner

    11/14/2021, 3:00 PM
    I've just updated my project to 3.4.2 that uses sqlite and I'm getting timeout errors from the sqlclient. I posted a migration problem on stackoverflow (Connection error when seeding data with Prisma while running migration only - Stack Overflow), but am now realizing the timeout problem is happening seemingly randomly. After I got my app working and the data seeded, when I run my app, I'm getting timeout errors on simple things that don't make sense to me also. (return to soon...) Here is an error I get from a delete:
    Copy code
    Invalid `prisma.noteOnTag.delete()` invocation:
    
    
      Error occurred during query execution:
    ConnectorError(ConnectorError { user_facing_error: None, kind: ConnectionError(Timed out during query execution.) })
    This is for a Pluralsight course I'm working on, and though the source is not public yet, I can share it if that helps.
    t
    • 2
    • 2
1...506507508...637Latest