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

    Jonathan Marbutt

    02/09/2022, 9:06 PM
    When I try to set a default to to a timestamp I always get an error:
    Copy code
    DateTime?                @db.Timestamp(6)
    a
    • 2
    • 6
  • j

    Jonathan Marbutt

    02/09/2022, 9:06 PM
    what is the correct way to set a default for this type on postgres?
  • j

    Jonathan Marbutt

    02/09/2022, 9:06 PM
    I can set the value as
    new Date()
    in the code but I would like to do a default, when I try to use
    @db.default(now())
    it doesn’t work
    t
    • 2
    • 2
  • g

    genedy

    02/09/2022, 9:45 PM
    hi everybody , my name is eslam genedy , I am a full stack developer . and I am searching for an open source under prisma organization to contribute .
  • g

    genedy

    02/09/2022, 9:46 PM
    Is there any channel that can help me in that ?
  • d

    Dan M

    02/09/2022, 11:47 PM
    I'm trying to do something like this:
    Copy code
    const usage = await prisma.nation.findUnique({
        select: {
            _count: {
                select: {
                    locales: true,
                    transitsOriginatingFromThisNation: true,
                    transitsDestinedForThisNation: true,
                    conflicts: { where: { isUserEntered: true } },
                },
            },
        },
        where: { id },
    });
  • d

    Dan M

    02/09/2022, 11:48 PM
    The part that doesn't work is the
    where
    clause on
    conflicts
    How do you do a where clause within aggregate count?
  • t

    Tyler Clendenin

    02/10/2022, 12:49 AM
    Is there any way to take a Prisma WhereInput object and get the SQL for it so that I can use it in a raw query?
  • m

    Michael Aubry

    02/10/2022, 1:35 AM
    https://prisma.slack.com/archives/CA491RJH0/p1644377499536349 I should be more clear here. I am using prisma-nexus and am working on a new project. Everything seems normal and is similar to an existing code base. When I issue a mutation and implicitly make a connection to the user model it seems to create two records for some reason. I have no clue how to debug this.
    n
    • 2
    • 8
  • b

    Brothak

    02/10/2022, 8:23 AM
    Hi I am getting a conflicting message after running prisma migrate dev on existing production database:
    Copy code
    [*] Changed the `addresses` table
      [-] Removed foreign key on columns (entity_id)
      [+] Added foreign key on columns (entity_id)
    
    [*] Changed the `entity_metadata` table
      [-] Removed foreign key on columns (tag_id)
      [+] Added foreign key on columns (tag_id)
    j
    • 2
    • 10
  • b

    Brothak

    02/10/2022, 8:24 AM
    It’s saying that I removed and added same foreign key on the same column?
  • j

    Jonas

    02/10/2022, 8:25 AM
    Is there a way to skip certain generators when running
    prisma migrate
    ?
    j
    • 2
    • 6
  • u

    user

    02/10/2022, 9:47 AM
    Tips for Content Creation by DevRel - Part 2 #shorts

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

    📷 If you're looking to improve your content, or are considering starting to create content, follow these tips from a developer relations perspective! 👀 #shorts #prisma #tipsforcontent
  • n

    Nathaniel Babalola

    02/10/2022, 10:18 AM
    I am tired, Prisma has been throwing this error when I try to deploy migrations. Please any help ?
  • n

    Nathaniel Babalola

    02/10/2022, 10:19 AM
    Can't reach database Context: Time out trying to acquire postgres advisory lock
  • f

    Florian

    02/10/2022, 10:23 AM
    Hello ☀️ I have this kind of models in my schema
    Copy code
    model Something {
      id        String     @id @default(dbgenerated("nanoid(\'SMTH_\')"))
      createdAt DateTime   @default(now())
      updatedAt DateTime   @updatedAt
    
      ....other fields....
    }
    (All of them have that default dbgenerated thing for the
    id
    column)
    Whenever I try to do a migration using
    prisma migrate dev
    the tool keeps trying to add the following SQL to the migration for all the tables:
    Copy code
    ALTER TABLE "something" ALTER COLUMN "id" SET DEFAULT nanoid('SMTH_');
    Even though it has been correctly set on the initial migration:
    Copy code
    CREATE TABLE "something" (
        "id" TEXT NOT NULL DEFAULT nanoid('SMTH_'),
        "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
        "updatedAt" TIMESTAMP(3) NOT NULL,
    
        CONSTRAINT "something_pkey" PRIMARY KEY ("id")
    );
    I keep removing them by hand, but is it possible for it not to create that everytime? 😄 Btw, I'm using
    prisma@3.9.1
    with
    postgres:10.13
    , I can't tell if it happened on previous versions, I did my setup this week 😄
  • m

    Mishase

    02/10/2022, 10:36 AM
    Hello. Is there any way to make prisma do only one query when querying from two tables?
    Copy code
    // prisma:query SELECT "public"."Session"."token", "public"."Session"."userId" FROM "public"."Session" WHERE "public"."Session"."token" = $1 OFFSET $2
    // prisma:query SELECT "public"."User"."id" FROM "public"."User" WHERE "public"."User"."id" IN ($1) OFFSET $2
    await prisma.session.findUnique({
    	select: {
    		user: { select: { id: true } },
    	},
    	where: {
    		token,
    	},
    });
    Copy code
    // prisma:query SELECT "public"."User"."id" FROM "public"."User" WHERE "public"."User"."id" IN ($1) OFFSET $2
    // prisma:query SELECT "public"."Session"."token", "public"."Session"."userId", "public"."Session"."createdAt" FROM "public"."Session" WHERE "public"."Session"."token" = $1 OFFSET $2
    await prisma.session.findUnique({
    	include: {
    		user: { select: { id: true } },
    	},
    	where: {
    		token,
    	},
    });
    Copy code
    // prisma:query SELECT "User".id FROM "User" WHERE "User".id = (SELECT "Session".userId FROM "Session" WHERE "Session".token = $1)
    await prisma.$queryRaw`SELECT "User".id FROM "User" WHERE "User".id = (SELECT "Session"."userId" FROM "Session" WHERE "Session".token = ${token})`;
    Copy code
    // prisma:query SELECT "User".id FROM "User" LEFT JOIN "Session" ON "User".id = "Session"."userId" WHERE "Session".token = $1
    await prisma.$queryRaw`SELECT "User".id FROM "User" LEFT JOIN "Session" ON "User".id = "Session"."userId" WHERE "Session".token = ${token}`;
  • j

    Josef Henryson

    02/10/2022, 1:23 PM
    We have a problem when our server restart due to maintenance etc, prisma client starts up before MySQL has finished starting up und thus causes error. We have resolved this by manually restarting the web server. But we want to find out if there is a way to configure prisma client to reconnect to MySQL if it initially fails to connect. Any ideas? @nikolasburk
  • m

    Matheus Assis

    02/10/2022, 1:24 PM
    Since
    createMany
    doesn't allow us to create the relations. What I'm doing is to first call
    createMany
    for the "base" write, and then I get the recently created ids with
    findMany
    and then call
    createMany
    again for each of the relations. The problem with this is that if some of the relations fail, the previous writes still exists. So I need to manually delete them in this case, and even this is not perfect, because while one of the elements on the createMany may have failed, not all of them would. I was planning on using a transaction but I saw that it doesn't help me in this case. What would be the best practice to do this then? Manually loop through each record and use nested write instead, and not do batches with createMany? But then it'd take a looong time instead. Is there a different solution?
    a
    • 2
    • 5
  • j

    Jonathan Marbutt

    02/10/2022, 3:21 PM
    We continue to get
    Timed out fetching a new connection from the connection pool. More info: <http://pris.ly/d/connection-pool> (Current connection pool timeout: 10, connection limit: 3)
    on a project that has the connection string with the connection pool to 100. And we are verifying that when the app starts up. It is a nestjs app running on Azure connecting to an AWS Aurora database. We have another project that is almost identical that is not having this issue. They share the same prisma client library. We are trying to get this to production ready but have no idea why this continues to happen
    n
    • 2
    • 7
  • v

    VR

    02/10/2022, 6:44 PM
    Hello team, we would like to migrate lookup data from one db environment to other environments as part of Prisma model migration CI/CD pipeline, Can you suggest how to achieve that?
  • a

    Alonso A.

    02/10/2022, 7:50 PM
    What application is everyone using to keep track of learning, notes, code, work etc?
    t
    • 2
    • 2
  • l

    Logan

    02/10/2022, 8:39 PM
    Hey. I want to run a weekly cleanup job on our database to get rid of some data from clients which no longer use our services. Because we have many tables, and more are being added regularly is there a good way of looping through every table without having to add hard coded values? I am using prisma client with TS
    ✅ 1
    n
    • 2
    • 2
  • m

    Mo El

    02/11/2022, 12:31 AM
    Can prisma do a o:m and a o:o on the same models? Especially with a sort would be great
    n
    • 2
    • 1
  • γ

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

    02/11/2022, 5:35 AM
    How can I add a resolver at
    objectType
    level at nexus?
  • u

    user

    02/11/2022, 8:31 AM
    GraphQL Berlin Meetup #25 - Matteo Collina - GraphQL caching demystified

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

    ◭ How would you implement a performant GraphQL cache? How can we design a good algorithm for it? Is there a good Open Source solution that is efficient, scalable, and easy to deploy? How is the caching key computed? What about cache invalidations? Would it be possible to deduplicate resolver execution? This might be seen as daunting but in reality is all code and algorithms. In this talk we are going to walk through a GraphQL caching system that we have developed for Mercurius - one of the fastest GraphQL servers for Node.js. ◭ Matteo is Chief Software Architect at NearForm, where he consults for the top brands in the world. In 2014, he defended his Ph.D. thesis titled "Application Platforms for the Internet of Things". Matteo is a member of the Node.js Technical Steering Committee focusing on streams, diagnostics and http. He is also the author of the fast logger Pino and of the Fastify web framework. Matteo is an renowed international speaker after more than 60 conferences, including Node.js Interactive, NodeConf.eu, NodeSummit, JSConf.Asia, WebRebels, and JsDay just to name a few. He is also co-author of the book "Node.js Cookbook, Third Edition" edited by Packt. In the summer he loves sailing the Sirocco. ◭ Get in touch with Matteo: https://twitter.com/matteocollina ◭ Join our GraphQL Berlin Meetup group: https://www.meetup.com/graphql-berlin
    prisma cool 1
    prisma rainbow 3
  • m

    Michael Aubry

    02/11/2022, 4:30 PM
    Following up on this, does anything seem unusual on my end? https://prisma.slack.com/archives/CA491RJH0/p1644456913167959
  • m

    Michael Aubry

    02/11/2022, 5:13 PM
    Im using the new data proxy service and the cloud service. I have to say its amazing! Ive been needing data proxy for motionbox.io for a while. I suspect many issues with uploading files, etc have been due to latency. This should reduce so many bugs! Thanks
  • j

    Jessica Otte

    02/11/2022, 6:35 PM
    I'm having an issue with queryRaw, where my date is returning as a string. Am I doing something wrong? • Column defined like
    effectiveDate  DateTime? @map("effective_date") @db.Date
    • Query looks like
    Copy code
    const courses: Course[] = await prisma.$queryRaw<Course[]>`
        SELECT
          id,
          course_number,
          effective_date as "effectiveDate",
          ....
    But if I try and do effectiveDate.getDate() or something, I get a runtime error; and if I console.log
    typeof effectiveDate
    , it tells me that it's a string. If I do my query using
    prisma.findMany
    , it works fine. I do see in the docs it says
    Type caveats when using raw SQL: When you type the results of $queryRaw, the raw data does not always match the suggested TypeScript type.
    So, is it expected behavior that the date returns as a string, or am I doing something wrong? And if it matters,
    prisma --version
    gives me
    Copy code
    prisma                  : 3.0.1
    @prisma/client          : 3.7.0
    Current platform        : windows
  • j

    Jorge

    02/11/2022, 7:02 PM
    hello how to run
    prisma migrate deploy
    programmatically ?
1...544545546...637Latest