Skip to content

Commit 97dfe6e

Browse files
committed
feat(query-builder): update expr tree and condition transformation
1 parent a113286 commit 97dfe6e

1 file changed

Lines changed: 12 additions & 32 deletions

File tree

src/app/interactions/query-builder/query-builder-sql-sample/query-builder-sql-sample.component.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,24 @@ export class QueryBuilderSqlSampleComponent implements OnInit {
8484
const categoriesTree = new FilteringExpressionsTree(0, undefined, 'Categories', ['categoryId']);
8585
categoriesTree.filteringOperands.push({
8686
fieldName: 'name',
87+
ignoreCase: false,
8788
conditionName: IgxStringFilteringOperand.instance().condition('equals').name,
8889
searchVal: 'Beverages'
8990
});
9091

9192
const productsTree = new FilteringExpressionsTree(0, undefined, 'Products', ['supplierId']);
9293
productsTree.filteringOperands.push({
9394
fieldName: 'categoryId',
95+
ignoreCase: false,
9496
conditionName: IgxStringFilteringOperand.instance().condition('inQuery').name,
9597
searchTree: categoriesTree
9698
});
9799

98-
const suppliersTree = new FilteringExpressionsTree(0, undefined, 'Suppliers', ['supplierId', 'companyName', 'contactName', 'contactTitle']);
100+
const suppliersTree = new FilteringExpressionsTree(0, undefined, 'Suppliers', ['*']);
99101
suppliersTree.filteringOperands.push({
100102
fieldName: 'supplierId',
101103
conditionName: IgxStringFilteringOperand.instance().condition('inQuery').name,
104+
ignoreCase: false,
102105
searchTree: productsTree
103106
});
104107

@@ -149,12 +152,6 @@ export class QueryBuilderSqlSampleComponent implements OnInit {
149152
return `${field} = '${value}'`;
150153
case 'doesNotEqual':
151154
return `${field} <> '${value}'`;
152-
case 'contains':
153-
return `${field} LIKE '%${value}%'`;
154-
case 'startsWith':
155-
return `${field} LIKE '${value}%'`;
156-
case 'endsWith':
157-
return `${field} LIKE '%${value}'`;
158155
case 'greaterThan':
159156
return `${field} > ${value}`;
160157
case 'lessThan':
@@ -163,12 +160,14 @@ export class QueryBuilderSqlSampleComponent implements OnInit {
163160
return `${field} >= ${value}`;
164161
case 'lessThanOrEqualTo':
165162
return `${field} <= ${value}`;
163+
case 'contains':
164+
return `${field} LIKE '%${value}%'`;
166165
case 'doesNotContain':
167166
return `${field} NOT LIKE '%${value}%'`;
168-
case 'doesNotStartWith':
169-
return `${field} NOT LIKE '${value}%'`;
170-
case 'doesNotEndWith':
171-
return `${field} NOT LIKE '%${value}'`;
167+
case 'startsWith':
168+
return `${field} LIKE '${value}%'`;
169+
case 'endsWith':
170+
return `${field} LIKE '%${value}'`;
172171
case 'null':
173172
return `${field} IS NULL`;
174173
case 'notNull':
@@ -185,28 +184,9 @@ export class QueryBuilderSqlSampleComponent implements OnInit {
185184
return `${field} IN (${this.transformExpressionTreeToSqlQuery(operand.searchTree)})`;
186185
case 'notInQuery':
187186
return `${field} NOT IN (${this.transformExpressionTreeToSqlQuery(operand.searchTree)})`;
188-
case 'before':
189-
return `${field} < DATEFROMPARTS(${value.getFullYear()}, ${value.getMonth() + 1}, ${value.getDate()})`;
190-
case 'after':
191-
return `${field} > DATEFROMPARTS(${value.getFullYear()}, ${value.getMonth() + 1}, ${value.getDate()})`;
192-
case 'today':
193-
return `CONVERT(DATE, ${field}) = CONVERT(DATE, GETDATE())`;
194-
case 'yesterday':
195-
return `CONVERT(DATE, ${field}) = CONVERT(DATE, DATEADD(DAY, -1, GETDATE()))`;
196-
case 'thisMonth':
197-
return `YEAR(${field}) = YEAR(GETDATE()) AND MONTH(${field}) = MONTH(GETDATE())`;
198-
case 'lastMonth':
199-
return `${field} BETWEEN DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0) AND DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)`;
200-
case 'nextMonth':
201-
return `${field} BETWEEN DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) AND DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0)`;
202-
case 'thisYear':
203-
return `YEAR(${field}) = YEAR(GETDATE())`;
204-
case 'lastYear':
205-
return `YEAR(${field}) = YEAR(GETDATE()) - 1`;
206-
case 'nextYear':
207-
return `YEAR(${field}) = YEAR(GETDATE()) + 1`;
208187
default:
209-
return '';
188+
console.error(`Condition ${condition} is not implemented`);
189+
break;
210190
}
211191
}
212192

0 commit comments

Comments
 (0)