i have a question ! how i can hide password when ...
# prisma-client
r
i have a question ! how i can hide password when i do this query ? please.
Copy code
const prisma = new PrismaClient()
  const posts  = await prisma.post.findMany({
    include : {
      user : true
    },
    orderBy: {
      created_at: 'desc',
    },
    

  })
βœ… 1
m
I think you have a "select" option for that object, where you can set password to false
Copy code
// Returns an object or null
const getUser: object | null = await prisma.user.findUnique({
  where: {
    id: 22,
  },
  select: {
    email: true,
    name: true,
  },
})
r
@Marcos Iglesias i read it , but i have trouble whit type , coz password not boolean type
in mongoose exist a generic Omit<> but on prisma not exists.
m
no, it has nothing to do with it, you are setting like
flags
, in this case a boolean, to the fields that are going to beeing shown/retrieved or not.
have you tried with the select option?
r
yes i tried
m
It works for me, excluding a password for example, wich is a string...
not a boolean
r
4
m
try without the "user" parent
just the fields
and, I think, it goes after the order by... but im just suposing
r
same
Type '{ password: false; }' is not assignable to type 'PostSelect'. Object literal may only specify known properties, and 'password' does not exist in type 'PostSelect'.ts(2322)
m
try here
oh, I think you have a nested select there
Copy code
prisma.post.findMany({
  select: {
    user_name: true, (for example, add fields as needed)
    posts: {  // i.e. here we are nesting posts
      select: {
        title: true, // here we are just retrieving the title of the posts
      },
    },
  },
})
r
humm
nice , thanx iΔΊl try
i'll try
πŸ‘ 1
m
Copy code
const users = await prisma.user.findMany({
  // Returns all user fields
  include: {
    posts: {
      // Returns only the titles of the posts
      select: {
        title: true,
      },
    },
  },
})
good luck! let me know
m
Which editor do you use @Rogerio Orioli? It should help you by providing helpers while typing so you know what you have there and you can deduce how it should look like
βœ… 1
r
inside of include works πŸ˜„
Copy code
const prisma = new PrismaClient()
  const posts  = await prisma.post.findMany({
    include : {
      user : {
        select :{
          userName :true,
          avatar : true
        }
      },
      categorie : true
    },
    orderBy: {
      created_at: 'desc',
    },  
  })
πŸ‘‹ 1
m
perfect πŸ˜„
r
thanx guys you rock
πŸ’ͺ 1
m
nicee !!
r
@Mateusz Stepaniuk i use Vscode
m
So you definitely should have completions as VSCode is powered by TypeScript, just as Prisma is.