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

    Arun Kumar

    07/06/2021, 9:31 AM
    I've been using
    introspect
    command to update to the schema for the dev env. Now I want to update the schema on the qa env as well. How can I achieve this?
    j
    r
    • 3
    • 25
  • n

    Nikhil Goyal

    07/06/2021, 11:07 AM
    I want to use "if" condition in my findMany() query.For instance, in the following query, this.service.findMany({ where: { platformApplicationIdentity: { in: query.platformApplicationIdentities.split(","), }, settingType: { in: query.settingTypes.split(",") }, identity: { in: query.identities.split(",") }, user: { in: query.users.split(",") }, },
    r
    l
    • 3
    • 7
  • u

    user

    07/06/2021, 11:50 AM
    How migrating from Sequelize to Prisma allowed Invisible to scale Invisible is a B2B productivity startup that allows its users to automate and outsource any complex workflow or business process through Worksharing. Prisma played a crucial role in allowing Invisible to future proof their tech stack and in supporting its scale.
    prisma rainbow 3
  • c

    Copium Dealer

    07/06/2021, 2:55 PM
    Hey everyone. I have this query
    Copy code
    const results = await prisma.token.findMany({
        select: {
          id: true,
          name: true,
          symbol: true,
          telegram: true,
          _count: { select: { votes: true } },
        },
        orderBy: { votes: { count: "desc" } },
      });
    However I would like this to be a range query, so I can select tokens in descending order where the date on votes are less than 24 hours ago If possible, I would also like to select the count of these votes too (but total count is fine if that's not possible).
    d
    • 2
    • 17
  • l

    Luc

    07/06/2021, 4:54 PM
    Hi guys, Is there a way in Prisma Client to reference the value of a field when filtering?
    Copy code
    model Model {
      id String @id
      field1 String
      field2 String
    }
    
    await prisma.Model.find({ where: { field1: { equals: // value of field2 }} });
    r
    • 2
    • 2
  • p

    Peter Kellner

    07/06/2021, 5:22 PM
    When creating an implicit many to many relation, following the docs here; https://www.prisma.io/docs/concepts/components/prisma-schema/relations, the table created for the join does not have a primary called out. MySql by default requires a primary key (and for good reason, replication counts on it). Is there a way to force a primary key creation on the implicit link table?
    Copy code
    CREATE TABLE "Category" (
        id SERIAL PRIMARY KEY
    );
    CREATE TABLE "Post" (
        id SERIAL PRIMARY KEY
    );
    -- Relation table + indexes -------------------------------------------------------
    CREATE TABLE "_CategoryToPost" (
        "A" integer NOT NULL REFERENCES "Category"(id),
        "B" integer NOT NULL REFERENCES "Post"(id)
    );
    CREATE UNIQUE INDEX "_CategoryToPost_AB_unique" ON "_CategoryToPost"("A" int4_ops,"B" int4_ops);
    CREATE INDEX "_CategoryToPost_B_index" ON "_CategoryToPost"("B" int4_ops);
    j
    • 2
    • 49
  • c

    Chris Baucom

    07/06/2021, 7:50 PM
    Does anyone have experience with NextAuth and successfully saving user data to Prisma from 3rd party providers? For example, signing in with Google, I get back the profile.picture and can log that it is indeed a correct URL string. But when trying to set that to store as
    avatar
    in my User model, it doesn’t seem to save. 🧵
    • 1
    • 1
  • j

    Jarod G

    07/06/2021, 9:03 PM
    Hey Prisma Team 👋 I'm following this guide (https://www.prisma.io/docs/guides/deployment/deployment-guides/deploying-to-aws-lambda) to deploy my Prisma backend. I'm having trouble importing my resolvers and am seeing this error.
    Copy code
    import { NonEmptyArray } from "type-graphql";
    ^^^^^^
    
    SyntaxError: Cannot use import statement outside a module
        at wrapSafe (internal/modules/cjs/loader.js:1001:16)
        at Module._compile (internal/modules/cjs/loader.js:1049:27)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
        at Module.load (internal/modules/cjs/loader.js:950:32)
        at Function.Module._load (internal/modules/cjs/loader.js:790:14)
        at Module.require (internal/modules/cjs/loader.js:974:19)
        at require (internal/modules/cjs/helpers.js:92:18)
        at Object.<anonymous> (C:\Workspace\Stagewood-Test\server\handler.js:4:19)
        at Module._compile (internal/modules/cjs/loader.js:1085:14)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    I think it has something to do with how I'm generating the resolvers to TypeScript and using it in the JS handler. This is what my handler.js looks like:
    Copy code
    const graphqlLambda = require('apollo-server-lambda');
    const makeExecutableSchema = require('graphql-tools');
    const importSchema = require('graphql-import');
    const resolvers = require('./prisma/generated/type-graphql/index.ts');
    
    const typeDefs = importSchema('./schema/schema.graphql')
    
    const myGraphQLSchema = makeExecutableSchema({
      typeDefs: typeDefs,
      resolvers,
    });
    
    exports.graphqlHandler = function graphqlHandler(event, context, callback){
      function callbackWithHeaders(error, output) {
        output.headers['Access-Control-Allow-Origin'] = '*';
        callback(error, output);
      }
      const handler = graphqlLambda({schema: myGraphQLSchema });
      return handler(event, context, callbackWithHeaders)
    }
    Does anyone know how I can get this working on AWS or point me in the right direction?
    l
    r
    • 3
    • 3
  • a

    Arun Kumar

    07/07/2021, 7:18 AM
    I was reading this doc https://www.prisma.io/docs/concepts/components/prisma-migrate/prisma-migrate-limitations-issues . So the same schema and migration will not work in dev and qa. How to make sure that schema changes in the dev DB reflect in the qa DB. Should I run the npx prisma migrate command in the qa env as well?
    r
    d
    • 3
    • 19
  • a

    Arun Kumar

    07/07/2021, 7:20 AM
    The docker file configuration is
    Copy code
    FROM node:latest as build
    	# set the working direction
    	WORKDIR /app
    	
    
    	# add `/app/node_modules/.bin` to $PATH
    	ENV PATH /app/node_modules/.bin:$PATH
    
    
    	# install app dependencies
    	COPY package.json ./
    	COPY package-lock.json ./
    	COPY . ./
    	RUN npm install
    	RUN npx prisma generate
    	CMD "npm" "start"
  • d

    Dimitri Ivashchuk

    07/07/2021, 7:55 AM
    Hey team! I am having troubles updating/creating an optional relation:
    Copy code
    Evaluations: {
                            upsert: [
                                {
                                    where: {
                                        topic_id_assessment_record_id_unique: {
                                            topicId: topicId as string,
                                            assessmentRecordId: recordId as string,
                                        },
                                    },
                                    create: {
                                        User: {
                                            connect: {
                                                id: user.id,
                                            },
                                        },
                                        Topic: {
                                            connect: {
                                                id: topicId as string,
                                            },
                                        },
                                        Level: {
                                            connect: {
                                                id: levelId as string,
                                            },
                                        },
                                        Stage: {
                                            connect: {
                                                id: stageId as string,
                                            },
                                        },
                                        comment: comment as string,
                                        score: 321,
                                    },
                                    update: {
                                        levelId: levelId as string,
                                        stageId: stageId as string,
                                    },
    Copy code
    model Evaluation {
      id                 String   @id @default(cuid())
      assessmentRecordId String
      userId             String
      topicId            String
      levelId            String?
      stageId            String?
      score              Float
      comment            String?
      createdAt          DateTime @default(now())
      updatedAt          DateTime @updatedAt @map(name: "updated_at")
    
      Record AssessmentRecord @relation(fields: [assessmentRecordId], references: [id])
      User   User             @relation(fields: [userId], references: [id])
      Topic  Topic            @relation(fields: [topicId], references: [id])
      Level  Level?           @relation(fields: [levelId], references: [id])
      Stage  Stage?           @relation(fields: [stageId], references: [id])
    
      @@unique([topicId, assessmentRecordId], name: "topic_id_assessment_record_id_unique")
      @@map(name: "evaluations")
    }
    Both
    null
    and
    undefined
    as arguments throw error 😕
    r
    • 2
    • 4
  • m

    Moh

    07/07/2021, 8:23 AM
    Hi guys, how can I use updateMany to update an entity, and then create an entity that has a one-to-many relationship with it? eg: Say I have a 'Rules' table and a flag that I want to set to 'true' for a bunch of ID's. 'Rules' has a 1-M relationship with another table called 'Version' which keeps version details. Every time I update 'Rule' I want to create a new entry in 'Version' Thought I could do something like: prisma.rules.updateMany({ data: { Flag: true, Version: { create: { AnotherFlag: true } } } }) But no luck
    d
    r
    • 3
    • 2
  • n

    Nikhil Goyal

    07/07/2021, 10:27 AM
    I want to update based on the combination of keys which are unique in my DB. When I update based on primary key it works but not on combination of keys which are defined unique. await this.service.update({ where:{ platformApplicationIdentity: uiData.platformApplicationIdentity, settingType: uiData.settingType, identity: uiData.identity, user: uiData.user, }, data:{ lastTouchedBy: uiData.lastTouchedBy, summary: uiData.summary, lastTouchedTimeUTC: uiData.lastTouchedTimeUTC == undefined ? null : uiData.lastTouchedTimeUTC, lastTouchedComment: uiData.lastTouchedComment == undefined ? null : uiData.lastTouchedComment, tenant: uiData.tenant == undefined ? null : uiData.tenant, } })
    r
    • 2
    • 9
  • t

    Taylor Lindores-Reeves

    07/07/2021, 11:15 AM
    Can anyone help me?
    r
    • 2
    • 2
  • h

    Halvor

    07/07/2021, 11:34 AM
    How can i do this?
  • h

    Halvor

    07/07/2021, 11:34 AM
    await prisma.arbitrated.upsert({ where: { match: { session_id: matchId } }, update: {}, create: { match: { connect: { session_id: matchId } }, value: 1233245354325 } });
    r
    • 2
    • 22
  • h

    Halvor

    07/07/2021, 11:34 AM
    match is another table that arbitrated is referensing.
  • m

    manuel

    07/07/2021, 1:04 PM
    Can anyone tell me why typescript/nexus is complaining if I generate my types? thanks!
    a
    • 2
    • 4
  • m

    manuel

    07/07/2021, 1:04 PM
    h
    c
    r
    • 4
    • 4
  • c

    Copium Dealer

    07/07/2021, 2:08 PM
    Is it possible to use a where clause with a nested relation count? For example, select the users who have more than 500 posts?
    r
    • 2
    • 27
  • j

    Jack Reed

    07/07/2021, 2:29 PM
    Hi all, I'm curious about what expectation I should have using nested reads. Should I have the expectation that a nested read would generate 1 SQL query? Or would it generate multiple queries, and I really shouldn't worry about it? For example:
    Copy code
    ctx.prisma.user.findUnique({
      where: {
        id: user.id,
      },
      include: {
        permissions: true
      }
    })
    Thanks!
    r
    l
    • 3
    • 3
  • d

    Dennis

    07/07/2021, 4:39 PM
    I have a database running in a kubernetes cluster, which I can access locally. The database is empty and I wanted to use it with prisma, but I struggle to initialize it. Locally I always used the the prisma cli, but what do I do on the cluster?
    j
    • 2
    • 3
  • h

    Halvor

    07/07/2021, 5:35 PM
    I need to have a 1-to-1 relation
  • h

    Halvor

    07/07/2021, 5:35 PM
    and use the relation as unique identifier
  • h

    Halvor

    07/07/2021, 5:35 PM
    is that possible?
    j
    • 2
    • 6
  • c

    Cole Voss

    07/07/2021, 6:48 PM
    Quick question. I have a migration that has been in a branch for a long time. Since then we reset our migrations and the original
    init
    and all other migrations now have a later dated migration folder name. It seems to have deployed ok in our staging environment, but locally it causes issues. I am thinking about changing the name of the migration folder to a later date, and then manually updating the
    _prisma_migration.migration_name
    to the new name in the database. Does anyone see any glaring issues with that? Thanks!
    r
    j
    +2
    • 5
    • 7
  • p

    prisma chobo

    07/07/2021, 7:24 PM
    Is it possible to filter relation specific id? I see that there are every and some keywords but I cannot acheive my intention. For example, this query
    Copy code
    prisma.transaction.findMany({
            skip,
            take,
            where: {
              audience,
              AND: [
                {
                  accounts: {
                    some: {
                      id: accountId,
                    },
                  },
                },
                {
                  balance: {
                    some: {
                      accountId,
                    },
                  },
                },
              ],
            },
            orderBy,
            include: {
              balance: true,
              transfer: true,
              payout: true,
              fees: true,
              fund: true,
            },
          });
        }
    gives me
    Copy code
    {
      "data": {
        "transactions": [
          {
            "id": "ckqtnygnv0032z5vhbb04b2kh",
            "type": "TRANSFER",
            "description": "test transfer",
            "transfer": {
              "id": "ckqtnygnv0035z5vhthw2z65e",
              "payee": {
                "username": "justin",
                "id": "ckqtn3kv70003ccvh1ufbyoxv"
              },
              "payor": {
                "id": "ckqtne3lm0128ccvhmpiz9c26",
                "username": "dustin"
              }
            },
            "fund": null,
            "balance": [
              {
                "id": "ckqtnygnv0033z5vhdlen44um",
                "amount": 5000,
                "account": {
                  "id": "ckqtn3kv70003ccvh1ufbyoxv",
                  "username": "justin"
                }
              },
              {
                "id": "ckqtnygnv0034z5vhvwwbr0z2",
                "amount": -5000,
                "account": {
                  "id": "ckqtne3lm0128ccvhmpiz9c26",
                  "username": "dustin"
                }
              }
            ]
          }
        ]
      }
    }
    But for balance entity, I only want to query balance.account.id == “ckqtn3kv70003ccvh1ufbyoxv” If i change this part to
    Copy code
    {
                  balance: {
                    some: {
                      accountId,
                    },
                  },
                }
    to this (some to every):
    Copy code
    {
                  balance: {
                    every: {
                      accountId,
                    },
                  },
                }
    I get empty array… is there anything similar like
    Copy code
    balance: {
      accountId = "account id I want to query "
    }
    r
    • 2
    • 2
  • w

    windkomo

    07/07/2021, 7:41 PM
    is it possible to keep order of a many to many relation without an explicit relation? Or do I need an explicit relation with an order column?
    r
    • 2
    • 2
  • h

    Halvor

    07/07/2021, 9:33 PM
    Is createMany() supported?
  • p

    prisma chobo

    07/07/2021, 9:52 PM
    yes
1...454455456...637Latest