Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(db-postgres): deep querying on json and rich text fields #9102

Merged
merged 3 commits into from
Nov 12, 2024

Conversation

r1tsuu
Copy link
Member

@r1tsuu r1tsuu commented Nov 11, 2024

What?

Allows to query on JSON / Rich Text fields in Postgres the same way as in Mongodb with any nesting level.

Example:
Data:

{
  json: {
    array: [
      {
        text: 'some-text', // nested to array + object
        object: {
          text: 'deep-text', // nested to array + 2x object
          array: [10], // number is nested to array + 2x object + array
        },
      },
    ],
  }
}

Query:

payload.find({
  collection: 'json-fields',
  where: {
    and: [
      {
        'json.array.text': {
          equals: 'some-text',
        },
      },
      {
        'json.array.object.text': {
          equals: 'deep-text',
        },
      },
      {
        'json.array.object.array': {
          in: [10, 20],
        },
      },
      {
        'json.array.object.array': {
          exists: true,
        },
      },
      {
        'json.array.object.notexists': {
          exists: false,
        },
      },
    ],
  },
})

How?

Utilizes the jsonb_path_exists postgres function

@r1tsuu r1tsuu changed the title feat(db-postges): deep querying on json and rich text fields feat(db-postgres): deep querying on json and rich text fields Nov 11, 2024
@r1tsuu r1tsuu marked this pull request as ready for review November 11, 2024 08:13
Copy link
Contributor

@DanRibbens DanRibbens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Looks like one merge conflict to resolve before it can be merged.

@r1tsuu r1tsuu force-pushed the feat/deep-json-querying-drizzle branch from 21f1fae to 272130d Compare November 11, 2024 17:46
@r1tsuu r1tsuu force-pushed the feat/deep-json-querying-drizzle branch from 4e106f6 to ced0ce5 Compare November 11, 2024 19:52
@r1tsuu r1tsuu merged commit b878daf into beta Nov 12, 2024
51 checks passed
@r1tsuu r1tsuu deleted the feat/deep-json-querying-drizzle branch November 12, 2024 07:26
Copy link

🚀 This is included in version v3.0.0-beta.128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants