Next.js Discord

Discord Forum

Prisma ORM + Server Actions (help to prettify)

Unanswered
piscopancer posted this in #help-forum
Open in Discord
I want to use my DB queries in client components, for that I create server actions and bind them, in precise alignment to the docs. And I do so for every place in in my app, but server actions files are growing fast. Can I somehow make this workflow easier for me? E.g. I wish I could simply leave the whole db object in the server action and provide it with user.create... or course.findMany... callback - that would be so nice, but I cannot provide callbacks to the server from the client
async function _searchUsers(search: string) {
  const res = db.user.findMany({
    where: {
      OR: [
        { email: { contains: search } },
        { name: { contains: search } },
        { surname: { contains: search } },
        { middlename: { contains: search } },
      ],
    },
  })
  return res
}

export async function searchUsers(search: string) {
  return _searchUsers.bind(null, search)()
}

0 Replies