Does Prisma support `DELETE FROM ... RETURNING *`?
# orm-help
a
Does Prisma support
DELETE FROM ... RETURNING *
?
n
Hey Zain đŸ‘‹ You get the object/record which was deleted in the response of
delete
query as mentioned in this reference Does this work for you?
a
Am I misunderstanding the documentation for
delete()
? It seems like it only deletes one row, and deleting multiple rows (like
DELETE FROM ...
) does has to be done with
deleteMany()
, which only seems to return count
n
yes, that’s true
delete
just deleted one record! if you need to delete multiple records you would need to use
deleteMany
which returns number of records deleted. If you need to return something else you would need to use Raw Query to write DELETE SQL query.
a
I see, I thought so, thanks! In trying to use Raw Query I ran into another issue that I made a Prisma Discussion post for (https://github.com/prisma/prisma/discussions/12537), do you maybe know the answer to that or should I wait for someone to reply there?
n
We do support BigInts: https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields#working-with-bigint Can you try creating a record as mentioned in the docs above and see if you get the same value while fetching it?
a
I'm having the same problem. schema.prisma:
Copy code
// This is your Prisma schema file,
// learn more about it in the docs: <https://pris.ly/d/prisma-schema>

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Sample {
  revenue BigInt @id
}
code:
Copy code
import { PrismaClient, Sample } from '@prisma/client';
const prisma = new PrismaClient();

(async () => {
  const doc = await prisma.sample.create({
    data: {
      revenue: BigInt('99999999999999999'),
    },
  });

  const deletedDocs = await prisma.$queryRaw<Sample[]>`
    DELETE FROM "Sample"
    RETURNING *
  `;

  console.log(doc, deletedDocs, doc.revenue === deletedDocs[0].revenue);
})();
this outputs:
Copy code
{ revenue: 99999999999999999n } // doc
[ { revenue: 100000000000000000 } ] // deletedDocs
false // doc.revenue === deletedDocs[0].revenue
n
Can you please open a GitHub Issue describing the same behaviour as above? Our engineering team should be able to look into this