typeorm / typeorm

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
http://typeorm.io
MIT License
33.46k stars 6.21k forks source link

typeorm query spesific selecion #10853

Open lakmal05 opened 3 weeks ago

lakmal05 commented 3 weeks ago

Issue description

Issue

Expected Behavior

there is no any mention about the spesific selection

Actual Behavior

there is no any mention about the spesific selection

Steps to reproduce

there is no any mention about the spesific selection

My Environment

Dependency Version
Operating System
Node.js version x.y.zzz
Typescript version x.y.zzz
TypeORM version x.y.zzz

Additional Context

No response

Relevant Database Driver(s)

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

iJhefe commented 3 weeks ago

if you are using Repository, you can pass the param "select" in find/findOne, for example:

// you can use with find, findOne, findOneOrFail
repository.find({
  select: {
    id: true,
    role: {
      id: true,
      name: true,
    }
  },
  relations: {
    role: true,
  },
  where: {
    id: In([1, 2, 3]),
  }
});

and with QueryBuilder

manager.createQueryBuilder(User, 'user')
  .select('user.id')
  .addSelect('role.id')
  .addSelect('role.name')
  .innerJoin('user.role', 'role')
  .where('user.id IN (:...ids)', { ids: [1, 2, 3] })
  .getMany();

see https://typeorm.io/find-options, https://typeorm.io/select-query-builder, https://typeorm.io/select-query-builder#partial-selection