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

    Clément Guibout

    08/13/2022, 2:27 PM
    But when using prisma.event.create() with the data, it works only one time, then it throws an error: Unique constraint failed on the fields: (
    evt_id
    )
  • c

    Clément Guibout

    08/13/2022, 2:28 PM
    I can't figure out why... And I have another model using the exact same column type and it works without any issue Did I missed something ?
    ✅ 1
    r
    • 2
    • 18
  • d

    Dor Meiri

    08/13/2022, 8:19 PM
    Hi all, is there any way using aggregation function on a computed value? for example:
    Copy code
    SELECT AVG(LENGTH(value)) FROM Word
    Maybe something similar to
    Copy code
    prisma.word.aggregate({
        _avg: { value: { length: true } }
    });
    👀 1
    r
    • 2
    • 4
  • n

    Nurul

    08/16/2022, 9:13 AM
    Continuing conversation here: https://prisma.slack.com/archives/CA491RJH0/p1660640566629239?thread_ts=1660249957.343099&cid=CA491RJH0
  • n

    Nurul

    08/16/2022, 9:13 AM
    Continuing conversation here: https://prisma.slack.com/archives/CA491RJH0/p1660640566629239?thread_ts=1660249957.343099&cid=CA491RJH0
  • r

    Rain

    08/14/2022, 7:13 PM
    Hi guys, I want to update a record and update to new related records in a single call. I saw that we can use
    set: []
    to disconnect all related records. Will this work ?
    Copy code
    prisma.user.create({ 
    data: { 
      name: 'test', 
      likes: { 
       set: [], 
       connect: [{ name: 'a'}, {name: 'b'}]
      }
    });
    ✅ 1
    r
    • 2
    • 5
  • c

    Christoffer

    08/14/2022, 8:10 PM
    hey guys! I am trying to implement an AuthProvider model for our postgres prisma schema. You can see the start of my work here:
    Copy code
    model AuthProvider {
      id String @id @default(cuid())
    
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    
      type           AuthProviderType 
      externalUserId String?          @unique 
    
      email         String  @unique // this should not be unique if the userId is the same among two AuthProviders
      emailVerified Boolean? @default(false) 
    
      password String? // Hashed password
    
      user   User   @relation(fields: [userId], references: [id])
      userId String
    
      @@map("auth_providers")
    }
    A user can have many authentication providers, such as email + password, google, twitter... that they can use to sign in with Now here comes the tricky part: what I want to accomplish is to make it so an AuthProviders email is unique, but ONLY if the userId of that AuthProvider is different. So a user should be able to have several AuthProviders with the same email, but if one user tries to connect an authprovider with an email that another user already has connected (on any of their authproviders), then it should fail via unique constraint. would this be achieveable just using uniuqe constraints/indexes in the schema?
    👀 1
    n
    v
    • 3
    • 2
  • n

    nick

    08/14/2022, 9:19 PM
    ------
  • n

    nick

    08/14/2022, 9:19 PM
    hiya, is there a way to load a single relationship from a has_many relationship?
    ✅ 1
    n
    • 2
    • 1
  • n

    nick

    08/14/2022, 9:51 PM
    so if a User has many Posts, I want to do
    include: { posts: true}
    on a user query but I only want the first post in the returned posts array, any way to do this?
    ✅ 1
    n
    r
    • 3
    • 2
  • d

    Doron Roberts-Kedes

    08/14/2022, 11:37 PM
    How is this example of session data middleware from the documentation accessing the session context? The example code just puts it in some magic global variable, but that's not realistic. I'd let to get the tenant id from my graphql context and us it in middleware to scope queries to the tenant. My use case seems very analogous to the example, but a real-world version of the example seems impossible based on what I've read about the middleware API so far. Any tips of achieving this?
    ✅ 1
    a
    • 2
    • 5
  • a

    Aladin

    08/14/2022, 11:53 PM
    This is related to the question above 👆 , I think Prisma should allow the removal of middleware, so that we can do something like: • Start of the HTTP request •
    prisma.$use(someMiddlewareWithAccessToRequest)
    • Process the request •
    prisma.$unuse(someMiddlewareWithAccessToRequest)
    • Return the response This will allow people to define context and request aware middleware
    ✅ 1
    n
    • 2
    • 1
  • s

    Samrith Shankar

    08/15/2022, 4:28 AM
    Hello, I am trying to set a custom path for the query engine library in my lambda. I have set it like so:
    Copy code
    PRISMA_QUERY_ENGINE_LIBRARY=/opt
    And when I
    Copy code
    ls /opt
    I get the following output:
    Copy code
    libquery_engine-rhel-openssl-1.0.x.so.node
    But when I run the lambda I still get error:
    Copy code
    "Runtime.UnhandledPromiseRejection: Error: Query engine library for current platform \"linux-arm64-openssl-1.0.x\" could not be found.",
            "You incorrectly pinned it to linux-arm64-openssl-1.0.x",
            "",
            "This probably happens, because you built Prisma Client on a different platform.",
            "(Prisma Client looked in \"/var/task/src/libquery_engine-linux-arm64-openssl-1.0.x.so.node\")",
            "",
            "Searched Locations:",
            "",
            "  /.prisma/client",
            "  /var/task",
            "  /var/task/src",
            "  /var/task/src",
            "  /tmp/prisma-engines",
            "  /var/task/src",
            "",
            "You already added the platforms \"darwin\", \"linux-arm64-openssl-1.0.x\" to the \"generator\" block",
            "in the \"schema.prisma\" file as described in <https://pris.ly/d/client-generator>,",
            "but something went wrong. That's suboptimal.",
            "",
            "Please create an issue at <https://github.com/prisma/prisma/issues/new>",
            "    at process.<anonymous> (file:///var/runtime/index.mjs:775:15)",
            "    at process.emit (node:events:527:28)",
            "    at emit (node:internal/process/promises:140:20)",
            "    at processPromiseRejections (node:internal/process/promises:274:27)",
            "    at processTicksAndRejections (node:internal/process/task_queues:97:32)"
    Any idea what am I missing? EDIT: Switching engine type to
    binary
    and uploading the binary, worked!
    ✅ 1
  • o

    Oleksii

    08/15/2022, 6:42 AM
    Hey 👋 Quick question: do I need to create an account with Prisma to use Prisma ORM in full?
    ✅ 1
    n
    • 2
    • 2
  • s

    Slackbot

    08/15/2022, 6:53 AM
    This message was deleted.
    r
    • 2
    • 1
  • a

    Adrien Wald

    08/15/2022, 10:05 AM
    heyo! when doing an interactive transaction is it necessary to use the
    prisma
    instance made available in the callback or can you use the
    prisma
    instance on which you called
    $transaction
    ?
    ✅ 1
    n
    • 2
    • 2
  • s

    Shamim Fahad

    08/15/2022, 10:54 AM
    hi, I was trying to create a migration where I changed the type of id from String to BigInt but I'm getting this error
    Error: P3006
    Migration
    20220815103305_product_and_order_incremental_id
    failed to apply cleanly to the shadow database. Error: db error: ERROR: value type string doesn't match type int of column "id" HINT: you will need to rewrite or cast the expression 0: sql_migration_connector::validate_migrations at migration-engine/connectors/sql-migration-connector/src/lib.rs:270 1: migration_core:state:DevDiagnostic at migration-engine/core/src/state.rs:250 can anyone help me about what I should do?
    👀 1
    r
    a
    • 3
    • 9
  • s

    Shamim Fahad

    08/15/2022, 10:55 AM
    I've also checked that, all the references for those columns have been changed from String to BigInt in the schema
    👀 1
  • r

    Richard

    08/15/2022, 1:51 PM
    Any prisma/mongo meetups in Berlin? I missed prisma day in June :(
    ✅ 1
    n
    • 2
    • 4
  • g

    Geebrox

    08/15/2022, 2:29 PM
    Copy code
    Invalid `prisma.user.upsert()` invocation:
    
    
      Error occurred during query execution:
    ConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: "unknown", message: "Command failed (WriteConflict): WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.)" } })
    What does it mean?
    ✅ 1
    n
    r
    • 3
    • 19
  • f

    Fishie

    08/15/2022, 3:17 PM
    https://github.com/prisma/prisma/discussions/14812 can anyone help me with this pls
    ✅ 1
    n
    • 2
    • 1
  • o

    Oleksii

    08/15/2022, 4:59 PM
    Any tips on using Prisma with Supabase?
    ✅ 1
    n
    • 2
    • 1
  • d

    Doron Roberts-Kedes

    08/15/2022, 5:11 PM
    What is the nature of Prisma's dependency on
    async_hooks
    ? Follow up question - can it be circumvented? I'm assuming the answer to the second question is "no". The reason I'm asking is because I'm attempting to migrate my app off of Meteor by incrementally adopting Prisma to replace Meteor collections. Meteor, unfortunately, uses fibers and can lead to memory leaks when used with
    async_hooks
    . We could move forward with one massive commit that introduces Prisma and removes Meteor, but incremental adoption would be preferable. Incremental adoption poses the problem of adding
    async_hooks
    into a Meteor environment, which leads to my questions above. Thanks!
    ✅ 1
    n
    • 2
    • 1
  • a

    Aman

    08/15/2022, 7:37 PM
    This is my database schema
    model User {
    id           Int          @id @default(autoincrement())
    auth0Id      String?      @unique
    authEmail    String?      @unique
    email        String       @unique
    name         String?
    companyData  CompanyData?
    }
    model CompanyData {
    id      Int  @id @default(autoincrement())
    owner   User @relation(fields: [ownerId], references: [id])
    ownerId Int  @unique
    capTable           CapTable?
    }
    model CapTable {
    id Int @id @default(autoincrement())
    stakeholder     Stakeholder[]
    stockClass      StockClass[]
    vestingTerm     VestingTerm[]
    transactions    Transactions[]
    companyData     CompanyData @relation(fields: [companyId], references: [id])
    companyId Int   @unique
    }
    model ConvertibleTransactions {
    id Int @default(autoincrement()) @unique
    json  Json?
    transactions Transactions?
    }
    model SecurityTransactions {
    id Int @default(autoincrement()) @unique
    json  Json?
    transactions Transactions?
    }
    model WarrantsTransactions {
    id Int @default(autoincrement()) @unique
    json  Json?
    transactions Transactions?
    }
    model Transactions {
    id Int @default(autoincrement()) @unique
    convertibleTransactions     ConvertibleTransactions? @relation(fields: [convertibleTransactionId], references: [id])
    convertibleTransactionId Int  @unique
    securityTransactions     SecurityTransactions? @relation(fields: [securityTransactionId], references: [id])
    securityTransactionId Int  @unique
    warrantsTransactions     WarrantsTransactions? @relation(fields: [warrantsTransactionId], references: [id])
    warrantsTransactionId Int  @unique
    capTable          CapTable?         @relation(fields: [capTableId], references: [id], onDelete: Cascade)
    capTableId        Int?
    }
    and this is my prisma query
    await prisma.user.update({
    where: {
    id: userData.id,
    },
    data: {
    companyData: {
    update: {
    capTable: {
    update: {
    transactions: {
    update: {
    convertibleTransactions: {
    upsert: {
    create: {
    json: data,
    },
    update: {
    json: data,
    },
    where: {
    id: data?.id || -1,
    },
    },
    },
    // where: {
    //   convertibleTransactionId: data.convertibleId || -1,
    // },
    },
    },
    },
    },
    },
    },
    }, ,
    });
    can someone help me with what I am doing wrong here
    ✅ 1
    n
    • 2
    • 1
  • t

    Ted Joe

    08/15/2022, 7:39 PM
    When running
    yarn rw prisma migrate deploy
    , I get an error saying:
    Copy code
    1 migration found in prisma/migrations
    
    Error: P3005
    
    The database schema is not empty. Read more about how to baseline an existing production database: <https://pris.ly/d/migrate-baseline>
    What am I doing wrong and how can I fix it?
    👀 1
    n
    v
    • 3
    • 2
  • i

    Italo Gama

    08/15/2022, 10:39 PM
    Hey guys, i need some help with this
  • i

    Italo Gama

    08/15/2022, 10:39 PM
  • i

    Italo Gama

    08/15/2022, 10:40 PM
    this is my DTO
  • i

    Italo Gama

    08/15/2022, 10:40 PM
  • i

    Italo Gama

    08/15/2022, 10:41 PM
    and this is the dto generated, i dont know why doesnt have a “spouse_id” on it, just “spouse”
1...608609610...637Latest