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

    Ruslan Gonzalez

    02/05/2022, 3:11 PM
    I'm wondering if the interactive transactions can be callable out of the callback scope like in the image:
  • r

    Ruslan Gonzalez

    02/05/2022, 3:12 PM
    ...the idea is to use the this.data (which is the instance of prisma but from a service that is in the global scope via the Dependency Injection)
  • r

    Ruslan Gonzalez

    02/05/2022, 3:12 PM
    just for e.g. I can do something like this.data.request.findUnique(......) intead of using the prisma that comes in the callback, please let me know if that can be possible to continue getting the benefit of the transactions rollbacks if something is being throwed
  • l

    Levi Mason

    02/05/2022, 6:32 PM
    Hey there, I was hoping someone might review my schema. I'm fairly new to Prisma. The goal is to allow a user to have their own projects that only they can access, users can also be a part of a group which will have projects that anyone in the group can access, and to allow there to be a manager user that can access multiple groups and their projects. Any feedback would be much appreciated!
    Copy code
    generator client {
      provider = "prisma-client-js"
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    // -------------------------------------- //
    
    enum Role {
      NONE
      GROUP
      MANAGER
    }
    
    enum ProjectStatus {
      TEMPLATE
      IN_PROGRESS
      COMPLETED
    }
    
    enum TaskStatus {
      IDLE
      DOING
      DONE
    }
    
    // -------------------------------------- //
    
    model User {
      id    Int    @id @default(autoincrement())
      name  String
      email String @unique
      role  Role
    
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    
      projects Project[]
    
      Group   Group? @relation(fields: [groupId], references: [id])
      groupId Int?
    }
    
    model Group {
      id    Int    @id @default(autoincrement())
      name  String
      email String @unique
    
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    
      members  User[]
      projects Project[]
    
      Manager   Manager? @relation(fields: [managerId], references: [id])
      managerId Int?
    }
    
    model Manager {
      id     Int    @id @default(autoincrement())
      userId String @unique
      name   String
      email  String @unique
    
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    
      groups Group[]
    }
    
    // -------------------------------------- //
    
    model Project {
      id            Int           @id @default(autoincrement())
      createdAt     DateTime      @default(now())
      updatedAt     DateTime      @updatedAt
      projectStatus ProjectStatus
      archived      Boolean       @default(false)
      starred       Boolean       @default(false)
      name          String
      description   String
      tag           String
      deadline      DateTime
      links         String[]
    
      stories Story[]
    
      User    User?  @relation(fields: [userId], references: [id])
      userId  Int?
    
      Group   Group? @relation(fields: [groupId], references: [id])
      groupId Int?
    }
    
    model Story {
      id          Int      @id @default(autoincrement())
      createdAt   DateTime @default(now())
      updatedAt   DateTime @updatedAt
      description String
    
      tasks Task[]
    
      Project   Project? @relation(fields: [projectId], references: [id])
      projectId Int?
    }
    
    model Task {
      id        Int        @id @default(autoincrement())
      createdAt DateTime   @default(now())
      updatedAt DateTime   @updatedAt
      name      String
      status    TaskStatus
    
      Story   Story? @relation(fields: [storyId], references: [id])
      storyId Int?
    }
  • e

    ezeikel

    02/06/2022, 12:12 AM
    Hey all 👋🏿 having an issue with a
    findMany
    query and
    some
    operator: When running this query:
    Copy code
    const clusters = await prisma.cluster.findMany({
      where: {
        followers: { some: { id: userId } },
      },
    });
    I get this error:
    ConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: "unknown", message: "Command failed (Location40081): $in requires an array as a second argument, found: objectId)" } })
    The two related models look like this:
    Copy code
    model Cluster {
      id          String   @id @default(dbgenerated()) @map("_id") @db.ObjectId
      name        String
      description String?
      sparks      Spark[]  @relation(fields: [sparkIDs])
      sparkIDs    String[] @db.Array(ObjectId)
      user        User     @relation("ClusterOwner", fields: [ownerID], references: [id])
      ownerID     String   @db.ObjectId
      shared      Boolean  @default(false)
      deleted     Boolean  @default(false)
      followers   User[]   @relation("ClusterFollowers", fields: [followerIDs])
      followerIDs String[] @db.Array(ObjectId)
      legacyId    String?  @unique
      meta        Meta[]   @relation(fields: [metaIDs])
      metaIDs     String[] @db.Array(ObjectId)
      log         Log[]
      createdAt   DateTime @default(now())
      updatedAt   DateTime @updatedAt
    
      @@unique([ownerID, id])
      @@map("clusters")
    }
    
    model User {
      id               String         @id @default(dbgenerated()) @map("_id") @db.ObjectId
      firstName        String?
      lastName         String?
      name             String?
      email            String         @unique // TODO: doesnt seem to be being enforced
      type             UserType       @default(EXTERNAL_SEA_USER)
      pin              String         @default("0000")
      role             UserRole       @default(USER)
      deleted          Boolean        @default(false)
      legacyId         String?        @unique
      clusterFollowers Cluster[]      @relation("ClusterFollowers")
      clusterOwner     Cluster[]      @relation("ClusterOwner")
      processedForUser Log[]          @relation("ProcessedForUser")
      processedByUser  Log[]          @relation("ProcessedByUser")
      sparks           Spark[]
      subscriptions    Subscription[]
      createdAt        DateTime       @default(now())
      updatedAt        DateTime       @updatedAt
    
      @@map("users")
    }
    Any ideas on what I might be doing wrong or is this a bug with the mongo connector?
    • 1
    • 5
  • p

    Philipp Minder

    02/06/2022, 10:48 PM
    hello maybe someone can help me. I have an explicit Relation. I want to update the programs in activity everytime when i do an update on activity. At the Moment i get an Primary Constraint Fail. What can i do?
  • f

    Fergus Meiklejohn

    02/07/2022, 3:36 AM
    Hey all, I just had an interesting JS type problem removing nulls from Prisma queries which might be useful to someone: I'm using this function to remove nulls from my Prisma get queries:
    Copy code
    export function removeNull(obj: any): any {
      if (!obj) return obj;
      if (obj instanceof Date) return obj;
      else {
        return Object.fromEntries(
          Object.entries(obj)
            .filter(([_, v]) => v != null)
            .map(([k, v]) => [k, v === Object(v) ? removeNull(v) : v])
        );
      }
    }
    And before I added the instanceof check it was removing all Date types from the response because JS types Date as an object 🤪 The result was returning objects with {insertedAt: {} ... } Maybe I'm missing a native Prisma method to remove nulls from queries??
  • f

    Fergus Meiklejohn

    02/07/2022, 4:08 AM
    If a Prisma query returns many rows it returns an object:
    Copy code
    {0: {}, 1: {}, 2: {} etc...}
    Has there been discussion about returning an array instead? An array would be more useful than an object whose keys are just the position in an array anyway. We can get the array with Object.values I know but still it seems like an unnecessary step..
    k
    n
    • 3
    • 6
  • m

    Miqhtie

    02/07/2022, 5:49 AM
    How can I get autocomplete working with prisma in vscode using typescript?
    n
    • 2
    • 1
  • e

    Ethan Zoller

    02/07/2022, 6:32 AM
    How can I do a query where I'm saying NOT for a field with two values. For example, I want users without the name "Ethan" or "Jeff".
    n
    • 2
    • 1
  • j

    Jannik Schmiedl

    02/07/2022, 7:18 AM
    Hey, has this repository been deleted recently? github.com/prisma/prisma-client-lib-go Its a dependency of the generated go-client for prisma1. Fetching dependencies fails since Friday because of this prisma-client-lib-go.
    n
    f
    • 3
    • 9
  • g

    Greger gregerson

    02/07/2022, 2:56 PM
    I've looked up and down in the prisma docs and can't find if there is any API for getting the length of a scalar list, is there one?
  • m

    Maotora

    02/07/2022, 3:19 PM
    Hey, curious how can I construct a query to fetch tag which has the most contents (relations)? Eg.
    Copy code
    Tag {
        contents    Content[]
        name        String      @unique
    }
    Would need to order tag which has most content first.
    • 1
    • 1
  • m

    Maguire Krist

    02/07/2022, 4:12 PM
    Why is it that, when migrating my existing schema to modify a many-to-one relationship to a many-to-many, that I can't preform the creation of a table using
    relation: { connect: [ { id: num }, ...]}
  • m

    Maguire Krist

    02/07/2022, 4:31 PM
    I found a bug in Prisma but I'm legit too lazy to reported
  • m

    Maguire Krist

    02/07/2022, 4:31 PM
    report it
  • m

    Maguire Krist

    02/07/2022, 4:32 PM
    Because I know y'all are going to want a whole ass report
    fast parrot 1
    😂 2
  • m

    Michael Aubry

    02/07/2022, 5:27 PM
    In my schema I auto generate ids for this particular model
    id          String        @id @default(cuid())
    I have a special case where I need to generate the record using an id I generate. Is it possible to pass a custom id into
    prisma.model.create
    ?
    c
    • 2
    • 1
  • s

    Shayne Czyzewski

    02/07/2022, 6:44 PM
    Hey everyone! I had a question about upgrading from Prisma 2.22.1 to the latest version (3.9.1). It seems when I run
    migrate dev
    after upgrading, it wants to create a new migration on existing SQLite and PostgreSQL databases. For SQLite, it wants to recreate all my tables (by creating a new migration basically with
    -- RedefineTables
    and
    -- RedefineIndex
    ). For PostgreSQL, it does
    -- DropForeignKey
    ,
    -- AddForeignKey
    , and
    -- RenameIndex
    (that I have seen so far). My main question is, is this expected and I should just add the new migration when upgrading (vs some other approach)? Any other tips/considerations to help migrate existing databases between these major versions? I did see this: https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/upgrading-to-prisma-3 Thanks!
  • u

    user

    02/07/2022, 7:54 PM
    Tips for Content Creation by DevRel - Part 2 #shorts

    https://www.youtube.com/watch?v=YQj6RY7ENd0▾

    📷 If you're looking to improve your content, or are considering starting to create content, follow these tips from a developer relations perspective! 👀 #shorts #prisma #tipsforcontent
    👀 1
    e
    • 1
    • 1
  • n

    Nick B

    02/08/2022, 12:37 AM
    Hi everyone! I have a general question about strategy. I have a nextjs app w/ my db on heroku. What I'm imagining I want is a staging DB that exists in order to test updates to my schema and data before actually going live. Have any of you done this? What would it look like to set this up? Is this a good idea? Is there a better idea? Any other thoughts? Thanks!
    a
    • 2
    • 2
  • p

    Peter Kellner

    02/08/2022, 12:42 AM
    I'm considering replacing my graphql sqlserver implementation with Apollo and Prisma. I've got it basically working in NextJS, but I realize there is one step that is going to be a huge drag on the conversion and I'm wondering if there is a simple workaround like there is in EntityFramework which is what I'm converting from. Specifically, when. did the db pull, I got all my 100 or so tables like this:
    Copy code
    model DiscussionItem {
      Id           Int       @id(map: "PK__Discussi__3214EC0771E234E0") @default(autoincrement())
      DiscussionId Int
      AttendeesId  Int
      DateEntered  DateTime  @db.DateTime
      MessageText  String    @db.NVarChar(4000)
      Attendees    Attendees @relation(fields: [AttendeesId], references: [Id], onUpdate: NoAction, map: "DiscussionItem_fk")
    }
    The real hassle is that all of the schema begins with uppercase "I" and I want those properties to translate easily to camelcase on the ApolloServer side. That is, id, attendeesId, discussionId, etc. The issue is the accepted norm for database columns is begin with capital, the accept norm for JavaScript variables is begin with lowercase. Is there an option for that?
    a
    • 2
    • 4
  • s

    Sabin Adams

    02/08/2022, 1:10 AM
    @Peter Kellner You can use the @map and @@map attributes to map fields in your schema to the underlying names in the database. Essentially allowing you to pick whatever convention you like for the client while maintaining the names in the actual DB. https://www.prisma.io/docs/concepts/components/prisma-schema/names-in-underlying-database#mapping-collectiontable-and-fieldcolumn-names
  • p

    Peter Kellner

    02/08/2022, 1:41 AM
    Thanks @Sabin Adams I'm feeling a little slow here. Does this mean that the schema.prisma is always the same but some how you reference the variables in your client code makes them look different?
  • p

    Peter Kellner

    02/08/2022, 1:51 AM
    @Sabin Adams I think I get it now. @@map does the table name and just @map does the column name. That would mean I'd have to go slowly and carefully through my generated schema and for every column add a @map table? That sounds like it would be no fun, not to mention all the typo's I'd probably leave behind. I guess this means there is no way to have this happen automatically like it does in Microsoft's EntityFramework?
  • s

    Sabin Adams

    02/08/2022, 2:13 AM
    @Peter Kellner At the moment that is correct, there isn't an option to have that happen automatically. I had a similar problem with tons (50+) of tables on a large application I was working on. I ended up just fixing naming conventions as I needed specific tables and columns
  • s

    Sabin Adams

    02/08/2022, 2:14 AM
    So for example, I would introspect and leave it as is. Then in a PR where I accessed the
    Users
    table, I would fix the conventions in that model as part of the PR
  • s

    Sabin Adams

    02/08/2022, 2:14 AM
    Slowly everything has been getting moved over model by model and everything in the code follows those good conventions
  • s

    Sabin Adams

    02/08/2022, 2:27 AM
    E.G: If I needed to use the
    User
    model for the first time. It might look like
    Copy code
    model users {
        Id Int @id @default(autoincrement())
        first_name String
        last_name String
    }
    I'd switch it to
    Copy code
    model User {
        id Int @id @default(autoincrement()) @map("Id")
        firstName String @map("first_name")
        lastName  String @map("last_name")
        @@map("users")
    }
  • s

    Sophia

    02/08/2022, 4:21 AM
    Has anyone solved the missing
    '_http_common'
    issue? I see a lot of issues on GitHub (and mentions in search here), but haven't found a solution yet. Thanks. ☺️
1...542543544...637Latest