mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 14:14:10 +00:00
Fix insensitive contains
This commit is contained in:
parent
e57a40b328
commit
df4c67e5e1
@ -19,8 +19,6 @@ const OPERATORS = [
|
||||
'$null',
|
||||
'$notNull',
|
||||
'$between',
|
||||
// '$like',
|
||||
// '$regexp',
|
||||
'$startsWith',
|
||||
'$endsWith',
|
||||
'$contains',
|
||||
@ -214,17 +212,6 @@ const applyOperator = (qb, column, operator, value) => {
|
||||
qb.whereBetween(column, value);
|
||||
break;
|
||||
}
|
||||
// case '$regexp': {
|
||||
// // TODO:
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// // string
|
||||
// // TODO: use $case to make it case insensitive
|
||||
// case '$like': {
|
||||
// qb.where(column, 'like', value);
|
||||
// break;
|
||||
// }
|
||||
|
||||
// TODO: add casting logic
|
||||
case '$startsWith': {
|
||||
@ -316,9 +303,10 @@ const applyWhere = (qb, where) => {
|
||||
|
||||
const fieldLowerFn = qb => {
|
||||
// Postgres requires string to be passed
|
||||
if (qb.client.config.client === 'pg') {
|
||||
if (qb.client.config.client === 'postgres') {
|
||||
return 'LOWER(CAST(?? AS VARCHAR))';
|
||||
}
|
||||
|
||||
return 'LOWER(??)';
|
||||
};
|
||||
|
||||
|
||||
@ -253,10 +253,12 @@ const createQueryBuilder = (uid, db) => {
|
||||
qb.groupBy(state.groupBy);
|
||||
}
|
||||
|
||||
// if there are joins and it is a delete or update use a sub query
|
||||
if (state.where) {
|
||||
helpers.applyWhere(qb, state.where);
|
||||
}
|
||||
|
||||
// if there are joins and it is a delete or update use a sub query
|
||||
if (state.search) {
|
||||
qb.where(subQb => {
|
||||
helpers.applySearch(subQb, state.search, { alias: this.alias, db, uid });
|
||||
|
||||
@ -236,7 +236,7 @@ describe('Filtering API', () => {
|
||||
qs: {
|
||||
filters: {
|
||||
name: {
|
||||
$contains: 'product',
|
||||
$containsi: 'product',
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -252,7 +252,7 @@ describe('Filtering API', () => {
|
||||
qs: {
|
||||
filters: {
|
||||
name: {
|
||||
$contains: 'PrOdUct',
|
||||
$containsi: 'PrOdUct',
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -268,7 +268,7 @@ describe('Filtering API', () => {
|
||||
qs: {
|
||||
filters: {
|
||||
name: {
|
||||
$contains: 'production',
|
||||
$containsi: 'production',
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -282,7 +282,7 @@ describe('Filtering API', () => {
|
||||
qs: {
|
||||
filters: {
|
||||
name: {
|
||||
$contains: 'ProdUctIon',
|
||||
$containsi: 'ProdUctIon',
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -300,7 +300,7 @@ describe('Filtering API', () => {
|
||||
qs: {
|
||||
filters: {
|
||||
name: {
|
||||
$notContains: 'production',
|
||||
$notContainsi: 'production',
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -315,7 +315,7 @@ describe('Filtering API', () => {
|
||||
url: '/products',
|
||||
qs: {
|
||||
filters: {
|
||||
name: { $notContains: 'ProdUctIon' },
|
||||
name: { $notContainsi: 'ProdUctIon' },
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -329,7 +329,7 @@ describe('Filtering API', () => {
|
||||
url: '/products',
|
||||
qs: {
|
||||
filters: {
|
||||
name: { $notContains: 'product' },
|
||||
name: { $notContainsi: 'product' },
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -341,7 +341,7 @@ describe('Filtering API', () => {
|
||||
url: '/products',
|
||||
qs: {
|
||||
filters: {
|
||||
name: { $notContains: 'ProDuCt' },
|
||||
name: { $notContainsi: 'ProDuCt' },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user