mysql - NestJS & TypeORM & MySQL - 模块“typeorm”没有导出成员“ArrayContains”

我将 NestJS 与 MySQL 数据库和 TypeORM 一起使用。我想过滤数组包含一些数字的查询结果。我对 ArrayContains 运算符有疑问。 https://github.com/typeorm/typeorm/blob/master/CHANGELOG.md 版本中添加的 TypeORM 包不导出运算符。结果我得到一个错误

模块“typeorm”没有导出成员“ArrayContains”。

有我的 package.json 依赖项

"scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main"
  },
  "dependencies": {
    "@nestjs/axios": "0.0.7",
    "@nestjs/common": "8.4.3",
    "@nestjs/core": "8.4.3",
    "@nestjs/jwt": "8.0.0",
    "@nestjs/passport": "8.2.1",
    "@nestjs/platform-express": "8.4.3",
    "@nestjs/schedule": "1.0.2",
    "@nestjs/typeorm": "8.0.3",
    "bcrypt": "5.0.1",
    "class-transformer": "0.5.1",
    "class-validator": "0.13.2",
    "date-fns": "2.28.0",
    "mysql2": "2.3.3",
    "passport": "0.5.2",
    "passport-jwt": "4.0.0",
    "reflect-metadata": "0.1.13",
    "rimraf": "3.0.2",
    "rxjs": "7.5.5",
    "typeorm": "0.3.4"
  },
  "devDependencies": {
    "@nestjs/cli": "8.2.4",
    "@nestjs/schematics": "8.0.9",
    "@types/bcrypt": "5.0.0",
    "@types/cron": "1.7.3",
    "@types/express": "4.17.13",
    "@types/node": "16.11.26",
    "@types/passport-jwt": "3.0.6",
    "source-map-support": "0.5.21",
    "ts-loader": "9.2.8",
    "ts-node": "10.7.0",
    "tsconfig-paths": "3.14.1",
    "typescript": "4.6.3"
  }

我如何尝试使用 ArrayContains 运算符

import { DrawEntity } from '@entities/draw.entity';
import { SortOrder } from '@models/sort-order.enum';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { ArrayContains, Repository } from 'typeorm';

@Injectable()
export class ExampleService {

  constructor(
    @InjectRepository(DrawEntity) private readonly drawEntityRepository: Repository<DrawEntity>,
  ) {
  }

  public findAndCountAl(params: { take: number, skip: number, sortField: string, sortOrder: SortOrder }): Promise<[ DrawEntity[], number ]> {
    return this.drawEntityRepository.findAndCount({
      where: {
        result: ArrayContains([ 1, 2, 5, 10 ]),
      },
      order: {
        [params.sortField]: params.sortOrder === SortOrder.DESC ? 'DESC' : 'ASC',
      },
      take: params.take,
      skip: params.skip,
      cache: 60000,
    });
  }
}

实体

import { Column, Entity, PrimaryColumn } from 'typeorm';

@Entity({
  name: 'draw',
  orderBy: {
    id: 'ASC',
    date: 'ASC',
  },
})
export class DrawEntity {

  @PrimaryColumn({ type: 'uuid', nullable: false, generated: 'uuid' })
  public id: string;

  @Column({ type: 'datetime', nullable: false })
  public date: Date;

  @Column({ type: 'json', nullable: false })
  public result: number[];

  @Column({ type: 'json', nullable: false })
  public specialResult: number[];
}

任何想法我做错了什么?

回答1

它现在应该工作了。我们正在使用 typeorm 0.3.0 和 nestjs。 https://github.com/nestjs/typeorm/blob/master/package.json#L59

相似文章