typeorm#WhereExpression TypeScript Examples
The following examples show how to use
typeorm#WhereExpression.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CashActionRepository.ts From cashcash-desktop with MIT License | 6 votes |
private createWhereClause<T extends WhereExpression>(
qb: T,
parameters: RuleParameters = {},
): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.searchString && parameters.searchString.length > 1) {
qb = qb.andWhere(`INSTR(LOWER(r.name), LOWER('${parameters.searchString}')) > 0`);
}
if (parameters.accountIdList && parameters.accountIdList.length > 0) {
qb = qb.andWhere(`cashAccount.id IN ( ${parameters.accountIdList.join(', ')} )`);
}
return qb;
}
Example #2
Source File: CashBudgetSplitRepository.ts From cashcash-desktop with MIT License | 6 votes |
private createWhereClause<T extends WhereExpression>(
qb: T,
parameters: SplitParameters = simpleTransactionParameters,
): T {
if (parameters.splitAccountIdList && parameters.splitAccountIdList.length > 0) {
qb = qb.andWhere(`s.accountId IN ( ${parameters.splitAccountIdList.join(', ')} )`);
}
const repo = this.manager.getCustomRepository(CashBudgetTransactionRepository);
let cashBudgetTransactionIdQb = repo.createQueryBuilder('t').select('t.id');
cashBudgetTransactionIdQb = repo.createWhereClause(cashBudgetTransactionIdQb, parameters);
qb = qb.andWhere(`s.transactionId IN ( ${cashBudgetTransactionIdQb.getQuery()} )`);
return qb;
}
Example #3
Source File: CashFilterRepository.ts From cashcash-desktop with MIT License | 6 votes |
private createWhereClause<T extends WhereExpression>(
qb: T,
parameters: RuleParameters = {},
): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.searchString && parameters.searchString.length > 1) {
qb = qb.andWhere(`INSTR(LOWER(r.name), LOWER('${parameters.searchString}')) > 0`);
}
if (parameters.accountIdList && parameters.accountIdList.length > 0) {
qb = qb.andWhere(`cashAccount.id IN ( ${parameters.accountIdList.join(', ')} )`);
}
return qb;
}
Example #4
Source File: CashImportConfigRepository.ts From cashcash-desktop with MIT License | 6 votes |
private createWhereClause<T extends WhereExpression>(
qb: T,
parameters: ImportConfigParameters = {},
): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
'c',
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
'c',
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.searchString && parameters.searchString.length > 1) {
qb = qb.andWhere(`INSTR(LOWER(c.name), LOWER('${parameters.searchString}')) > 0`);
}
return qb;
}
Example #5
Source File: CashRateRepository.ts From cashcash-desktop with MIT License | 6 votes |
private createWhereClause<T extends WhereExpression>(
qb: T,
parameters: RateParameters = {},
): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.currencyIdList && parameters.currencyIdList.length > 0) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(r.fromCurrencyId IN ( ${parameters.currencyIdList.join(
', ',
)} ) OR r.toCurrencyId IN ( ${parameters.currencyIdList.join(', ')} ))`,
);
}
return qb;
}
Example #6
Source File: CashRuleRepository.ts From cashcash-desktop with MIT License | 6 votes |
private createWhereClause<T extends WhereExpression>(
qb: T,
parameters: RuleParameters = {},
): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.searchString && parameters.searchString.length > 1) {
qb = qb.andWhere(`INSTR(LOWER(r.name), LOWER('${parameters.searchString}')) > 0`);
}
if (parameters.accountIdList && parameters.accountIdList.length > 0) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(filterCashAccount.id IN ( ${parameters.accountIdList.join(
', ',
)} ) OR actionCashAccount.id IN ( ${parameters.accountIdList.join(', ')} ))`,
);
}
return qb;
}
Example #7
Source File: CashSplitRepository.ts From cashcash-desktop with MIT License | 6 votes |
private createWhereClause<T extends WhereExpression>(
qb: T,
parameters: SplitParameters = simpleTransactionParameters,
): T {
if (parameters.splitAccountIdList && parameters.splitAccountIdList.length > 0) {
qb = qb.andWhere(`s.accountId IN ( ${parameters.splitAccountIdList.join(', ')} )`);
}
const repo = this.manager.getCustomRepository(CashTransactionRepository);
let cashTransactionIdQb = repo.createQueryBuilder('t').select('t.id');
cashTransactionIdQb = repo.createWhereClause(cashTransactionIdQb, parameters);
qb = qb.andWhere(`s.transactionId IN ( ${cashTransactionIdQb.getQuery()} )`);
return qb;
}
Example #8
Source File: CashTagRepository.ts From cashcash-desktop with MIT License | 6 votes |
private createWhereClause<T extends WhereExpression>(qb: T, parameters: TagParameters = {}): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
'r',
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.searchString && parameters.searchString.length > 1) {
qb = qb.andWhere(`INSTR(LOWER(r.name), LOWER('${parameters.searchString}')) > 0`);
}
return qb;
}
Example #9
Source File: QueryBuilderUtil.ts From cashcash-desktop with MIT License | 6 votes |
static addDateFilter<T extends WhereExpression>(
qb: T,
tableAlias: string,
dateFieldName: string,
fromDate?: Date,
toDate?: Date,
): T {
if (fromDate && toDate) {
const fromDateString = fromDate.toISOString();
const toDateString = toDate.toISOString();
qb = qb.andWhere(
`${tableAlias}.${dateFieldName} BETWEEN datetime('${fromDateString}') AND datetime('${toDateString}')`,
);
} else if (fromDate) {
const fromDateString = fromDate.toISOString();
qb = qb.andWhere(`${tableAlias}.${dateFieldName} >= datetime('${fromDateString}')`);
} else if (toDate) {
const toDateString = toDate.toISOString();
qb = qb.andWhere(`${tableAlias}.${dateFieldName} < datetime('${toDateString}')`);
}
return qb;
}
Example #10
Source File: CashAccountRepository.ts From cashcash-desktop with MIT License | 5 votes |
private createWhereClause<T extends WhereExpression>(
qb: T,
parameters: AccountParameters = simpleAccountParameters,
): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
'a',
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
'a',
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.accountIdList && parameters.accountIdList.length > 0) {
qb = qb.andWhere(`a.id IN ( ${parameters.accountIdList.join(', ')} )`);
}
if (parameters.currencyIdList && parameters.currencyIdList.length > 0) {
qb = qb.andWhere(`a.currencyId IN ( ${parameters.currencyIdList.join(', ')} )`);
}
if (parameters.accountTypeList && parameters.accountTypeList.length > 0) {
qb = qb.andWhere(
`a.type IN ( ${parameters.accountTypeList.map((item) => `'${item}'`).join(', ')} )`,
);
}
if (parameters.isLeaf) {
qb = qb.andWhere(`a.isDirectory = 0`);
}
if (parameters.searchString) {
qb = qb.andWhere(`a.name LIKE %${parameters.searchString}%`);
}
return qb;
}
Example #11
Source File: CashBudgetTransactionRepository.ts From cashcash-desktop with MIT License | 5 votes |
createWhereClause<T extends WhereExpression>(
qb: T,
parameters: TransactionParameters = simpleTransactionParameters,
): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
't',
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
't',
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.accountIdList && parameters.accountIdList.length > 0) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(t.fromSplitAccountId IN (${parameters.accountIdList.join(
', ',
)}) OR t.toSplitAccountId IN (${parameters.accountIdList.join(', ')}))`,
);
}
if (parameters.fromAccountIdList && parameters.fromAccountIdList.length > 0) {
qb = qb.andWhere(
`t.fromSplitAccountId IN (${parameters.fromAccountIdList.join(', ')})`,
);
}
if (parameters.toAccountIdList && parameters.toAccountIdList.length > 0) {
qb = qb.andWhere(`t.toSplitAccountId IN (${parameters.toAccountIdList.join(', ')})`);
}
if (parameters.currencyIdList && parameters.currencyIdList.length > 0) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(t.fromSplitCurrencyId IN (${parameters.currencyIdList.join(
', ',
)}) OR t.toSplitCurrencyId IN (${parameters.currencyIdList.join(', ')}))`,
);
}
if (parameters.amountLessThan) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(abs(t.fromSplitAmountCent) < ${
parameters.amountLessThan * 100
} OR abs(t.toSplitAmountCent) < ${parameters.amountLessThan * 100})`,
);
}
if (parameters.amountGreaterThan) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(abs(t.fromSplitAmountCent) > ${
parameters.amountGreaterThan * 100
} OR abs(t.toSplitAmountCent) > ${parameters.amountGreaterThan * 100})`,
);
}
if (parameters.amountEquals) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(abs(t.fromSplitAmountCent) == ${
parameters.amountEquals * 100
} OR abs(t.toSplitAmountCent) == ${parameters.amountEquals * 100})`,
);
}
if (parameters.transactionTypeList && parameters.transactionTypeList.length > 0) {
const formatedList = parameters.transactionTypeList.map((s) => `'${s}'`).join(', ');
qb = qb.andWhere(`t.type IN ( ${formatedList} )`);
}
return qb;
}
Example #12
Source File: CashTransactionRepository.ts From cashcash-desktop with MIT License | 4 votes |
createWhereClause<T extends WhereExpression>(
qb: T,
parameters: TransactionParameters = simpleTransactionParameters,
alias: string = 't',
): T {
qb = QueryBuilderUtil.addDateFilter(
qb,
alias,
'createdDate',
parameters.createdDateFrom,
parameters.createdDateTo,
);
qb = QueryBuilderUtil.addDateFilter(
qb,
alias,
'updatedDate',
parameters.updatedDateFrom,
parameters.updatedDateTo,
);
if (parameters.accountIdList && parameters.accountIdList.length > 0) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(${alias}.fromSplitAccountId IN (${parameters.accountIdList.join(
', ',
)}) OR ${alias}.toSplitAccountId IN (${parameters.accountIdList.join(', ')}))`,
);
}
if (parameters.fromAccountIdList && parameters.fromAccountIdList.length > 0) {
qb = qb.andWhere(
`${alias}.fromSplitAccountId IN (${parameters.fromAccountIdList.join(', ')})`,
);
}
if (parameters.toAccountIdList && parameters.toAccountIdList.length > 0) {
qb = qb.andWhere(
`${alias}.toSplitAccountId IN (${parameters.toAccountIdList.join(', ')})`,
);
}
if (parameters.currencyIdList && parameters.currencyIdList.length > 0) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(${alias}.fromSplitCurrencyId IN (${parameters.currencyIdList.join(
', ',
)}) OR ${alias}.toSplitCurrencyId IN (${parameters.currencyIdList.join(', ')}))`,
);
}
if (parameters.tagIdList && parameters.tagIdList.length > 0) {
const formatedList = [...parameters.tagIdList]
.sort()
.map((item) => `${TAG_SEPARATOR}${item}${TAG_SEPARATOR}`);
qb = qb.andWhere(`LIKE('%${formatedList.join('%')}%',${alias}.tagIdList)`);
}
if (parameters.amountLessThan) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(abs(${alias}.fromSplitAmountCent) < ${
parameters.amountLessThan * 100
} OR abs(${alias}.toSplitAmountCent) < ${parameters.amountLessThan * 100})`,
);
}
if (parameters.amountGreaterThan) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(abs(${alias}.fromSplitAmountCent) > ${
parameters.amountGreaterThan * 100
} OR abs(${alias}.toSplitAmountCent) > ${parameters.amountGreaterThan * 100})`,
);
}
if (parameters.amountEquals) {
// tslint:disable-next-line:max-line-length
qb = qb.andWhere(
`(abs(${alias}.fromSplitAmountCent) == ${
parameters.amountEquals * 100
} OR abs(${alias}.toSplitAmountCent) == ${parameters.amountEquals * 100})`,
);
}
if (parameters.searchString && parameters.searchString.length > 1) {
const stringQuery = Array.from(
CashTransactionIndexUtils.generateListItem(parameters.searchString),
).join(' AND ');
if (stringQuery.length > 0) {
const repo = this.manager.getCustomRepository(CashTransactionIndexRepository);
const cashTransactionIdQb = repo
.createQueryBuilder('cashTransactionIdx')
.select('rowId')
.andWhere(`cash_transaction_idx MATCH '{description} :${stringQuery}'`);
qb = qb.andWhere(`${alias}.id IN ( ${cashTransactionIdQb.getQuery()} )`);
}
}
if (parameters.detailSearchString && parameters.detailSearchString.length > 1) {
const stringQuery = Array.from(
CashTransactionIndexUtils.generateListItem(parameters.detailSearchString),
).join(' AND ');
if (stringQuery.length > 0) {
const repo = this.manager.getCustomRepository(CashTransactionIndexRepository);
const cashTransactionIdQb = repo
.createQueryBuilder('cashTransactionIdx')
.select('rowId')
.andWhere(`cash_transaction_idx MATCH '{detail} :${stringQuery}'`);
qb = qb.andWhere(`${alias}.id IN ( ${cashTransactionIdQb.getQuery()} )`);
}
}
qb = QueryBuilderUtil.addDateFilter(
qb,
alias,
'transactionDate',
parameters.transactionDateFrom,
parameters.transactionDateTo,
);
if (parameters.transactionTypeList && parameters.transactionTypeList.length > 0) {
const formatedList = parameters.transactionTypeList.map((s) => `'${s}'`).join(', ');
qb = qb.andWhere(`${alias}.type IN ( ${formatedList} )`);
}
return qb;
}