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

    Raphael Etim

    09/30/2022, 7:42 AM
    Hi @Vu Duong 👋 if you want to query by a single day (like 2006-01-23) or any other time frame, instead of a very specific time (like 2006-01-23T190000.000Z) you need to use a combination of
    gt/gte
    and
    lt/lte
    . For example.
    Copy code
    let result = await prisma.post.findMany({
        where: {
          updatedAt: {
            gte: '2020-03-19T00:00:00+00:00',
            lte: '2020-03-19T23:59:59+00:00'
          }
        }
      })
    👍 1
    v
    • 2
    • 4
  • d

    darksider

    09/30/2022, 8:22 AM
    My application and website dashboard are running separately, both sharing same database so how can I use Prisma for managing both?
    ✅ 1
    n
    j
    n
    • 4
    • 16
  • j

    Joey

    09/30/2022, 2:19 PM
    Had a question about multi column uniqueness. Is there any way to enforce uniqueness, only if both the properties have a value: Say I have a “Team” table with an optional
    organizationId String?
    field and a required
    name String
    field. Is there any way to enforce that two teams in the same organization don’t have the same name, BUT also allow many Teams with the same name if they’re not affiliated with an organization (organizationId = null)? So my goal would be : name: “joe”, orgId: null + name:“joe”, orgId:null === OK name: ’joe”, orgId: 1 + name:“joe”, orgId:2 === OK name: ’joe”, orgId: 1 + name:“joe”, orgId:1 === err: DUPLICATE I usually do
    @@unique([name, organizationId])
    , but i think this would cause the first example to fail when it shouldnt, bc both are null, but i want to allow that.
    👀 1
    ✅ 1
    n
    • 2
    • 4
  • j

    Jose Donato

    09/30/2022, 3:24 PM
    hello! is it possible to catch errors in case DATABASE_URL is not on env/DATABASE_URL is wrongly formatted? it just crashes the whole app even if i catch the error
    👀 1
    n
    v
    • 3
    • 4
  • d

    doddy nicolas

    09/30/2022, 3:45 PM
    hi prisma people , could you help me with this code? THANKS
    j
    v
    • 3
    • 8
  • a

    Anthony

    09/30/2022, 6:07 PM
    Hello! Prisma has very powerful TypeScript support, and we’d like to incorporate that in old current codebase where we’re using native
    pg
    (postgres) library to query with SQLs. We still want to reuse the connections created by
    pg
    , without setting up new connections by Primsa client. I’m wondering if this is possible and if it’s so, how can we do that?
    ✅ 1
    a
    • 2
    • 1
  • b

    Boo

    09/30/2022, 11:18 PM
    I'm confused why the
    NOT/not/notIn
    filter queries does not work on optional fields?
    👀 1
    n
    v
    • 3
    • 2
  • v

    ven v

    10/01/2022, 12:47 AM
    Hi guys - When a user signs up for the first time i dont have any information about them in my User table. So when they login for the first time my query looks at the user table for their authId and returns a null. Prisma throws a null error in the logs. how do i prevent this? How to handle a null return in a Prisma findUnique? my getter is below -
    Copy code
    export const getUser = (id) => {
        return prisma.User.findUnique({
            where: { authId: id },
        });
    };
    ✅ 1
    j
    j
    • 3
    • 11
  • r

    Ridhwaan Shakeel

    10/01/2022, 4:08 AM
    hi all I want a script that copies the database & data from one environment to a demo environment The snapshot & data need to be the same except for one column that needs to be random values or any arbitrary unique values How do you do that using prisma client js or snaplet? prisma connector is sqlite thanks
    ✅ 1
    j
    • 2
    • 7
  • g

    Grégory D'Angelo

    10/01/2022, 8:14 AM
    Hey, guys, @Sabin Adams @nikolasburk do you know if there is a way to access some Prisma-generated types of my schema, such as for the
    include
    or
    select
    ? I'm asking that because I'm wrapping my Prisma functions inside service functions for a Node.js project. Those functions accept
    include
    or
    select
    as arguments and I'd like to keep type-safety, but I'm not sure if it is actually possible or the best way to do it. Any advice or suggestions from what you've seen? Here's an example:
    Copy code
    export interface FindQuizzesByStatusInput {
      status: Status;
      take: number;
      after?: string | null;
      include?: { [key: string]: any }; // not great for type-safety!!!
    }
    
    export const findQuizzesByStatus = async (
      input: FindQuizzesByStatusInput
    ): Promise<Quiz[]> => {
      // ...
    }
    Thanks!
    ✅ 1
    j
    • 2
    • 5
  • s

    Slackbot

    10/01/2022, 10:52 AM
    This message was deleted.
  • d

    doddy nicolas

    10/01/2022, 10:54 AM
    this code still don't work
  • d

    doddy nicolas

    10/01/2022, 10:56 AM
    the data object is unknow for vscode
  • d

    doddy nicolas

    10/01/2022, 11:52 AM
    Copy code
    prisma.ts
    
    declare global {
        var prisma: PrismaClient; // This must be a `var` and not a `let / const`
      }
    
    import { PrismaClient } from '@prisma/client'
     let prisma: PrismaClient;
     if(process.env.NODE_ENV === 'production'){
        prisma = new PrismaClient();
    }
     else{
        if(!global.prisma){
            global.prisma = new PrismaClient();
        }
        prisma = global.prisma
    }  
     
    export default prisma;  
    
    
    
    
    graphl.ts
    
    import { createServer , createPubSub } from '@graphql-yoga/node'
    import { User } from '@prisma/client'
    import type { NextApiRequest, NextApiResponse } from 'next'
    import prisma from '../../lib/prisma'
    
    const schema = {schema: {
        typeDefs: /* GraphQL */ `
        
          type User {
            lname: String
            fname: String
         }
       
        type Mutation{
          addUser(lname: String, fname: String): User!
        }
        `,
        resolvers: {
        
             Mutation: {
             addUser: async(parent: any,_: any) => {
               return await prisma.user.create(
                data:{
                  lname:"coucou",
                  fname:"salut"
                }
           )}  
    
        },
        
      }
    }
    
    i just want to add a new user in graphql with prisma but the resolver don't work                  <https://github.com/doddynicolas/try-prisma.git>
    ✅ 1
    j
    v
    • 3
    • 3
  • d

    doddy nicolas

    10/01/2022, 11:56 AM
    no
    ✅ 1
    j
    • 2
    • 8
  • k

    Kenny Tran

    10/01/2022, 1:24 PM
    Hey. Let's assume I have a sales model like so -
    model Sale {
    id        String            @id @default(uuid())
    createdAt DateTime          @default(now())
    updatedAt DateTime          @updatedAt
    name      String
    date      String
    time      String
    revenue   Int
    amount    Int
    invoice   String
    }
    After I fetch using
    prisma.sale.findMany({})
    I want to calculate the commission against some percentage and add an addition commission field. How would I add the type of the additional field to the client so that I can consume it there? Would it be possible to do something like -
    type Sale = Prisma.SaleGetPayload<{
    include: {
    commission: float
    }
    }>
    The reason why the commission field isn't in the sales model in the first place is because the commission percentage is not persistant and might change depending on other factors. So it needs to be calculated before it gets passed further. I hope that makes sense. Any help is appreciated
    ✅ 1
    j
    • 2
    • 13
  • n

    N

    10/01/2022, 2:13 PM
    from the https://www.prisma.io/docs/concepts/components/prisma-schema/relations/one-to-one-relations#required-and-optional-1-1-relation-fields,
    Copy code
    model User {
      id      Int      @id @default(autoincrement())
      profile Profile?
    }
    
    model Profile {
      id     Int  @id @default(autoincrement())
      user   User @relation(fields: [userId], references: [id])
      userId Int  @unique // relation scalar field (used in the `@relation` attribute above)
    }
    ✅ 1
    v
    • 2
    • 3
  • n

    N

    10/01/2022, 2:41 PM
    after playing around, it appears this expression of a "User can optionally have a profile but a profile CANNOT be created with a user" is preferrable to the alternatives; thus I think this matter is closed.
    ✅ 1
  • s

    SJ

    10/02/2022, 12:45 AM
    does
    PrismaClient
    support programmatically accessing its generated SQL query e.g. as a
    string
    , without executing it? a sort of dry run, for debugging, strong emphasis on not actually executing the query and on 'piping' the query into a standard javascript variable example pseudocode:
    Copy code
    const sqlThatWouldHaveBeenExecuted: string = stringifyQueryAndDontExecute(await prisma.user.create({
      data: {
        name: 'Alice',
        email: '<mailto:alice@prisma.io|alice@prisma.io>',
      },
    }))
    I doubt this is possible atm with Prisma judging from a cursory glance, but if so, it would be quite a pleasant surprise for a database playground
    ✅ 1
    j
    • 2
    • 3
  • j

    Jyn

    10/02/2022, 5:03 AM
    Hi guys, i got a question.
    Copy code
    model Stage {
      id        String    @id @default(cuid())
      code      String    @unique
      createdAt DateTime? @default(now())
    
      rewards Reward[]
    }
    
    type Reward {
      item_code String
      count Int
    }
    I want to make my schema like this, but an error appears:
    Error validating: Composite types are not supported on Postgres.
    Copy code
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    generator client {
      provider = "prisma-client-js"
    }
    I don’t wanna make
    Reward
    as a table(model in schema), since it is very small pieces. What i tried instead is 1. Make It Together
    Copy code
    model Stage {
      id        String    @id @default(cuid())
      code      String    @unique
      createdAt DateTime? @default(now())
    
      reward_item_codes String[]
      reward_item_counts Int[]
    }
    Probleme: i need to always check the lengths of those are equal. 2. Use Json
    Copy code
    model Stage {
      id        String    @id @default(cuid())
      code      String    @unique
      createdAt DateTime? @default(now())
    
      rewards Json
    }
    probleme: Unhappy that i need to make json converter at each server&front. What do you bros usually solve these kinda mundane problem in Prisma? Appreciate your ideas,
    ✅ 1
    n
    • 2
    • 1
  • d

    David Hancu

    10/02/2022, 8:08 AM
    Hi everyone! I've been working on getting full-text search indexes (with
    pg_trgm
    ) ready for the next release of Prisma Util and I was wondering what you think about this configuration example. Should I change anything or keep it like this?
    Copy code
    ftsIndexes: {
      "base.prisma:Post": {
         type: "GIN",
         indexes: [{ language: "english", field: "title", weight: "A"}]
      }
    }
    💬 1
    n
    • 2
    • 2
  • k

    Kenny Tran

    10/02/2022, 10:12 AM
    Hey. I have a problem with deleting rows that are connected through many-to-many. I want to delete all the related fields
    onDelete: Cascade
    however when I perform a delete operation it only deletes the relation. Here's my models -
    model Sale {
    id        String            @id @default(uuid())
    createdAt DateTime          @default(now())
    updatedAt DateTime          @updatedAt
    index     Int               @unique @default(autoincrement())
    rank      Rank              @default(ROOKIE)
    services  ServicesOnSales[]
    }
    model Service {
    id        Int               @id @default(autoincrement())
    createdAt DateTime          @default(now())
    updatedAt DateTime          @updatedAt
    name      String
    provision String
    sales     ServicesOnSales[]
    }
    model ServicesOnSales {
    saleId       Int
    serviceId    Int
    createdAt    DateTime @default(now())
    updatedAt    DateTime @updatedAt
    subscription String
    sale         Sale     @relation(fields: [saleId], references: [index], onDelete: Cascade)
    service      Service  @relation(fields: [serviceId], references: [id], onDelete: Cascade)
    @@id([saleId, serviceId])
    }
    enum Rank {
    ROOKIE
    MASTER
    VETERAN
    }
    The query below only deletes the sale and the relation but the service is not getting removed
    await prisma.sale.delete({
    where: {
    id
    }
    })
    ✅ 2
    j
    v
    • 3
    • 7
  • d

    David Hancu

    10/02/2022, 12:16 PM
    Is there any way to get the raw SQL query that Prisma would run before it runs it?
    ✅ 1
    j
    n
    • 3
    • 9
  • d

    David Hancu

    10/02/2022, 12:16 PM
    Or at least access the query engine so I can do it myself.
    ✅ 1
  • м

    Мовсар Халахоев

    10/02/2022, 2:36 PM
    Hi everyone! Is there in-depth course on prisma? I have read doc, but i need tutorial with many examples. Thanks!
    ✅ 1
    j
    n
    • 3
    • 3
  • s

    Sahas Saurav

    10/02/2022, 3:27 PM
    hey everyone, I'm create wrapper for Prisma and I need the Use model with delegate can someone what is Patameter this Delegate in Prisma Prisma.UserDelegate<?>
    👀 1
    n
    • 2
    • 1
  • s

    Sahas Saurav

    10/02/2022, 3:30 PM
    I'm getting this error
    Generic type 'UserDelegate<GlobalRejectSettings>' requires 1 type argument(s).
    ✅ 1
    v
    • 2
    • 3
  • d

    David Hancu

    10/02/2022, 8:34 PM
    Speaking of this, I ended up reverse-engineering the query engine and building the queries from scratch, such a shame that Prisma doesn't support this natively.
    👀 1
    n
    • 2
    • 1
  • r

    Ridhwaan Shakeel

    10/02/2022, 9:38 PM
    hi
    Copy code
    BigInt.prototype.toJSON = () => {
      return this.toString();
    };
    I used the above function to fix the prisma error:
    Copy code
    message: "const result = await prisma.product.findMany(Inconsistent column data. Conversion failed: Value does not fit in an INT column, try migrating the 'revenue' column type to BIGINT"
    However, now when I query prisma and display the response it doesnt show the numerical value
    Copy code
    [
       {
          "id": 1,
          "revenue": "[object Object]",
          ...
       }
       ...
    ]
    How do you further resolve it? thanks
    👀 1
    ✅ 1
    n
    v
    • 3
    • 5
  • m

    Marrtin Rylander

    10/03/2022, 8:18 AM
    Hi there! Just joined the Slack channel 🙂 I have a small question, is it possible at runtime to output the connection limit and pool timeout the Prisma runtime had been loaded with? We have a system running in production, and to begin with we ran with the default number of connections. First time we had a one off connection pool error i updated the connection string to include ?connection_limit=50. Some time went by and we just got another connection limit error yesterday. The error output says the connection settings are using the defaults: (Current connection pool timeout: 10, connection limit: 5) I was just wondering if i could output the connection settings using Node somehow? Just to verify my settings are being read and are working. I don't know how i'll see it unless we get another error.
    ✅ 1
    • 1
    • 1
1...627628629...637Latest