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

    Ridhwaan Shakeel

    10/19/2022, 3:40 AM
    hi, I switched my node application (from commonjs) to type es module, and now my prisma client is throwing a timeout error in my async/await methods (sqlite connector)
    Copy code
    ```
    ready = true;
    ready && sync();
    
    const sync = async () => {
      /* some logic * /
      jsonCollection.length &&
        (await upsertManyA(
          jsonCollection.filter((obj) => obj.startsWith(A))
        ));
      jsonCollection.length &&
        (await upsertManyB(
          jsonCollection.filter((obj) => obj.startsWith(B))
        ));
      jsonCollection.length &&
        (await upsertManyC(
          jsonCollection.filter((obj) => obj.startsWith(C))
        ));
      /* finish */
    };
    ```
    const upsertManyA, upsertManyB, upsertManyC
    are
    async
    methods that each make an
    async
    request to an api service then perform an
    async
    prisma upsert
    upsertManyA
    (first method) runs normally, but
    upsertManyB
    (second method) throws a timeout error everytime when it starts. All async/await methods above are expected to run in serial
    Copy code
    node_modules/@prisma/client/runtime/index.js:30855
    [0]       throw new PrismaClientUnknownRequestError(message, this.client._clientVersion);
    [0]             ^
    [0]
    [0] PrismaClientUnknownRequestError:
    [0] Invalid `prisma.notAvailable.upsert()` invocation:
    [0]
    [0]
    [0] Error occurred during query execution:
    [0] ConnectorError(ConnectorError { user_facing_error: None, kind: ConnectionError(Timed out during query execution.) })
    [0]     at RequestHandler.handleRequestError (/node_modules/@prisma/client/runtime/index.js:30855:13)
    [0]     at RequestHandler.request (/node_modules/@prisma/client/runtime/index.js:30834:12)
    [0]     at async PrismaClient._request (/node_modules/@prisma/client/runtime/index.js:31812:16)
    [0]     at async upsertNotAvailable (file:/index.js:313:3) {
    [0]   clientVersion: '4.4.0'
    [0] }
    [0]
    [0] Node.js v18.11.0
    feedback appreciated thanks
    n
    v
    • 3
    • 4
  • m

    Max

    10/19/2022, 4:39 AM
    Hi all. I have a schema modelling question. In my order management system an order can be in three different states;
    new
    ,
    packing
    ,
    shipped
    . Each different state has additional fields tracking when the state was entered and other information. I'd like to create the schema so that I can query across all the different states. This is what I have so far:
    Copy code
    generator client {
      provider = "prisma-client-js"
    }
    
    datasource db {
      provider = "mongodb"
      url      = env("DATABASE_URL")
    }
    
    type LineItem {
      productId String
      name      String
      quantity  Int
    }
    
    enum Status {
      NEW
      PACKING
      SHIPPED
    }
    
    model NewOrder {
      id        String     @id @default(auto()) @map("_id") @db.ObjectId
      status    Status     @default(NEW)  
      lineItems LineItem[]
      createdAt DateTime   @default(now())
    }
    
    model PackingOrder {
      id        String     @id @default(auto()) @map("_id") @db.ObjectId
      status    Status     @default(PACKING)
      lineItems LineItem[]
      createdAt DateTime   
      packingStartedAt DateTime @default(now())
    }
    
    model ShippedOrder {
      id        String     @id @default(auto()) @map("_id") @db.ObjectId
      status    Status     @default(SHIPPED)
      lineItems LineItem[]
      createdAt DateTime   
      packingStartedAt DateTime 
      shippedAt DateTime @default(now())
    }
    Is there it possible to achieve this or am I barking up the wrong tree? Thanks!
    n
    v
    • 3
    • 7
  • j

    Javier Tarazaga Gomez

    10/19/2022, 5:19 AM
    👋 Hello, team!
    👋 2
  • j

    Javier Tarazaga Gomez

    10/19/2022, 5:22 AM
    Hi everyone! Does anybody know a good example of using DDD together with Prisma, specially when it comes to related data? Per example, if you have a List with many tasks, how would you upsert/delete tasks from the list using DDD? TypeORM will identify orphan records in a OneToMany relation when doing an insert and you can tell it to automatically remove them, but I have no idea if this is even possible in Prisma. Thanks!
    👀 1
    n
    • 2
    • 7
  • k

    Klaus

    10/19/2022, 9:50 AM
    Heya, If I have a explicit many to many table, then connect/disconnect doesnt work anymore
  • k

    Klaus

    10/19/2022, 9:53 AM
    Do I need to use create/delete instead
    ✅ 1
    n
    • 2
    • 3
  • k

    Kenny Tran

    10/19/2022, 10:29 AM
    Hey, what is the maximum query count you can fetch from a table. Is it over 10k?
    ✅ 1
    n
    m
    • 3
    • 3
  • v

    ven v

    10/19/2022, 1:59 PM
    Hi - I am using Prisma with Nuxt 3 and I recently upgraded to rc12 (release candidate 12) and I am getting the following error.
    ✅ 1
    r
    • 2
    • 5
  • p

    Patrick

    10/19/2022, 3:04 PM
    I have a column in my DB that was supposed to be unique, but it’s not. Some bad data got in and I ended with the same value in multiple rows. Does prisma have a method to find all rows whose column value occurs more than once in the DB?
    👀 1
    t
    r
    • 3
    • 8
  • s

    Sebastian Gug

    10/19/2022, 3:16 PM
    Copy code
    this.client.user.update({
          where: { id },
          data: { emailVerificationSendCount: +1 },
        });
    ✅ 1
  • s

    Sebastian Gug

    10/19/2022, 3:16 PM
    is this syntax possible with postgres? for racing conditions reasons I'd prefer not to set it as an absolute value
    ✅ 1
    n
    • 2
    • 3
  • s

    Sebastian Gug

    10/19/2022, 3:16 PM
    do I need to do it raw sql?
    ✅ 1
    t
    n
    • 3
    • 7
  • s

    Sebastian Gug

    10/19/2022, 4:06 PM
    any ideas what the latest transaction syntax is supposed to be? looking at the docs there's
    Copy code
    prisma.$transaction(async (tx) => {
    but this throws a type error now
    Argument of type '(tx: any) => void' is not assignable to parameter of type 'PrismaPromise<any>[]'
    what even is a PrismaPromise? and if it's an array, how am I supposed to benefit from the result of one of those operations for incrementing purposes?
    ✅ 1
    n
    • 2
    • 1
  • s

    Sebastian Gug

    10/19/2022, 4:07 PM
    ah I have to enable preview features, found an SO thread
    👌 2
  • a

    Alex Vilchis

    10/19/2022, 4:55 PM
    Hello 👋 Is there a way to obtain the ids of the records I create with
    createMany
    ? Something like this:
    Copy code
    const result = await prisma.payment.createMany({
      data: [...]
    });
    
    const createdPayments = await prisma.payment.findMany({
      where: {
        id: {
          in: result.ids, // THIS IS NOT POSSIBLE
        },
      },
    });
    Any possible workarounds?
    ✅ 1
    t
    n
    • 3
    • 6
  • g

    Gerardo Gomez

    10/19/2022, 6:37 PM
    Hello! I’ve seen rumblings of this in outdated github issues and there seems to be a thread here on slack but i wanted to confirm. I am trying to get the generated SQL that prisma creates, is there a
    toSQL()
    function? I’ve seen other ORMs that have this functionality. I don’t need to log this query (I saw that functionality) I need the raw statement at the moment the code is run
    👀 1
    k
    t
    • 3
    • 3
  • v

    Vivek Yadav

    10/19/2022, 8:56 PM
    Hi guys, Is there any way sort a table on the basis of nested tables field. e.g.: Table: user username, age, sex post post[] Table: post title published author Author Table: Author name city Now want get all users (including fields of posts and author) sorted by city of Author Can we do it with the help of prisma and graphql query?
    👀 1
    r
    v
    • 3
    • 2
  • s

    Sebastian Gug

    10/20/2022, 12:14 AM
    Could I just delete all my existing migrations after going through the development phase? it seems a bit stupid to apply sequentially all the stupid ways I've modified the data throughout development to the end production DB, is there any downside, possible pitfall with doing this?
    ✅ 1
    t
    n
    • 3
    • 4
  • k

    Kenny Tran

    10/20/2022, 5:33 AM
    Hey, is it possible to use
    aggrigate
    to sum up a field within a relation query. Have a look at the my query below -
    const profiles = await prisma.profile.findMany({
    include: {
    offer: true,
    meeting: true,
    sale: true
    },
    orderBy: {
    points: "desc"
    },
    take: 10
    })
    I want to get the sum of offer, meeting and sale, Individually
    ✅ 1
    t
    • 2
    • 2
  • d

    DuckyDev

    10/20/2022, 7:08 AM
    Hi There. I’m still considering Prisma for my next big project with NestJS. However, I’m required to connect to at least to databases, how well will Prisma handle this?
    ✅ 1
    r
    • 2
    • 5
  • j

    james tan

    10/20/2022, 7:40 AM
    hi guys, anyone got a solution to mongodb serverless automatic closed connection? it seems to cause broken pipe error
    👀 1
    n
    v
    • 3
    • 5
  • a

    Andy Pickler

    10/20/2022, 10:02 AM
    I was seeing some issues around not getting stack traces logged properly when a PrismaClientInitializationError was thrown (I expected the error, because my local database hadn’t been started). I noticed in the source for this Error that I don’t think it is being constructed properly: source:
    Copy code
    constructor(message: string, clientVersion: string, errorCode?: string) {
        super(message)
        this.clientVersion = clientVersion
        this.errorCode = errorCode
        Error.captureStackTrace(PrismaClientInitializationError)
      }
    • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#custom_error_types • https://nodejs.org/dist/latest-v16.x/docs/api/errors.html#errorcapturestacktracetargetobject-constructoropt what I believe is correct:
    Copy code
    constructor(message: string, clientVersion: string, errorCode?: string) {
        super(message)
        this.clientVersion = clientVersion
        this.errorCode = errorCode
        Error.captureStackTrace(this, PrismaClientInitializationError)
      }
    I am up for contributing a PR, but first I am curious if there was an intentional design around capturing the stack trace in this manner.
    ✅ 1
    n
    v
    • 3
    • 9
  • m

    Marek Brzeziński

    10/20/2022, 10:47 AM
    Hi all! Noob question here. Given that: 1. I have a basic Prisma schema for users and auth with database in place 2. I want to import completely unrelated data to my database (sports data) Can I import data to my existing prisma managed database and use
    prisma db pull
    to automatically update schema with the imported data tables? 🤔
    ✅ 1
    t
    r
    +2
    • 5
    • 5
  • s

    Sebastian Gug

    10/20/2022, 11:22 AM
    let's say I apply a prisma migration in a github actions workflow --- would you do it before the successful deployment of the services or after? can't see an effective way of doing this without causing some downtime, it would be ideal if I could call an endpoint to a running 'super/bastion' service to apply the migrations from within a VPC
  • s

    Sebastian Gug

    10/20/2022, 11:25 AM
    Copy code
    const {execSync} = require('child_process');
    
    let output = execSync('npx prisma migrate');
    this seems uhhh, a bit hacky for some reason
    👀 1
    n
    • 2
    • 1
  • d

    Dan Calise

    10/20/2022, 1:11 PM
    Hey everyone, I am using Prisma with Next.js and an SQLite database. I’m having a lot of trouble with the DateTime data. If I define the field in the schema using the
    DateTime
    type, I see this when making my query:
    Copy code
    Inconsistent column data: Conversion failed: input contains invalid characters
    I also try defining it as a string to see if I could just get the raw string output of
    7/28/22 4:56:51 PM
    , that didn’t work. I tried adding it as an unsupported type and using
    queryRaw
    , but I get:
    Copy code
    Invalid `prisma.$queryRaw()` invocation:
    
    
    Raw query failed. Code: `N/A`. Message: `N/A`
    Any ideas? edit: I ran the same sql query directly on the db to make sure the sql was valid and it worked just fine.
    r
    • 2
    • 28
  • m

    mazhar iqbal

    10/20/2022, 1:15 PM
    Hello all I have a schema as model Business { id String @id @default(uuid()) name String } model Role { id String @id @default(uuid()) name String business Business? @relation(fields: [business_id], references: [id]) business_id String? @@unique([business_id, name]) @@map("role") } I have a scenario to add roles with business OR without business. How this can be achieved with upsert. I have tried to run below query, but it returns error. error screenshot attached as well await prisma.role.upsert({ where: { business_id_name: { business_id: null, name: 'Owner' } }, update: {}, create: { business_id: null, name: 'Owner', }, });
    r
    • 2
    • 4
  • a

    Alban Kaperi

    10/20/2022, 2:04 PM
    Hi all
  • a

    Alban Kaperi

    10/20/2022, 2:04 PM
    I am trying to make a query between a range of date but it freezes
  • a

    Alban Kaperi

    10/20/2022, 2:05 PM
    Copy code
    where: {
        day: {
            gte: new Date('2022-10-20'),
            lte: new Date('2022-10-25'),
        },
    },
1...633634635636637Latest