Skip to content

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Jan 14, 2026

Summary by CodeRabbit

  • New Features

    • Added regex pattern matching support for queries across adapters with PCRE and POSIX variants.
    • Introduced trigram indexes for optimized text search on supported databases.
    • Added elemMatch operator for filtering nested array elements.
    • Enhanced object attribute indexing capabilities.
  • Bug Fixes

    • Added timeout protection for regex patterns to prevent performance issues.
  • Improvements

    • More specific validation error messages for integer fields.

✏️ Tip: You can customize this high-level summary in your review settings.

ArnabChatterjee20k and others added 30 commits December 31, 2025 11:20
* support for object contains , not contains, equals, not equals
…ttributes, unique indexes, and fulltext indexes
…allow mixed lists and improve depth handling
Co-authored-by: Jake Barnby <jakeb994@gmail.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR introduces regex queries, trigram indexing, and object index capabilities across database adapters. It adds new query types (TYPE_REGEX, TYPE_ELEM_MATCH), an index constant (INDEX_TRIGRAM), and capability-checking methods across all adapters with varying implementation levels. Postgres and Mongo provide advanced support, while MariaDB and SQLite declare minimal support.

Changes

Cohort / File(s) Summary
Base Adapter API
src/Database/Adapter.php
Introduces five new abstract/concrete capability methods: getSupportForObjectIndexes(), getSupportForTrigramIndex(), getSupportForPCRERegex(), getSupportForPOSIXRegex(), and a composed helper getSupportForRegex() that returns logical OR of regex support.
SQL Adapter Implementations
src/Database/Adapter/MariaDB.php, src/Database/Adapter/MySQL.php, src/Database/Adapter/SQLite.php
Each adds concrete capability methods. MariaDB: all false except PCRE=true. MySQL: adds getSupportForObjectIndexes() + regex timeout handling via regexp_time_limit. SQLite: all three capability methods return false.
PostgreSQL Adapter
src/Database/Adapter/Postgres.php
Adds five capability methods with support for POSIX regex (true), trigram indexes (true), and object indexes (true); extends index creation to handle TRIGRAM and OBJECT types with GIN expressions; installs pg_trgm extension during database creation.
MongoDB Adapter
src/Database/Adapter/Mongo.php
Implements four capability methods (PCRE/POSIX/trigram/object); introduces three private helpers (convertStdClassToArray, flattenWithDotNotation, handleObjectFilters) to support nested object querying and dot-notation filtering.
SQL Generic Adapter
src/Database/Adapter/SQL.php
Adds getRegexOperator(): string returning 'REGEXP' and integrates it into getSQLOperator() for regex query type mapping.
Pool Adapter
src/Database/Adapter/Pool.php
Adds four delegation methods for new capability checks: getSupportForPCRERegex(), getSupportForPOSIXRegex(), getSupportForTrigramIndex(), getSupportForObjectIndexes().
Core Query Class
src/Database/Query.php
Adds two new public constants: TYPE_REGEX and TYPE_ELEM_MATCH; includes them in TYPES and LOGICAL_TYPES; adds static helpers regex() and elemMatch(); introduces protected isObjectAttribute property.
Core Database Class
src/Database/Database.php
Adds INDEX_TRIGRAM constant; replaces getSupportForObject() calls with getSupportForObjectIndexes() in validators; adds private isCompatibleObjectValue() for object type detection; refines object value handling in JSON filter paths.
Index Validator
src/Database/Validator/Index.php
Adds five new constructor parameters for capability flags (trigram, spatial, key, unique, fulltext); implements three new validation methods (checkValidIndex, checkTrigramIndexes, checkKeyUniqueFulltextSupport) with early guards; tightens control flow to reject unsupported configurations with precise messages.
Queries Validator
src/Database/Validator/Queries.php
Routes two new query types to FILTER method type: TYPE_ELEM_MATCH and TYPE_REGEX.
Query Filter Validator
src/Database/Validator/Query/Filter.php
Improves integer validation to derive bit width from schema size; hardens object query value validation with new recursive isValidObjectQueryValues() helper; adds TYPE_REGEX to single-value path; implements TYPE_ELEM_MATCH case with nested query validation and support guards.
Structure Validator
src/Database/Validator/Structure.php
Refines VAR_INTEGER validation to compute bit width from attribute size (64 if ≥8 bytes, else 32) with unsigned flag logic.
E2E Adapter Tests
tests/e2e/Adapter/Scopes/DocumentTests.php, tests/e2e/Adapter/Scopes/IndexTests.php, tests/e2e/Adapter/Scopes/ObjectAttributeTests.php, tests/e2e/Adapter/Scopes/SchemalessTests.php
Adds comprehensive test coverage: regex injection/ReDoS tests, trigram index lifecycle/validation, object attribute indexes, elemMatch behavior, nested object queries with dot notation. Includes new private helper createAttribute() in ObjectAttributeTests.
Unit Tests
tests/unit/Validator/IndexTest.php, tests/unit/Validator/QueriesTest.php, tests/unit/Validator/StructureTest.php, tests/e2e/Adapter/Scopes/AttributeTests.php
Adds trigram index validation unit test; extends object attribute query validation with new meta attribute test cases; updates error message expectations to reflect specific bit-width integer ranges.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Mongo object support and relevant queries #777: Implements Mongo object/elemMatch support with corresponding Query type helpers and object filter conversion methods—directly overlapping with Mongo adapter changes in this PR.
  • Query regex #775: Adds regex and trigram/index capability support across adapters with similar capability methods and Query::regex helper—substantial overlap with core functionality.
  • Object(json) attribute support for postgres #741: Adds object/JSON attribute and index support with getSupportForObjectIndexes and INDEX_OBJECT handling—parallel changes to object capability checking and validator wiring.

Suggested reviewers

  • ArnabChatterjee20k
  • fogelito

Poem

🐰 Hops with regex joy!
A trigram here, elemMatch there,
Postgres dances, Mongo sings—
Objects nest in SQL's care,
Queries match with fuzzy wings! 🌟

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 783193d and e491ed2.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (22)
  • src/Database/Adapter.php
  • src/Database/Adapter/MariaDB.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/MySQL.php
  • src/Database/Adapter/Pool.php
  • src/Database/Adapter/Postgres.php
  • src/Database/Adapter/SQL.php
  • src/Database/Adapter/SQLite.php
  • src/Database/Database.php
  • src/Database/Query.php
  • src/Database/Validator/Index.php
  • src/Database/Validator/Queries.php
  • src/Database/Validator/Query/Filter.php
  • src/Database/Validator/Structure.php
  • tests/e2e/Adapter/Scopes/AttributeTests.php
  • tests/e2e/Adapter/Scopes/DocumentTests.php
  • tests/e2e/Adapter/Scopes/IndexTests.php
  • tests/e2e/Adapter/Scopes/ObjectAttributeTests.php
  • tests/e2e/Adapter/Scopes/SchemalessTests.php
  • tests/unit/Validator/IndexTest.php
  • tests/unit/Validator/QueriesTest.php
  • tests/unit/Validator/StructureTest.php

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@abnegate abnegate changed the title added regex query support for the mongodb(schema + schemaless) Sync 3.x Jan 14, 2026
@abnegate abnegate closed this Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants