diff --git a/app/config/example.yaml b/app/config/example.yaml index e252b5a4..4fd30695 100644 --- a/app/config/example.yaml +++ b/app/config/example.yaml @@ -27,6 +27,11 @@ tables: filters: - ['created_at', 'gt', 'expr: date_sub(now(), interval 60 day)'] + # Dump only CMS pages without "FAQ" in their meta title + cms_page: + filters: + - ["expr: COALESCE(meta_title, '')", 'notLike', '%FAQ%'] + # Anonymize a table named "my_custom_table" my_custom_table: converters: diff --git a/src/Dumper/Mysql/TableFilterExtension.php b/src/Dumper/Mysql/TableFilterExtension.php index 4d3f8a9e..8cea38cc 100644 --- a/src/Dumper/Mysql/TableFilterExtension.php +++ b/src/Dumper/Mysql/TableFilterExtension.php @@ -205,7 +205,7 @@ private function applyTableConfigToQueryBuilder(QueryBuilder $queryBuilder, Tabl $whereExpr = call_user_func_array( $callable, - [$this->connection->quoteIdentifier($filter->getColumn()), $value] + [$this->getFilterColumn($filter), $value] ); $queryBuilder->andWhere($whereExpr); @@ -261,8 +261,21 @@ public function getWhereSql(QueryBuilder $queryBuilder): string return substr($sql, strpos($sql, ' WHERE ') + 7); } + /** + * Get a filter column. + * If it was prefixed with `expr:`, returns the raw SQL statement instead of a quoted identifier. + */ + private function getFilterColumn(Filter $filter): string + { + $column = $filter->getColumn(); + + return str_starts_with($column, 'expr:') ? + ltrim(substr($column, 5)) : $this->connection->quoteIdentifier($column); + } + /** * Get a filter value. + * If it was prefixed with `expr:`, returns the raw SQL statement instead of a quoted value. * * @throws UnexpectedValueException */