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

    Kevin Reed

    09/16/2022, 11:41 PM
    I've been stuck trying to connect prisma to a postgresql server running on a computer on my local network. When I use the local IPv4 of my machine (in the
    DATABASE_URL
    ) I'm able to connect no problem, but when I try and use my external IPv4, that I have port forwarded, it fails to connect. Is there something that I'm missing? I'm trying to cut down on DB hosting costs.
    ✅ 1
    n
    • 2
    • 1
  • p

    Pranav Sathyanarayanan

    09/17/2022, 3:31 AM
    Hi everyone; I am attempting to leverage pgbouncer with Prisma and setting the
    pgbouncer=true
    flag on our connections. However our application still seems to be creating a connection pool of
    2n+1
    (so in our case 5 as these are 2 core machines) on our GCP Cloud Run applcation. I wanted to know: 1. What is the recommendation w.r.t to connection pooling in the application (Prisma) when we have pgBouncer configured. I was under the assumption that the application shouldn't pool connections at all and should opt rather to simply "request" a new connection (or create a new one) per query. 2. What happens if we set the
    connection_limit
    to 0? Does this just disable application side pooling? The recommendation seems to be setting it to "1" however our intended behavior is that Prisma defers entirely to pgbouncer to supply connections on demand. 3. Prisma chunks large / complex queries into a series of SELECT statements one after the other. How does this behavior impact settings + usage of pgbouncer? 4. I assumed setting
    pgbouncer=true
    should have disabled the client side application pool totally. I am still seeing (however) "timeouts" fetching a new connection with connection limit printing 5. Is that expected?
    ✅ 1
    n
    • 2
    • 6
  • s

    Samrith Shankar

    09/17/2022, 4:09 AM
    I am randomly facing an error on my server:
    Copy code
    error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.
    Now the thing is my
    DATABASE_URL
    is present in my Lambda configuration and when I log it, it does even print it. Don’t know why this is happening.. any idea? Full error message:
    Copy code
    "Runtime.UnhandledPromiseRejection: Error: error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.",
            "  -->  schema.prisma:3",
            "   | ",
            " 2 |   provider             = \"mysql\"",
            " 3 |   url                  = env(\"DATABASE_URL\")",
            "   | ",
            "",
            "Validation Error Count: 1",
            "    at process.<anonymous> (file:///var/runtime/index.mjs:1131:17)",
            "    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)"
    Client version: 3.15.2 Error message code: P1012
    👀 1
    a
    n
    • 3
    • 10
  • j

    Javier Sebastián Fernández

    09/17/2022, 12:12 PM
    Hi there guys, I've been trying to get rid of this error for days. I am using Next JS, and I am not been able to configure my Prisma client. It doesn't matter what I do or try that I always end with this error. This is the code I am using:
    Copy code
    import { PrismaClient } from '@prisma/client';
    
    let prisma: PrismaClient;
    
    if (process.env.NODE_ENV === 'production') {
        prisma = new PrismaClient();
    } else {
        if (!(global as any).prisma) {
            (global as any).prisma = new PrismaClient();
        }
        prisma = (global as any).prisma;
    }
    
    export default prisma;
    I've have also tried this:
    Copy code
    import { PrismaClient } from '@prisma/client';
    
    declare global {
        // allow global `var` declarations
        // eslint-disable-next-line no-var
        var prisma: PrismaClient | undefined;
    }
    
    export const prisma =
        global.prisma ||
        new PrismaClient({
            log: ['query'],
        });
    
    if (process.env.NODE_ENV !== 'production') global.prisma = prisma;
    This is the error that I am getting:
    👀 1
    p
    r
    v
    • 4
    • 5
  • j

    Jarupong

    09/18/2022, 3:19 AM
    It seems like a feature request could you create the issue on prisma repo?
    d
    • 2
    • 2
  • r

    Richard

    09/18/2022, 8:18 AM
    Is there a way in Prisma to queue transaction calls in Mongo? I have: - a
    api/register
    endpoint - which runs a multi-document transaction in my mongodb database (
    updateMany
    ) The Issue I'm encountering: If two calls to that endpoint are made quickly, the latter one fails because the former's transaction in mongoDB isn't done yet. (see screenshot) (continues in thread)
    ✅ 1
    l
    n
    • 3
    • 10
  • v

    Vasily Zorin

    09/18/2022, 10:18 AM
    Is there a way to insert an unsafe string into prisma.$queryRaw ?
    👀 1
    r
    v
    • 3
    • 6
  • k

    Kenny Tran

    09/18/2022, 11:54 AM
    Hey, what is the current limit for querying records -
    take: N?
    await prisma.record.findMany({
    take: N
    })
    ✅ 1
    n
    • 2
    • 1
  • t

    Theo Letouze

    09/18/2022, 12:58 PM
    Hey, do we know when the 4.4 version will be released? I'm waiting for this bug fix https://github.com/prisma/prisma/issues/15361
    ✅ 1
    n
    • 2
    • 1
  • r

    Richard

    09/18/2022, 2:30 PM
    TypeScript question: How can I have Prisma return the query type dynamically when I provide the
    args
    two levels up?
    Copy code
    // in user.controller.ts
    const getUser => {
      const user = this.userService.findFirst({where: { id: "1" }, include: { childrenField: true } })
      
      user
      //ˆ? type is `User` ❌
      // what I want: `User & { childrenField: ChildenField }`
    }
    Copy code
    // in user.service.ts file...
    async findFirst(args: Parameters<typeof this.userRepository.findFirst>[0]) {
        return await this.userRepository.findFirst(args);
      }
    
    // in user.repository.ts file...
    
    const findFirst = async (args) => {
      return await this.prisma.user.findFirst(args);
    }
    ✅ 1
    v
    y
    • 3
    • 4
  • r

    Ridhwaan Shakeel

    09/18/2022, 4:25 PM
    Copy code
    /app/node_modules/.prisma/client/index.js:3
        throw new Error(
        ^
    
    Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
    In case this error is unexpected for you, please report it in <https://github.com/prisma/prisma/issues>
        at new PrismaClient (/app/node_modules/.prisma/client/index.js:3:11)
        at Object.<anonymous> (/app/server/data/index.js:3:16)
        at Module._compile (node:internal/modules/cjs/loader:1119:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
        at Module.load (node:internal/modules/cjs/loader:997:32)
        at Module._load (node:internal/modules/cjs/loader:838:12)
        at Module.require (node:internal/modules/cjs/loader:1021:19)
        at require (node:internal/modules/cjs/helpers:103:18)
        at Object.<anonymous> (/app/server/routes/index.js:39:5)
        at Module._compile (node:internal/modules/cjs/loader:1119:14)
    Why does this happen sometimes? prisma database is not empty but sometimes requires a prisma generate
    ✅ 1
    r
    • 2
    • 2
  • c

    Craig Haseler

    09/18/2022, 10:49 PM
    Hi, been fighting this for a few hours and it seems like it should be a pretty basic use case but I just can't figure it out. My app gets data from MSSQL by running stored procedures, which have multiple parameters, and those stored procedures return the data. I'm interested in using Prisma but I just can't get it to work. Here's the code I'm trying to run:
    Copy code
    let procedure= "pbk_Chart_Data_Get"
    let params = [{name: "PARSID", value: "1024"}]
    
    return prisma.$queryRaw`${procedure} ${params[0].name} = ${params[0].value};`;
    Here's what I get back from Prisma/SQL
    Copy code
    prisma:error @P2 is not a parameter for procedure pbk_Chart_Data_Get.
    prisma:query @P1 @P2 = @P3;
    @P1 @P2 = @P3; ["pbk_Chart_Data_Get","@PARSID",1033]
    But I know that SP takes a parameter called PARSID which is an int. So I'm not sure how to accomplish this. Even if I can, I'm not sure how to expand this to an arbitrary number of stored proc parameters.
    ✅ 1
    n
    • 2
    • 5
  • r

    Raphael Etim

    09/19/2022, 5:38 AM
    Hi @Valentin Micu 👋 Have you taken a look at this deployment to vercel guide?
    v
    v
    • 3
    • 3
  • a

    Arpan Bagui

    09/19/2022, 7:25 AM
    Is it possible to lock prisma query so that it runs one at a time in server?
    ✅ 2
    j
    r
    • 3
    • 29
  • t

    Theo Letouze

    09/19/2022, 7:41 AM
    Hey guys, I would like to get this bug fix: https://github.com/prisma/prisma-engines/pull/3198 How can I do that? I’ve seen a 4.4.0-dev.44 version on npm
    ✅ 1
    n
    • 2
    • 1
  • r

    Richard

    09/19/2022, 9:40 AM
    alphabet yellow question How can I set up
    tsc
    to have the same output as VSCode's TypeScript server? Somehow, the compilation isn't able to pick up the
    include
    return type from prisma while VSCode is.
    Copy code
    ❌
    src/auth/auth.service.ts:293:13 - error TS2339: Property 'tokenSet' does not exist on type 'User'.
    
    293     const { tokenSet, ...user } = userDatabase;
                    ~~~~~~~~
    Here's the typescript signature of my function:
    Copy code
    async findFirst<T extends Prisma.UserFindFirstArgs>(
        args: Prisma.SelectSubset<T, Prisma.UserFindFirstArgs>,
      ) {
        const user = await this.prisma.user.findFirst(args);
        if (!user) throw new NotFoundException('User not found!');
        return user;
      }
    whereas in vscode, the type is inferred correctly.. 🤔
    ✅ 1
    n
    • 2
    • 3
  • v

    ven v

    09/19/2022, 10:22 AM
    can anyone from prisma tell me if the new full text search supports partial matches? e.g. "J" should return all records where the search column contains the letter "J"
    ✅ 1
    j
    n
    • 3
    • 15
  • v

    ven v

    09/19/2022, 2:02 PM
    Question about pagination - I am reading the docs here (https://www.prisma.io/docs/concepts/components/prisma-client/pagination) and there are two seperate queries suggested for cursor based pagination. Do i need to create/call two seperate queries based on user interaction (either button click or observer API) or can i lump the two queries into one and pass the cursor id as an optional parameter?
    ✅ 1
    n
    • 2
    • 2
  • j

    Joey

    09/19/2022, 2:32 PM
    Is there a way to do counts to see how many occurrences there are of different enum values? Example, say I have a table like so
    model Coordinate {
    direction String // NORTH | SOUTH | EAST | WEST
    x         Float
    y         Float
    id String @id @default(cuid())
    }
    I know I can count how many records have one value, say ‘SOUTH’ for instance, but is there any way, in one call, to count how many records have north, how many have south, how many have east, and how many have west?
    ✅ 1
    n
    • 2
    • 2
  • r

    Rob Hoskins

    09/19/2022, 2:59 PM
    greetings. How do I ensure a User can like a Playlist Once? I assume it's w/ @unique but where? I have the following (simplified) schema
    Copy code
    model User {
      id            String     @id @default(cuid())
      name          String?
      email         String?    @unique
      emailVerified DateTime?
      image         String?
      accounts      Account[]
      sessions      Session[]
      Like          Like[]
      Playlist      Playlist[]
    }
    
    model Playlist {
      id          String       @id @default(cuid())
      createdAt   DateTime     @default(now())
      updatedAt   DateTime     @updatedAt
      likeCount   Int?
      type        PlaylistType
      url         String
      name        String?
      description String?
      author      String?
      tags        Tag[]
      submittedBy User?        @relation(fields: [userId], references: [id])
      likes       Like[]
      userId      String?
    }
    
    model Like {
      id         String   @id @default(cuid())
      createdAt  DateTime @default(now())
      user     User[]     
      playlist Playlist[] 
    }
    ✅ 1
    n
    j
    v
    • 4
    • 5
  • r

    Rob Hoskins

    09/19/2022, 3:50 PM
    Hey People of Prisma, how do I get my tags data on this Typescript type (noticed I had to manually select tags in my findMany Query too) many TIA!
    👀 1
    ✅ 1
    r
    n
    • 3
    • 2
  • t

    Terada

    09/19/2022, 4:41 PM
    Hi I'm working with PostgreSQL. I'm trying to insert 100k rows into an empty table with about 60 columns with createMany. It takes around 30 seconds. Is it normal speed or is there any possibility for speed improvement? Or should I consider like redesign my schema? Logging each query, createMany seems to throw about 40 queries to complete all the inserts.
    ✅ 1
    j
    n
    • 3
    • 6
  • r

    Ridhwaan Shakeel

    09/19/2022, 5:57 PM
    Is there a feature that let’s you copy the current database state (the dataset across all tables) and make a prisma seed script out of it?
    👍 1
    ✅ 1
    r
    • 2
    • 1
  • k

    Kyle Hayes

    09/19/2022, 6:10 PM
    I'm looking for a Dart compatible version of Prisma and discovered this — but something about it doesn't feel like its a legit implementation? https://prisma.pub/
    ✅ 1
    r
    • 2
    • 2
  • м

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

    09/19/2022, 6:16 PM
    Hey there! Which is the best way of using prisma with graphql? Can you recommend some good tutorials, courses or etc? Thanks!
    ✅ 1
    s
    r
    • 3
    • 2
  • e

    Emanuele Ricci

    09/19/2022, 8:55 PM
    Hi there, is it possible to “include” something that do not have a relationship to a query?
    Copy code
    const effects = await prisma.transactionEffect.findMany({
            where: {
                assetBalance: {
                    wallet: {
                        id: wallet?.id,
                    },
                    asset: {
                        symbol: assetBalance?.asset?.symbol,
                    },
                },
            },
            orderBy: {
                transaction: {
                    blockNumber: 'desc',
                },
            },
            include: {
                transaction: true,
                // here I would like to include assetPrice
                // assetPrice has not a connection directly with transactionEffect
                // is it possible to include it even if there's not a releationship but I can say
                // load the price where assetId = XXX and timestamp = XYZ?
            },
        });
    👀 1
    n
    • 2
    • 1
  • e

    Emanuele Ricci

    09/19/2022, 9:01 PM
    or is it possible to use a field as a filter for a subinclude? I need to do this
    Copy code
    const effects = await prisma.transactionEffect.findMany({
            where: {
                assetBalance: {
                    wallet: {
                        id: wallet?.id,
                    },
                    asset: {
                        symbol: assetBalance?.asset?.symbol,
                    },
                },
            },
            orderBy: {
                transaction: {
                    blockNumber: 'desc',
                },
            },
            include: {
                transaction: true,
                assetBalance: {
                    include: {
                        asset: {
                            include: {
                                assetPrice: {
                                    where: {
                                        blockDate: // must be equal to transaction.timestamp (datetime) formatted as MM/dd/yyyy
                                    }
                                }
                            }
                        }
                    }
                }
            },
        });
    👀 1
    n
    v
    • 3
    • 2
  • r

    Rob Hoskins

    09/19/2022, 9:09 PM
    Having issues adding likes based on the model below. Is this the right way to go about it? I'm trying to do it off the Playlist so I can ++ the likeCount and create the Like at the same time but not having any luck, I've tried just about everything here(nested writes) & I'm super stuck
    Copy code
    model User {
      id            String     @id @default(cuid())
      name          String?
      email         String?    @unique
      emailVerified DateTime?
      image         String?
      accounts      Account[]
      sessions      Session[]
      Playlist      Playlist[]
      Like          Like[]
    }
    
    model Playlist {
      id          String   @id @default(cuid())
      createdAt   DateTime @default(now())
      updatedAt   DateTime @updatedAt
      likeCount   Int?
      type        PlaylistType
      url         String
      name        String?
      description String?
      author      String?
      tags        Tag[]
      submittedBy User?   @relation(fields: [userId], references: [id])
      likes       Like[]
      userId      String?
    }
    
    model Like {
      id         String   @id @default(cuid())
      createdAt  DateTime @default(now())
      user       User    @relation(fields: [userId], references: [id])
      userId     String
      playlist   Playlist @relation(fields: [playlistId], references: [id])
      playlistId String
    
      @@unique([userId, playlistId])
    }
    Copy code
    const newLike = { userId: 'cl883tgpm0079x4u5ivj6bzv9', playlistId: 'cl86l256l00935cu59fv08pc3' }
        const result = await prisma.playlist.update({
            where: {
                id: 'cl86l256l00935cu59fv08pc3'
            },
            data: {
                likeCount: { increment: 1 },
                likes: {
                    upsert: {
                        create: newLike,
                        update: newLike
                    }
                },
            },
            include: {
                likes: true,
                tags: true
            }
    
        })
        console.log(result)
    ✅ 1
    n
    j
    • 3
    • 4
  • r

    Ryan Roline

    09/20/2022, 3:28 AM
    Hello! I am very interested in adding Prisma to the stack we are using for a commercial web application. After reviewing the documentation and an open GitHub ticket: https://github.com/prisma/prisma/issues/1122... it looks as though you can only add a single schema to Prisma's configuration? We have customer data separated by schemas within a singular db, and need to know if your solution will allow us to be able to build queries that point to different schemas. No cross-schema joins or anything like that is necessary, we only need to execute queries within the same schema. Any insight or guidance would be greatly appreciated.
    ✅ 1
    d
    r
    v
    • 4
    • 4
  • s

    StevieW

    09/20/2022, 8:34 AM
    Hey! Just getting started with Prisma, and I have a question regarding connecting and disconnecting. I've read this >> https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/connection-management, but still a little unsure on something. If I do something like this
    Copy code
    import { PrismaClient } from '@prisma/client'
    const prisma = new PrismaClient()
    const allPosts: Post[] = await prisma.post.findMany()
    Each time this is called, what happens to the prisma client? Does it auto disconnect when done, and next time it's called a new one is created (then closed) or will I end up with 1000's of these open and running in the background? If so, do I need to just create one and use that all the time? How does that work if it has to handle 1000's of requests at once? I guess I'm just after a little guidance on how best to approach. I get these are likely basic questions! I'm moving over from Python / Django and trying to get my head around things. Thanks!
    ✅ 1
    r
    • 2
    • 3
1...622623624...637Latest