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

    John Cantrell

    05/21/2022, 4:50 PM
    any idea what pricing will be for the data proxy eventually?
    a
    • 2
    • 2
  • j

    John Cantrell

    05/21/2022, 4:51 PM
    are there multiple regions available for the proxy? I'm thinking of using it with cloudflare workers and would love to be able to switch proxy at runtime based on user region
    a
    • 2
    • 1
  • n

    Norbert Takács

    05/21/2022, 6:18 PM
    I have started with a simple setup:
    Copy code
    datasource db {
      provider = "sqlite"
      url      = "file:./../config/rss_bot_database.db"
    }
    
    model rss {
      id   Int    @id @unique(map: "sqlite_autoindex_rss_1") @default(autoincrement())
      link String @unique(map: "sqlite_autoindex_rss_2")
      last String
      name String @unique(map: "sqlite_autoindex_rss_3")
    }
    trying to move to this schema.
    Copy code
    datasource db {
      provider = "sqlite"
      url      = "file:./../config/rss_bot_database.db"
    }
    
    model rss {
      id      Int    @id @unique(map: "sqlite_autoindex_rss_1") @default(autoincrement())
      link    String
      last    String
      name    String
      chat_id Int    @default(0)
    }
    
    model setting {
      id             Int     @id @unique @default(autoincrement())
      show_changelog Boolean @default(true)
      last_version   String
      chat_id        Int     @unique
      delay          Int
    }
    I get the following error:
    Copy code
    npx prisma migrate dev --name multichat
    
    Environment variables loaded from .env
    Prisma schema loaded from prisma/schema.prisma
    Datasource "db": SQLite database "rss_bot_database.db" at "file:./../config/rss_bot_database.db"
    
    - The migration `20220503190343_multichat` failed.
    - Drift detected: Your database schema is not in sync with your migration history.
    
    The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.
    
    It should be understood as the set of changes to get from the expected schema to the actual schema.
    
    [+] Added tables
      - rss
    
    [*] Changed the `rss` table
      [+] Added unique index on columns (name)
      [+] Added unique index on columns (link)
      [+] Added unique index on columns (id)
    - The migrations recorded in the database diverge from the local migrations directory.
    
    ✔ We need to reset the SQLite database "rss_bot_database.db" at "file:./../config/rss_bot_database.db".
    Do you want to continue? All data will be lost.
    I am new to prisma, what can I do? It makes no sense 😢
    n
    • 2
    • 2
  • c

    chepte

    05/21/2022, 6:30 PM
    Hi, I have an implicit many to many relationship (a user has many chats and a chat can belong to 2 -so many - users). How can I find one chat (chat.findUnique) where I give 2 user ID’s and prisma gets the chat that belongs to these two users? I can’t find it anywhere in the documentation...
    n
    • 2
    • 1
  • a

    Aaron Waller

    05/21/2022, 6:58 PM
    Hi, how to orderBy _count? I want to sort all my users by the amount of posts they have. This is what I found in the docs:
    Copy code
    const getActiveUsers = await prisma.user.findMany({
      take: 10,
      orderBy: {
        posts: {
          _count: 'desc',
        },
      },
    })
    This is not working for me, I only can choose the fields inside “orderBy” that are not arrays. Am I missing something? Its a simple one-to-many relation
    n
    • 2
    • 3
  • b

    Bailey Granam

    05/21/2022, 7:41 PM
    I asked on GH but was hoping someone might know the answer, I am trying to write a query that returns a list of resources that are available for a given range. The issue however is that I cannot seem to find any documentation on referencing custom values in the
    where
    statement. For now I am using a raw query but would rather not if possible. Current:
    Copy code
    SELECT "Resource".*
        FROM "Resource"
        LEFT JOIN "Appointment" ON "Appointment"."resourceId" = "Resource"."id"
        WHERE "Appointment"."id" IS NULL
        OR NOT (
            "Appointment"."startAt" < ${range.endDate}
            AND ("Appointment"."startAt" + INTERVAL '1 Minute' * "Appointment"."duration") > ${range.startDate}
        );
    Desired:
    Copy code
    prisma.resource.findMany({
        where: {
          appointments: {
            none: {
              startAt: { lt: range.endDate },
              // How do I query:
              // ("Appointment"."startAt" + INTERVAL '1 Minute' * "Appointment"."duration") > ${range.startDate}
            },
          },
        },
      });
    n
    • 2
    • 1
  • h

    Hoàng Anh Uy Vũ

    05/22/2022, 2:38 AM
    👋 Hello, team!
    n
    • 2
    • 1
  • a

    Ankit Singh

    05/22/2022, 7:17 AM
    Hello guys, I hava a very basic Schema with implicit many to many relation between two models (User > Post > Likes) here: I Just want to know how can i query through prisma if the many to many relation exist for the given userID? scratching my head for so long! any help would be much appreciated. Thank you
    Copy code
    model User {
      id                         Int                          @id @default(autoincrement())
      username                   String?                      @unique 
      Post                       Post[]   
      PostLike                   Post[]                       @relation("likeTable")
    }
    
    model Post {
      id          Int           @id @default(autoincrement())
      content     String?
      userId      Int
      user        User          @relation("posts", fields: [userId], references: [id])
      Likes       User[]        @relation("likeTable")
    }
    n
    • 2
    • 1
  • o

    Omar

    05/22/2022, 8:12 AM
    Anybody knows where I can find the Prisma Studio repo?
    r
    n
    • 3
    • 4
  • v

    Vyrek XD

    05/22/2022, 3:38 PM
    Copy code
    imageID   String  @id @default(auto()) @map("_id") @db.ObjectId
        messageID String?
        userID    String?
        guild     String?
        channelID String?
        logID     String?
    
        url String
    
        type            String
        interactionType String?
    
        isVideo Boolean?
    
        tags       String[]
        likedBy    Users[]  @relation(fields: [likedByIds], references: [id])
        likedByIds String[]
    }
    
    model Users {
        id             String   @id @map("_id")
        premium        Boolean  @default(false)
        tagsSuggested  Int      @default(0)
        baraRequested  Int      @default(0)
        isContribuitor Boolean  @default(false)
        liked          Images[]
    }
    n
    • 2
    • 3
  • v

    Vyrek XD

    05/22/2022, 3:38 PM
    so i have this
  • v

    Vyrek XD

    05/22/2022, 3:38 PM
    but it gaves me an error on vscode
  • v

    Vyrek XD

    05/22/2022, 3:38 PM
  • v

    Vyrek XD

    05/22/2022, 3:38 PM
    its a "like" system
    n
    • 2
    • 1
  • p

    prisma chobo

    05/22/2022, 7:40 PM
    Please help me this time, when I raw aggregate query against mongodb atlas for objectId, I get error about ObjectIt Type. "Remote error from mongot :: caused by :: \"compound.must[1].equals.value\" must be a boolean or objectId)"" Here is my query
    Copy code
    await prisma.userAgent.aggregateRaw({
        pipeline: [
          {
            $search: {
              compound: {
                must: [
                  {
                    text: {
                      query: "opera",
                      path: {
                        wildcard: "*",
                      },
                    },
                  },
                  {
                    equals: {
                      path: "application_id",
                      value: 'ObjectId("6284913de2e5beb0e6336033")',
                    },
                  },
                ],
              },
            },
          },
        ],
      });
    For the value field, I tried 'ObjectId("6284913de2e5beb0e6336033")', new ObjectID("id"), "6284913de2e5beb0e6336033", etc... All fails with the same error message. How do I pass ObjectId to mongodb atlas using aggregateRaw????
    r
    n
    • 3
    • 4
  • b

    Berian Chaiwa

    05/22/2022, 9:51 PM
    Hello here.I am using
    yarn
    but after I run
    npx prisma init
    I am seeing it attempting to install
    Prisma
    again when I have already done that via
    yarn add
    . Any quick pointers?
    Copy code
    Need to install the following packages:
      prisma
    Ok to proceed? (y) 
    > Downloading Prisma engines for Node-API for debian-openssl-1.1.x
    n
    • 2
    • 5
  • e

    Erik Näslund

    05/22/2022, 11:31 PM
    Good evening! I am having an issue with prisma running in a docker container. To have my Node.js server read from my Postgres server using prisma I have to set the db-url to be the container name of the db service. But to seed or migrate the server prisma needs the db-url to be set to the IP (0.0.0.0). Have anyone here had a similar issue and / or can point me in the right direction?
    b
    • 2
    • 6
  • c

    Chris Tsongas

    05/23/2022, 1:06 AM
    Is there a way to reset the database without seeding it?
    n
    • 2
    • 1
  • a

    Alan

    05/23/2022, 3:27 AM
    hello. I have a noob question where I ran the migrate successfully for a model Album. When trying to use the prisma client, I can get as far as
    (new PrismaClient()).album
    but when chaining
    .findMany()
    after that I get an exception
    The table 'public.Album' does not exist in the current database.
    , which doesn't make sense since I have checked on both the remote postgres db and the remote postgres shadow db and both have a public Album table. Any help is much appreciated
    n
    • 2
    • 1
  • a

    Alan

    05/23/2022, 3:28 AM
    logging
    (new PrismaClient()).album
    also shows
    {}
    n
    • 2
    • 1
  • s

    shibi

    05/23/2022, 8:34 AM
    Hi guys! I was using a loop but haven't find an answer for my question. I am in the middle of migration to prisma from prisma1 and I am wondering if I can do it partly and for some time have prisma1 and prisma2 in my project. I am using GraphQL for queries. I am aware of that if I want to get nested fields with Graphql query I need to use custom resolver as the docs says. Is it possible to fetch nested data which is available only in prisma2, using prisma1 query? Is it possible to create resolver which will use prisma2 to fetch nested object while using prisma1 client? For example:
    type User {
    id: String
    stats: Stats
    }
    type Stats {
    id: String
    }
    I have User in prisma1 and prisma2. And I have stats in prisma2 only. When I am overriding whole user query to prisma2 it works good with custom resolver to receive stats:
    Copy code
    User {
     stats: (parent, args, context) => {
      return context.newPrisma.user.findUnique({
        where: { id: parent.id },
      }).stats();
     }
    }
    But when I won't override user query to new prisma and will use old prisma to fetch user, it won't use stats resolver 😞 Is it possible to somehow force graphql/prisma to use prisma2 resolver inside prisma1 query? This is only simple example, application is complex so I would like to somehow keep it consistent for now and migrate it part by part. Thanks in advance and have a great Monday!
    n
    • 2
    • 1
  • a

    Adrian

    05/23/2022, 8:44 AM
    What do you think about removing the "Decimal" library from Prisma completely? I think it should be up to every development to decide if they want to use it. For me it crashing all my Rest API definitions Types since the API returns either a string or number but Prisma returns a Prisma.Decimal types. The following won't work because Prisma.Decimal does not match string type, even if when Prisma.Decimal is serialized to JSON, it becomes a string
    Copy code
    // prisma.client.ts
    export type Post {
      decimal: Prisma.Decimal
    }
    
    // post.entity.ts
    class Post {
      decimal: string
    }
    
    // post.controller.ts
    async function findOnePost(): Promise<Post> {
      return prisma.post.findOne() 
    }
    j
    o
    n
    • 4
    • 5
  • b

    Brothak

    05/23/2022, 9:07 AM
    I am getting and error Failed to convert rust
    String
    into napi
    string
    .
    Seems related to https://prisma.slack.com/archives/CA491RJH0/p1651696799848119 The thing is I can’t reproduce it constantly. It happens with same query but only when pass certain string as parameter. Tried on 3.14 and 3.12
    n
    • 2
    • 1
  • k

    Kate

    05/23/2022, 11:05 AM
    Hey Prisma community! Is there anyone who uses or is planning to use AWS Aurora or other Postgres in the cloud? Would you be willing to tell me about your experience? I'm working on an open-source serverless Postgress project and trying to understand what's the most useful thing to build at the moment
    n
    • 2
    • 2
  • k

    Kavita Nambissan

    05/23/2022, 12:11 PM
    Hey Prisma folks 👋! I wanted some help with an issue that I'm facing with Prisma client. I posted a discussion here about it, but haven't received any responses yet and since this is a blocker for me I would really appreciate some help 🙏 - https://github.com/prisma/prisma/discussions/13423. To reiterate, I renamed a column in my database, ran
    npx prisma db pull
    and
    npx prisma generate
    and now I cannot create any records due to an error
    The column new does not exist
    There was no column
    new
    to begin with. I don't use
    prisma migrate
    the database is modified manually by the team, and it makes sense to update the Prisma schema as per the database. This is only happening with this one table. Any suggestions on what could be wrong? Thank you!
    r
    • 2
    • 18
  • g

    Giorgia Mazzini

    05/23/2022, 1:55 PM
    Hi guys!!!My first time on slack..Hope I dont mess up stuff 😛 I love prisma but I m having troubles using queryRaw.. I just want to pass my custom query (built FE) as an input.. Is there a way not to use queryRawUnsafe???? 😭😣 thank you ❤️
    Copy code
    That's the error I get: :sob:{
        "errors": [
            {
                "message": "\nInvalid `prisma.queryRaw()` invocation:\n\n\n  Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near \"$1\"`",
                "locations": [
                    {
                        "line": 2,
                        "column": 3
                    }
                ],
                "path": [
                    "getCars"
                ],
                "extensions": {
                    "code": "INTERNAL_SERVER_ERROR",
                    "exception": {
                        "code": "P2010",
                        "clientVersion": "3.13.0",
                        "meta": {
                            "code": "42601",
                            "message": "db error: ERROR: syntax error at or near \"$1\""
                        },
                        "stacktrace": [
                            "Error: ",
                            "Invalid `prisma.queryRaw()` invocation:",
                            "",
                            "",
                            "  Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near \"$1\"`",
                            "    at Object.request (C:\\Users\\Giorgia.Mazzini\\Documents\\learninggraphql\\smarter01\\BE\\node_modules\\@prisma\\client\\runtime\\index.js:45629:15)",
                            "    at async Proxy._request (C:\\Users\\Giorgia.Mazzini\\Documents\\learninggraphql\\smarter01\\BE\\node_modules\\@prisma\\client\\runtime\\index.js:46456:18)"
                        ]
                    }
                }
            }
        ],
        "data": {
            "getCars": null
        }
    }
    That's my code
    Copy code
    getCars: (_parent, { input }, { prisma }) => {
        if(input){
    
            console.log(input) // --> SELECT * FROM car WHERE car."plate" ILIKE '%123%'  //type String
            const differentInput = '%123%'
    
            // const result =  prisma.$queryRaw`SELECT * FROM car WHERE car."plate" ILIKE '%123%'` // works
            // const result =  prisma.$queryRaw`SELECT * FROM car WHERE car."plate" ILIKE ${differentInput}` // works
            // const result =  prisma.$queryRawUnsafe(input) // Works
    
            const result =  prisma.$queryRaw`${input}` // Doesn`t work!!!!
            return result
    
        }
        // ... Other code
      }
    j
    • 2
    • 2
  • k

    Kelly Copley

    05/23/2022, 4:21 PM
    Any one have any idea why errors about column names wouldn't contain the name of the column? It super unhelpful to have an error like this:
    The column (not available) does not exist in the current database
    n
    • 2
    • 3
  • r

    Richard Piacentini

    05/23/2022, 4:50 PM
    Hello guys.
    👋 1
  • r

    Richard Piacentini

    05/23/2022, 4:54 PM
    I have an error when trying a search insensitive filtering with Prisma 3.13.0 and Sqlite3, did I do something wrong or is it Sqlite3 related?
    prisma.cities.findFirst({
    where: {
    name: {
    equals: name,
    mode: "insensitive",
    },
    },
    });
    j
    • 2
    • 33
  • j

    Jacob Martin

    05/23/2022, 5:38 PM
    Hey all. I switched from TypeORM to Prisma, which required me to make an initial Prisma migration (see screenshot) that does things like drop the TypeORM migrations table, rename tables to mach Prisma naming conventions, etc. This all worked perfectly and now my prod system is working entirely in Prisma, no issues. However, now when I go to add a 2nd migration, I'm unable to because the shadow database starts empty, and it can't drop tables that don't exist, and the initial migration drops tables that already existed in my prod database:
    Copy code
    » npx prisma migrate dev --name add_config --create-only
    Environment variables loaded from .env
    Prisma schema loaded from prisma/schema.prisma
    Datasource "db": PostgreSQL database "xxx", schema "public" at "<http://xxx.b.db.ondigitalocean.com:25060|xxx.b.db.ondigitalocean.com:25060>"
    
    Error: P3006
    
    Migration `20220222031047_init` failed to apply cleanly to the shadow database. 
    Error code: P1014
    Error:
    The underlying table for model `migrations` does not exist.
    n
    • 2
    • 4
1...577578579...637Latest