查找所有数据

查找数据库所有数据通过 find() 查找

  1. @Get('all')
  2. index() {
  3. return this.typeormService.findAll();
  4. }
  5. async findAll() {
  6. return await this.typeormsEntity.find();
  7. }

查找一条符合条件数据

http://localhost:5500/typeorm/one/2

  1. /**
  2. * 查找一条符合条件的数据
  3. * {id:1}
  4. */
  5. @Post('one/:id')
  6. getAllOne(@Param() param:TypeormsModule):Promise<TypeormsEntity>{
  7. return this.typeormService.findOne(param)
  8. }
  9. /**
  10. * 查找一条符合条件的数据
  11. * {id:1}
  12. */
  13. async findOne(param){
  14. return await this.typeormsEntity.findOne(param)
  15. }

查找所有符合条件数据

http://localhost:5500/typeorm/findAll
{
“age”:”q”
}

  1. /**
  2. * 获取所有符合条件的数据
  3. */
  4. @Post('findAll')
  5. getFindAll(@Body() body){
  6. return this.typeormService.getFindAll(body)
  7. }
  8. /**
  9. * 查找所有符合条件数据
  10. */
  11. async getFindAll(body){
  12. return await this.typeormsEntity.find(body)
  13. }

查找指定数据 并且 获取数据数量

http://localhost:5500/typeorm/findAndConut
{
“name”:1233
}

  1. @Post('findAndConut')
  2. getFindAndConut(@Body() body){
  3. return this.typeormService.getFindAndConut(body)
  4. }
  5. async getFindAndConut(body){
  6. return await this.typeormsEntity.findAndCount(body).then(res =>{
  7. const [data,count] = res;
  8. return{
  9. data,
  10. count
  11. }
  12. })
  13. }
  14. // 结果
  15. {
  16. "code": 2000,
  17. "message": "请求成功!",
  18. "time": "2021-03-14T06:59:06.520Z",
  19. "data": {
  20. "data": [
  21. {
  22. "id": 1,
  23. "name": "1233",
  24. "age": "q"
  25. },
  26. {
  27. "id": 5,
  28. "name": "1233",
  29. "age": "q"
  30. },
  31. {
  32. "id": 12,
  33. "name": "1233",
  34. "age": ""
  35. }
  36. ],
  37. "count": 3
  38. }
  39. }