prisma / prisma1

💾 Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB) [deprecated]
https://v1.prisma.io/docs/
Apache License 2.0
16.55k stars 863 forks source link

JSON filters #148

Closed marktani closed 2 years ago

marktani commented 7 years ago

The ability to filter a node based on the keys or values of a JSON field. Suggestion:

query {
  allPosts(filter: {
    myJsonField: {
      has_key: "myKey"
      int_gte: {
        key: "count"
        value: 23
      }
    }
  }) {
    id
  }
}
marktani commented 7 years ago

Further inspiration: https://docs.puppet.com/puppetdb/4.3/api/query/examples-pql.html#fact-resource-and-resource-parameter-filtering

matthiasak commented 7 years ago

would it be possible to filter on Json columns? maybe for just testing if empty or null?

allRecords(filter:{ jsonColumn_empty: true}){ ... }
PierBover commented 7 years ago

Could Algolia be used for querying JSON fields?

jdbence commented 7 years ago

Add JSON support using dot notation. Could require depth or exact flat map in the field's settings to limit search.

// Example JSON
{
  "some": {
    "deep": {
      "value": 99
    },
    "nested": [
      {
         "value": 88
      },
      {
         "value": 77
      }
    ]
  }
}

// Filter obj
query {
  allPosts(filter: {
    jsonFieldName.some.deep.value_gte : 23
  }
}) {
    id
  }
}

// Filter array
query {
  allPosts(filter: {
    jsonFieldName.some.nested {
      value_gte : 23
    }
  }
}) {
    id
  }
}
rohitghatol commented 6 years ago

Is this feature still on horizon? Or Would the Implementation for "Interface types" #83 cover this feature?

johnslemmer commented 6 years ago

This is something I'm interested in. But I also think we could start iteratively.

First, I think there needs to be a way to query scalar list fields and Json type fields for whether or not they are null (or unset or emtpy). Maybe something like this:

query {
  allPosts(where: {
    myJsonField_null: true
  }) {
    id
  }
}

Or maybe just providing a raw strict equality and that way you could use the NOT query if you want or even do strict comparison of one JSON value to another.:

query {
  allPosts(where: {
    myJsonField: null
  }) {
    id
  }
}

This seems like something that I hope could happen sooner rather than later without needing to decide on a whole schema for deep Json field queries.

yocheved commented 6 years ago

Is there any estimated date for this feature? We really need this!!

carstenbaumhoegger commented 6 years ago

hey! We're also desperately waiting for this to be implemented! @marktani is this still on the roadmap?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

davidboom95 commented 5 years ago

Any advice on this feature?

entrptaher commented 5 years ago

Given this mongo schema,

var instanceSchema = new mongoose.Schema({
  name: String,
  data: Array
});

I can push data like below,

var example = new Instance({
  name: "Example.com",
  data: [
    {"Property 1": "Example.com"},
    {"Property 2": "Something else"},
  ]
});

And query like this,

Instance.findOne({
  name: "Example.org",
  "data.2.Property 3": "Something else 3"
})

I cannot find any way to get similar result with prisma/graphql.

I ended up creating my own filter using mingo, but I suppose prisma can implement it somewhere and abstract it away.

entrptaher commented 5 years ago

I needed a solution to filter schemaless Json data (array of objects). So there were two path for me. Either create a schema on the fly, or add some filters manually.

If anyone want's to see the minimal implementation I did for JSON filter, check my playground-json-query-mingo repo.

All suggestions are welcome.

Simple filter: image

Complex filter: image

kiano0sh commented 5 years ago

Any solution ?

m1m6 commented 4 years ago

any solution?