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

    Pranav Sathyanarayanan

    06/02/2021, 7:42 PM
    Hmm, was there some breaking change to how template strings are implemented for
    queryRaw
    in Prisma 2.23.0?
    Copy code
    await prisma.$queryRaw(`
        SELECT c."uuid", c."createdAt"
        FROM "EmploymentRecord" AS er
        JOIN "User" AS u ON (u."uuid" = er."userUuid")
        JOIN "Company" AS c ON (c."uuid" = er."companyUuid")
        WHERE er."endDate" IS NULL
        AND LOWER(u."email") IN (${Array.from(prodUserEmails)
          .map((email) => `'${email}'`)
          .join(', ')})
        GROUP BY c."uuid", c."createdAt"
        ORDER BY c."createdAt" ASC;
      `);
    The query above works perfectly and returns my several hundred rows, but:
    Copy code
    await prisma.$queryRaw`
        SELECT c."uuid", c."createdAt"
        FROM "EmploymentRecord" AS er
        JOIN "User" AS u ON (u."uuid" = er."userUuid")
        JOIN "Company" AS c ON (c."uuid" = er."companyUuid")
        WHERE er."endDate" IS NULL
        AND LOWER(u."email") IN (${Array.from(prodUserEmails)
          .map((email) => `'${email}'`)
          .join(', ')})
        GROUP BY c."uuid", c."createdAt"
        ORDER BY c."createdAt" ASC;
      `;
    Does not. I know I am manually string quoting my values, but not sure how else to perform an
    IN
    with
    queryRaw
    • 1
    • 1
  • j

    John Egan

    06/02/2021, 8:31 PM
    Hi all-- I'm working on using
    prisma migrate deploy
    with a Vercel deployment workflow + digital ocean pooled postgresql db & pgbouncer and can't quite figure out the right way to define a different DATABASE_URL to run during build time vs. runtime (in order to point to the non-pgbouncer URL during migrations at build time). It looks like Vercel exposes the "CI" env variable during build time which I thought would be helpful but is there a way to include a conditional in the schema.prisma file to react to this? Something like the following (which does not work for obvious reasons)?
    Copy code
    datasource db {
      provider = "postgresql"
      url      = env("CI") ? env("DATABASE_URL_NOPGBOUNCER") : env("DATABASE_URL")
    }
    Thanks!
    šŸ’š 1
    o
    g
    • 3
    • 9
  • m

    Mattia Romeo

    06/02/2021, 9:33 PM
    I think I'm missing something about how migrations are supposed to be used. Specifically I don't understand why to update my schema during development I need to point prisma to a running database instance. I get that
    migrate deploy
    needs to point to an actual database instance but why does
    migrate dev
    ? To do its work it just needs the schema and the list of previous migrations, no?
    s
    • 2
    • 20
  • y

    YErii

    06/03/2021, 8:11 AM
    is there any limitation for
    notIn
    operator? for example we have 5 users, 3 is in the condition and 2 is not. if we execute
    prisma.user.findMany({where: {notIn: [...]}})
    will return 7 result. the above is to clarify the problem and the real count may be 5000 items in
    notIn
    clause which returns wrong result. But
    prisma.user.count(...)
    and
    prisma.user.findMany({where: {NOT: {in: []}}})
    are ok
  • y

    YErii

    06/03/2021, 8:34 AM
    I have logged the sql for query like above. prisma will split
    notIn
    clause to 5000 per chunk and merge each result which result in the wrong total count results
  • y

    YErii

    06/03/2021, 8:36 AM
    For
    In
    cluase, the merge of each chunk is ok. And for
    {NOT: { in: [] } }
    it will not split params to chunks. So both of this situation are ok.
  • y

    YErii

    06/03/2021, 8:45 AM
    Copy code
    const v = await prisma.user.findMany({
        where: {id: {notIn: Array.from({length: 6000}, (v, idx) => idx.toString())}}
      })
      const total = await prisma.user.findMany({
        where: {}
      })
      console.log(v.length, total)
    this should reproduct the problem.
    r
    • 2
    • 14
  • s

    Swapnull

    06/03/2021, 9:39 AM
    Hey! I am currently doing something like
    Copy code
    const lastLesson = await db.lesson.findFirst({ where: { date: { gt: new Date() } }});
    but I have a field called
    lesson.duration
    . So I would ideally want to do only get it if the duration has passed, maybe something like this
    Copy code
    const lastLesson = await db.lesson.findFirst({ where: { date: { gt: addMinutes(new Date(), 
    this.duration) } }});
    basically can I get the where to know context about the current row somehow so it can know what the duration is while checking, rather than having to loop? Is this possible?
    m
    r
    • 3
    • 12
  • m

    manuel

    06/03/2021, 10:09 AM
    hey! is there a recommended way how to know which versions of nexus and prisma work together? Because I guess I can't update to the latest prisma version right?
    r
    • 2
    • 2
  • p

    Patrick

    06/03/2021, 10:54 AM
    Is it possible to set those query param options outside connection URL? For example as separate variable in prisma.schema file?
    r
    j
    • 3
    • 3
  • d

    Dan Shapir

    06/03/2021, 11:15 AM
    Can I use relations when I have two different schema files in two different projects?
    r
    • 2
    • 2
  • s

    Swapnull

    06/03/2021, 3:05 PM
    Hey! Second question in a day! Has anybody figured out how to keep Algolia and prisma/postgres in sync? I tried writing some middleware a while ago which was like https://gist.github.com/Swapnull/9a88e7b9df1db7a68711728394717355 , but it feels pretty crappy having to write a function for each model I want to put there. And that doesn’t even touch things like updating.
    j
    • 2
    • 1
  • j

    Jared Salzano

    06/03/2021, 7:16 PM
    How do Prisma users keep track of functions in their DB?
    o
    r
    • 3
    • 3
  • j

    Jose Maria CL

    06/03/2021, 7:41 PM
    Hi there. We are still using Prisma 1. I want to migrate to Prisma 2. I would like to know if there are performance benefits. What do you thing?
    j
    • 2
    • 2
  • b

    Bojan Å ernek

    06/03/2021, 8:38 PM
    hey prisma guys, is there a feature request open anywhere about typing Json fields, like maybe referencing a typescript file and type within it with an annotation
    šŸ‘ 1
    😮 1
    r
    • 2
    • 2
  • a

    aspect

    06/03/2021, 9:34 PM
    Hey everyone, so currently I'm trying to migrate our development database, and I'm getting an error every time I try to do so.

    https://i.imgur.com/5nguZhE.pngā–¾

    I've retried multiple times, nothing seems to work. Any help?
    r
    • 2
    • 1
  • d

    Dan Shapir

    06/03/2021, 10:03 PM
    When and how to run prisma migrate deploy? I can't run it from my CI/CD since it doesn't have access to the production Postgres (not part of the VPC and shouldn't be), so when should it be done? And how...?
    r
    • 2
    • 3
  • j

    jasci

    06/04/2021, 10:06 AM
    Hello everyone, I’m currently upgrading from prisma1 to prisma2, specifically wanted to move from prisma-binding to nexus. I see that there are 2 prisma plugins to use with nexus:
    nexus-plugin-prisma
    and
    nexus-prisma
    . As I understood I’d better use
    nexus-plugin-prisma
    in production, but wanted to ask how hard will it be to then replace it with the new
    nexus-prisma
    when it’s production ready ? I mean it seems like
    nexus-plugin-prisma
    is gonna be deprecated soon, but
    nexus-prisma
    is not ready, maybe it’s safer to wait until it’s ready and for now use SDL first ? Thank you.
    d
    • 2
    • 2
  • d

    Dev__

    06/04/2021, 1:10 PM
    is there any update on this?: https://github.com/prisma/prisma/issues/5040
    r
    • 2
    • 4
  • t

    Tharshan

    06/04/2021, 2:07 PM
    How is everyone handling slugs in urls? and the logic for when that slug changes? Are you making slugs unique in your model? Consider this scenario: • You create a task, and it has a title. You slugify that and make it unique. So when a user visits /task/{slug} - you can fetch that unique task and get that data. • But when a user changes the title - Do you update the slug? • What happens if that url with the old slug has been linked externally (e.g. on slack, on the web etc) - how do you handle fallbacks? is there best practices to make human friendly urls like this easier to handle?
    m
    • 2
    • 6
  • n

    Nimish Gupta

    06/04/2021, 6:27 PM
    Hello prisma team! Have a question with respect to prisma connections. How does prisma fetch a connection from connection pool? Context - I am using Postgres as DB and turned logging on. So in the following code snippet, prisma is fetching two connections from pool.
    Copy code
    // Node js
    // Fetched a connection from pool. --> (1)
    const firstQuery = await prisma.model.find();
    // Fetched a connection from pool. --> (2)
    const secondQuery = await prisma.model.find();
    So
    1
    and
    2
    statements are logged while calling these queries. Can you explain why second statement is logged? Prisma should use the same connection (connection used for performing first query), right?
    j
    • 2
    • 26
  • n

    Nimish Gupta

    06/04/2021, 6:28 PM
    Also can we log the current number of used connections?
    j
    • 2
    • 2
  • c

    Carlos Moreira

    06/04/2021, 10:43 PM
    Hello people Is it possible to make several micro-services communicate with a single instance of the Prisma Client? I'm asking this because the Prisma Client is consuming some considerable memory in each microservice, something that can be prevented if a single instance of the Prisma client is consumed. Instead of: M1 -> Prisma Client 1 M2 -> Prisma Client 2 M3 -> Prisma Client 3 M4 -> Prisma Client 4 I want to get something like: M1 -> Prisma Client 1 M2 -> Prisma Client 1 M3 -> Prisma Client 1 M4 -> Prisma Client 1
    d
    j
    • 3
    • 2
  • e

    esau

    06/05/2021, 12:48 AM
    Hey guys, just a quick question, is it normal behavior that I'm unable to update a one-to-one relationship on the required side? I'm sure that the update value is correct / unused. When I do, I get this error
    Copy code
    The change you are trying to make would violate the required relation...
    This may be a complete oversight but thanks in advance for the help! šŸ™‚
    j
    • 2
    • 5
  • e

    Eric Martinez

    06/05/2021, 1:42 AM
    Hey guys! I'm new here, learning about Prisma. Is this syntax still valid https://github.com/prisma/prisma/issues/2245#issuecomment-617038028 ?
  • e

    Eric Martinez

    06/05/2021, 1:42 AM
    I'm trying the following and it fails
  • e

    Eric Martinez

    06/05/2021, 1:43 AM
    Copy code
    const test = await this.prisma.proyecto.findMany({
          include: {
            owner: {
              where: {
                nombre: {
                  contains: 'asd'
                }
              }
            }
          }
        });
    Copy code
    Unknown arg `where` in include.owner.where for type Owner. Did you mean `select`? Available args:
    type owner {
    }
    d
    • 2
    • 3
  • a

    amaraa

    06/05/2021, 4:18 AM
    Prisma1 specially 1.34 with docker latest version on mac M1 no more supports? or wait for something and any ideas for it? Entire project move to Prisma2 I’m not sure also sounds are feel like a so costly. 🤧
    j
    • 2
    • 1
  • m

    Mohit Gupta

    06/05/2021, 7:51 AM
    Hey guys, is there a way to have composite primary keys defined in Prisma schema?
    d
    • 2
    • 2
  • т

    Тоше

    06/05/2021, 11:19 AM
    Is any of the following part of the prisma road map • adding aggregate to the fluent api and batch those requests, so they can be called from the parent model or • allowing aggregate queries to be batched regardless
    Copy code
    const User = objectType({
      name: 'User',
      definition(t) {
        <http://t.nonNull.int|t.nonNull.int>('id')
        t.string('name')
        t.nonNull.string('email')
        t.nonNull.list.nonNull.field('posts', {
          type: 'Post',
          resolve: (parent, _, context) => {
            return context.prisma.user
              .findUnique({
                where: { id: parent.id || undefined },
              })
              .aggregate(*some logic)
          },
        })
      },
    })
    r
    • 2
    • 1
1...438439440...637Latest