I have a Prisma model defining events stored in a PostgreSQL database. One of the fields is additionalFields, which is a JSON object. How can I construct a Prisma query to retrieve events, matching even if the additionalFields contain additional properties beyond those specified in the query? Here’s my model:
model Event {
id Int @id @default(autoincrement())
eventType String
additionalFields Json
}
Suppose I have an event in the database with the following data:
{
id: 1,
eventType: "type1",
additionalFields: {
"name": "This is a name",
"amount": 123
}
I want to construct a Prisma query that can match this event even if the additionalFields contain extra properties. For instance, the query below should match the event above:
const dataToQuery {
eventType: "type1",
additionalFields: {
"name": "This is a name",
"amount": 123,
"foo": "bar",
"whatever": "value"
}
}
but this should not match,since there is a missing property:
const dataToQuery {
eventType: "type1",
additionalFields: {
"name": "This is a name",
}
}
I don’t mind a raw SQL query, thanks.