nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.09k stars 539 forks source link

andWhere alias length too long for Oracle #677

Open denodaeus opened 3 years ago

denodaeus commented 3 years ago

Oracle has an alias length max of 30 Chars, but this code generates aliases that are longer than that.

For example:

IPTION_1" AS "9fdc394f21b9f667947aa911091df7", "BTBT"."BENCHMARK_ISIN_1" AS "65e3e4651bda2cfb364a626ab5fefa" FROM "BTBT_TRADES" "BTBT" WHERE ("BTBT_TRADES"."TRADE_SIDE" = :andWheretradeSide18833018231956) FETCH NEXT 10 ROWS ONLY -- PARAMETERS: ["Buy"]

Typeorm in general should be handling this condition in the query builder, but it's coverage is spotty at best: https://github.com/typeorm/typeorm/issues/4425

It would be nice to either have this convention configurable (via a max length or something), or have it cap out at 30 chars (which would work agnostically with all db technologies typeorm supports)

Here's where it happens in the code: https://github.com/nestjsx/crud/blob/bbea082a3f0fc7c1be42a79164f41b8449ad2251/packages/crud-typeorm/src/typeorm-crud.service.ts#L769

  protected builderSetWhere(
    builder: SelectQueryBuilder<T>,
    condition: SConditionKey,
    field: string,
    value: any,
    operator: ComparisonOperator = '$eq',
  ) {
    const time = process.hrtime();
    **const index = `${field}${time[0]}${time[1]}`;**
    const args = [
      { field, operator: isNull(value) ? '$isnull' : operator, value },
      index,
      builder,
    ];
    const fn = condition === '$and' ? this.setAndWhere : this.setOrWhere;
    fn.apply(this, args);
  }