Alex Service
03/30/2022, 2:28 PM{
"data": {
"field_one": {
"field_two": "hello"
}
}
}
In postgres, I could quickly find records matching on field_two’s value like so:
SELECT doc_col FROM "MyTable" WHERE doc_col @> '{"data": {"field_one": {"field_two": "hello"}}}'
I have my table created in schema.prisma
with doc_col set as Json and enabled prisma’s “filterJson” previewFeature. I wrote the following graphql query, which takes 4 seconds:
query { myTables(where: {doc_col: {path: ["data", "field_one", "field_two"], equals: "0004"}}) }
Alex Service
03/30/2022, 2:30 PM#>
operator, but I’m unsure if there’s a way to encourage the desired behavior aboveNurul
04/01/2022, 11:13 AMAlex Service
04/05/2022, 3:33 PM#>
operator, which causes postgres to spend a long time searching for records. I worked around this by creating a custom resolver like so:
@Query(() => [MyModel])
async myModel(@Args() { key, take }: GetMyModelArgs) {
return await prisma.$queryRaw(Prisma.sql`SELECT * FROM "MyModel" WHERE "document" @> ${key} LIMIT ${take};`);
}
If I pass in a json string for key
, then everything runs very quickly 🙂