storage process serialization of typeorm "And" find operator
This commit is contained in:
parent
44870aa667
commit
409b0beb95
1 changed files with 7 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { FindOperator, LessThan, MoreThan, LessThanOrEqual, MoreThanOrEqual, Equal, Like, ILike, Between, In, Any, IsNull, Not, FindOptionsWhere } from 'typeorm';
|
import { FindOperator, LessThan, MoreThan, LessThanOrEqual, MoreThanOrEqual, Equal, Like, ILike, Between, In, Any, IsNull, Not, FindOptionsWhere, And } from 'typeorm';
|
||||||
export type WhereCondition<T> = FindOptionsWhere<T> | FindOptionsWhere<T>[]
|
export type WhereCondition<T> = FindOptionsWhere<T> | FindOptionsWhere<T>[]
|
||||||
|
|
||||||
type SerializedFindOperator = {
|
type SerializedFindOperator = {
|
||||||
|
|
@ -11,7 +11,7 @@ export function serializeFindOperator(operator: FindOperator<any>): SerializedFi
|
||||||
return {
|
return {
|
||||||
_type: 'FindOperator',
|
_type: 'FindOperator',
|
||||||
type: operator['type'],
|
type: operator['type'],
|
||||||
value: operator['value'],
|
value: Array.isArray(operator['value']) ? operator["value"].map(serializeFindOperator) : operator["value"],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,6 +41,11 @@ export function deserializeFindOperator(serialized: SerializedFindOperator): Fin
|
||||||
return IsNull();
|
return IsNull();
|
||||||
case 'not':
|
case 'not':
|
||||||
return Not(deserializeFindOperator(serialized.value));
|
return Not(deserializeFindOperator(serialized.value));
|
||||||
|
case 'and':
|
||||||
|
if (serialized.value.length !== 2) {
|
||||||
|
throw new Error("Typeorm and operator with more than 2 arguments not supported");
|
||||||
|
}
|
||||||
|
return And(deserializeFindOperator(serialized.value[0]), deserializeFindOperator(serialized.value[1]));
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown FindOperator type: ${serialized.type}`);
|
throw new Error(`Unknown FindOperator type: ${serialized.type}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue