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

    Callum

    07/20/2021, 10:05 AM
    Hi all! I might be missing something but is it possible to perform a "count where" inside a relation of a
    findMany
    ?
  • c

    Callum

    07/20/2021, 10:08 AM
    I can see a few issues have been opened about this but they all seem to end up referencing other issues/prs that have been closed/merged with no real answer as to how to do it
    r
    • 2
    • 1
  • t

    Thomas Morice

    07/20/2021, 2:41 PM
    Hello everyone! I would like to ask something around Prisma usage, am I in the right channel ?
    r
    • 2
    • 2
  • p

    protzman

    07/20/2021, 6:34 PM
    Hey been a while since i've been in here and haven't been following prisma too much. Starting a new project @ work and looking to shake things up and use the tools I actually want to use. Currently have a Postgresql db with a bunch of entries, some of which have lat/lon data. I was curious if it is possible to use some of prisma's aggregation functionality to mimic querying by bounding box - specifically looking at this example
    Copy code
    const usersByCountry = await prisma.user.groupBy({
      by: ['country'],
      count: {
        country: true,
      },
      having: {
        country: {
          count: {
            gt: 3,
          },
        },
      },
    })
    }
    so you could do something like aggregate by
    lat: {gt : whatever, lt: whatever} , lon: {gt : whatever, lt: whatever}
    or something?
    r
    • 2
    • 2
  • p

    prisma chobo

    07/20/2021, 8:57 PM
    Why am I getting undefined type?
    Copy code
    const transaction = prisma.transaction.create({
        data: {
          audience,
          description,
          paymentMethodId: '',
          type: 'TRANSFER',
          balances: {
            create: [
              {
                amount,
                accountId: payeeId,
                currency: 'GPT',
              },
              {
                amount: amount * -1,
                accountId: payorId,
                currency: 'GPT',
              },
            ],
          },
          transfer: {
            create: {
              payeeId,
              payorId,
            },
          },
           accounts: {
            connect: [
              {
                id: '',
              },
              {
                id: '',
              },
            ],
          },
        },
      });
    And this is my schema for transaction and account:
    Copy code
    model Transaction {       
      accounts                    Account[]
    }
    
    
    model Account {
      transactions                Transaction[] 
    }
    This is my error:
    Copy code
    Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type '(Without<TransactionCreateInput, TransactionUncheckedCreateInput> & TransactionUncheckedCreateInput) | (Without<...> & TransactionCreateInput)'.
      Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type 'Without<TransactionUncheckedCreateInput, TransactionCreateInput> & TransactionCreateInput'.
        Type '{ audience: AUDIENCE; description: string; paymentMethodId: string; type: "TRANSFER"; balances: { create: { amount: number; accountId: string; currency: "GPT"; }[]; }; transfer: { create: { ...; }; }; accounts: { ...; }; }' is not assignable to type 'Without<TransactionUncheckedCreateInput, TransactionCreateInput>'.
          Types of property 'paymentMethodId' are incompatible.
            Type 'string' is not assignable to type 'undefined'.
    🄲 1
    c
    r
    • 3
    • 18
  • d

    Dev__

    07/20/2021, 9:13 PM
    can someone explain to me prisma's API
    every
    and
    some
    ? everything I use them they always do the opposite of what I expect
  • d

    Dev__

    07/20/2021, 9:21 PM
    for example I have this model
    Copy code
    model Buyer {
      id
    
      buyersToBuyerGroups    BuyersToBuyerGroups[]
    }
    
    model BuyerGroup {
      id
    
      buyersToBuyerGroups               BuyersToBuyerGroups[]
    }
    
    model BuyersToBuyerGroups {
      buyerId
      buyerGroupId
    
      buyerGroup BuyerGroup @relation(fields: [buyerGroupId], onDelete: Cascade, references: [id])
      buyer      Buyer      @relation(fields: [buyerId], onDelete: Cascade, references: [id])
    }
    so lets say there is two records inside the
    BuyersToBuyerGroups
    Copy code
    buyerId    buyerGroupId
    1          32
    1          12
    so what I want with this query is I want to fetch all buyer groups where
    buyerId
    is equal to
    x
    Copy code
    prisma.buyerGroup.findMany({
      where: {
        buyersToBuyerGroups = {
    	  every: {
    	    buyerId: 1
    	  }
    	};
      }
    })
    I expect it to return only 2
    buyerGroups
    because of the
    where
    but instead it returns me all rows expect those 2. am I misunderstanding
    every
    or is this suppose to happen? when i use
    some
    it works as expected, I only get back 2 records...
    r
    • 2
    • 1
  • c

    Chris Packett

    07/21/2021, 3:11 AM
    Hey all, I’m running into a race condition where Stripe sends two webhooks: ā€œinvoice.paidā€ and ā€œcheckout.session.completedā€ (which are sent in random order) and my backend creates a ā€œPaymentā€ record when I receive the ā€œinvoice.paidā€ event, and a ā€œCustomerā€ record when I receive the ā€œcheckout.session.completedā€ event. The issue comes to play when I need the ā€œcustomerIdā€ for the ā€œPaymentā€ record. On both event handlers, I ā€œupsertā€ a ā€œCustomerā€ record to ensure that a ā€œcustomerIdā€ is always present when creating a ā€œPaymentā€ record; however, two ā€œCustomerā€ records end up getting created because it doesn’t seem like Prisma ORM ā€œlocksā€ the table from reads/writes. Has anyone had an issue like this before? Will post code in the thread.
    • 1
    • 1
  • a

    Arun Kumar

    07/21/2021, 7:55 AM
    Changing the model from bigInt to int and applying the migration throw an error
    Error querying the database: db error: ERROR: type "serial" does not exist
    r
    • 2
    • 2
  • p

    Paul

    07/21/2021, 8:14 AM
    Hey all. I'm on Prisma 2.20.1. I want to use updateMany on a binary id.
    Copy code
    db.damFile.updateMany({
            data: {
              deletedAt: DateTime.utc().toString(),
            },
            where: {
              id: {
                in: ids.join(",")
              }
            },
          })
    This obviously doesn't work. What's the best way to handle this use-case? I don't want to use a for loop and delete each one individually. Note: I could use an execute raw and use a string array... Thanks
    t
    • 2
    • 5
  • j

    JohnyTheCarrot

    07/21/2021, 8:30 AM
    Hi! I’m having some issues with typescript. I had to anonymise the error here but I’m sure it’s still usable.
    Copy code
    Type 'Prisma__our_record_formatClient<{ varOne: boolean; varTwo: boolean; }>' is missing the following properties from type 'OurRecordFormat': varOne, varTwo
    r
    • 2
    • 2
  • n

    Nichita Z

    07/21/2021, 11:28 AM
    Hello! I seem to have run into a bug with Prisma when counting relations. I have this model:
    model Hashtag {
    tag String @id
    posts Post[]
    }
    And i’m trying to count the relations like so:
    include: { _count: { select: {  posts: true  } } },
    And it’s throwing the below error.. looks like prisma isn’t generating something correctly? Running prisma migrate dev tells me there’s nothing to generate šŸ˜ž
    t
    r
    • 3
    • 9
  • s

    Subash Ganesh

    07/21/2021, 12:29 PM
    Hi Everyone. I am inserting the row using $queryRaw,$executeRaw. Once it get inserted I need the Inserted row id. Using RETURNING id and LAST_INSERT_ID. I am not able to get this. Any other solution for this. Thanks in advance.
    r
    • 2
    • 1
  • b

    Baris

    07/21/2021, 12:56 PM
    Hey everyone, I am currently facing some issues with prisma and postgres inside a docker container on the new M1 - Apple Silicion architecutre and wanted to ask if someone had experienced that before and solved it. Running a migration
    npx prisma migrate dev
    returns this from the postgres container log:
    2021-07-21 12:52:58.927 UTC [76] ERROR:  relation "_prisma_migrations" does not exist at character 126
    I have also defined the binaryTargets in the schema:
    Copy code
    generator client {
      provider      = "prisma-client-js"
      binaryTargets = ["native","linux-arm-openssl-1.1.x"]
    }
    Currently running
    node:16
    on the docker container When I am running a migration outside the docker container with
    docker-compose run --publish 5555:5555 next npx prisma "migrate" "dev"
    it throws an error that it could not reach the database:
    Copy code
    Error: P1001: Can't reach database server at `test-postgres`:`5432`
    The docker-compose for the db looks like this:
    Copy code
    postgres:
        container_name: 'test-postgres'
        restart: unless-stopped
        image: 'postgres:13'
        platform: linux/arm64
        ports:
          - '15432:5432'
        volumes:
          - 'pgdata:/var/lib/postgresql/data/'
        environment:
          POSTGRES_PASSWORD: postgres
    • 1
    • 1
  • s

    Scott

    07/21/2021, 1:59 PM
    Hey, what are some use cases where I would choose sqlite over postgres?
  • k

    Kindly

    07/21/2021, 4:45 PM
    Heya. I seem to have a problem with relations. It says I must reference a unique criteria in the related model, but I can't do that, since the field is not meant to be unique. This is the gist:
    Copy code
    model User {
        id        String   @id @default("")
    
        habits        UserToHabit[] @relation(name: "UserToHabit_User", fields: [id], references: [userId])
        partnerHabits UserToHabit[] @relation(name: "UserToHabit_Partner", fields: [id], references: [partnerId])
        league        League        @relation(fields: [leagueId], references: [id])
    }
    
    model UserToHabit {
        id        String   @id @default("")
    
        user      User    @relation(name: "UserToHabit_User", fields: [userId], references: [id])
        partner   User?   @relation(name: "UserToHabit_Partner", fields: [partnerId], references: [id])
        habit     Habit   @relation(fields: [habitId], references: [id])
        habitId   String
        userId    String
        partnerId String?
    
        @@unique([habitId, userId])
    }
    The relation from UserToHabit to User goes fine, as it goes from userId to id, but the other way around doesn't, as it goes from id to userId, but userId on UserToHabit isn't and can't be unique (habitId + userId is unique though). And I also can't remove the relation from User to UserToHabit because it doesn't let me.
    r
    • 2
    • 2
  • g

    Gelo

    07/21/2021, 6:48 PM
    Prisma studio for m1 already supported?
    r
    • 2
    • 4
  • w

    William Chantry

    07/21/2021, 6:50 PM
    I’m trying to create a db and add an extension (this is a test helping database, integresql) but am having trouble connecting and inspecting said db using
    executeRaw
    . Does anyone know if this is possible using
    executeRaw
    ? (thread)
    r
    • 2
    • 3
  • p

    Paul

    07/22/2021, 9:09 AM
    So I have given up my previous question with Buffers and now instead trying to use string. I keep on getting 0 changes when I am submitting a multiple item array, just 1 item and it's fine.
    Copy code
    const query = db.$executeRaw(
            `
            update DamFile
            set deletedAt = ?
            where id in (?)
          `,
            DateTime.utc().toString(),
            ids.join(",")
          )
    
          const result = await db.$transaction([query])
    
          console.log(result)
    Can anyone catch what I am doing wrong? Thanks
    r
    • 2
    • 21
  • d

    David

    07/22/2021, 11:04 AM
    Hi guys, anyone tried to use RushJS with Prisma before? right now I have a multiple apps inside one repo built using RushJS. and last time, only one back end app (and one prisma inside). But, now there is more than one back end app in the repo, and all of them using Prisma. So I want to separate the Prisma to be in common folder and make its as a library that others backend app will be import. But I keep failed with the error is
    TypeError: prisma_1.default is not a constructor
    šŸ˜• anyone have any idea why? basically I just make an
    index.ts
    file and
    helper.ts
    inside that and the content is:
    helper.ts
    Copy code
    import { PrismaClient } from '@prisma/client';
    
    const client = new PrismaClient()
    
    export default client;
    index.ts
    Copy code
    export { default } from './helper'
    one of my backend app's index file:
    Copy code
    import PrismaClient from 'my-library-name';
    
    //just use the PrismaClient I imported like usual
    I also tested by adding some console log in
    helper.ts
    and
    index.ts
    and when I run the backend app's, the console.log is printed before the error exception is appear. --- tl;dr: I want to make a separate folder for the Prisma to shared into 3 different apps. But, I keep failed at importing the PrismaClient.
    r
    • 2
    • 3
  • a

    Adam

    07/22/2021, 3:20 PM
    The official Microsoft Visual Studio twitch channel is streaming a show about
    prisma
    https://www.twitch.tv/visualstudio
  • u

    user

    07/22/2021, 4:30 PM
    Prisma Adopts Semantic Versioning (SemVer) We are adjusting our release policy to adhere more strictly to Semantic Versioning. In the future, breaking changes in the stable development surface (i.e. General Availability) will only be rolled out with major version increments.
    ā¤ļø 6
    šŸ”¢ 3
  • a

    Alex Okros

    07/22/2021, 5:14 PM
    Hey all, I’m currently trying to run
    prisma migrate deploy
    in a self-contained environment without npm. Does anyone know how I can package the prisma cli with
    pkg
    into an executable I can use in that environment?
  • c

    Chris Tsongas

    07/22/2021, 8:22 PM
    Question about naming models and their corresponding types...I'm new to TypeScript and one thing I've noticed is that when a model name ends with the word "Type" that leads to awkward "TypeType" types. For example, a project I'm starting has
    Case
    and
    CaseType
    models which lead to
    CaseType
    and
    CaseTypeType
    types if I'm appending the word
    Type
    to name my types. Awkward. It was suggested to prefix type names with
    I
    instead, but I don't use interfaces much mostly just types which I've heard someone's company prefixes with
    T
    so maybe I'd do that, and prefix interfaces with
    I
    and enums with
    E
    ?
    šŸ‘ 1
    r
    • 2
    • 1
  • c

    Chris Tsongas

    07/22/2021, 8:24 PM
    P.S. I'm not doing any automated type generation yet, but am entertaining eventually using something like GraphQL Code Generator.
  • w

    William Chantry

    07/22/2021, 8:27 PM
    I had to edit a migration to work with a new version of our id. Does anyone know how the file checksum is calculated? I’d like to get rid of the warning on deploy
    • 1
    • 1
  • m

    Melvin Gaye

    07/22/2021, 9:10 PM
    Question about deploying procedure scripts using queryraw.
    Copy code
    .....
    DELIMITER //
    Drop proc if exists.....
    Create proc...
    ....
    END....
    Running something like above to create a proc using workbench and it works. But when I run it using prisma.queryraw, prisma returns a syntax error. Valid query that executes but prismatic has trouble with. Anyone ran into anything like this?
    r
    • 2
    • 4
  • e

    Edward Baer

    07/22/2021, 11:14 PM
    I didn't have a lot of luck using Prisma to create Stored Procedures. I ended up using raw MySQL like this:
  • e

    Edward Baer

    07/22/2021, 11:15 PM
    Copy code
    const mysql = require('mysql-await');
    
      // Drop, and re-create Sequence Stored Procedure
      const dropSomeProcedure = 'DROP PROCEDURE IF EXISTS someProcedure';
    
      const createSomeProcedure = `
        CREATE PROCEDURE someProcedure (
    	...
        )
        BEGIN
    	....
        END
      `;
    
      const connectionParams = {
        host: config.dbHost,
        port: config.dbPort,
        user: config.dbUsername,
        password: config.dbPassword,
        database: config.dbDatabase
      };
    
    
      const dbConn = mysql.createConnection(connectionParams);
    
      await dbConn.awaitQuery(dropSomeProcedure );
      await dbConn.awaitQuery(createSomeProcedure);
    
      dbConn.end();
  • e

    Edward Baer

    07/22/2021, 11:15 PM
    @Melvin Gaye Sorry, I forgot to tag you on my response above...
1...461462463...637Latest