FindBy

Receives any parameter as an argument as long as it is a { key: value } or array of { key: value }.

For simple queries:

const example = await this.examplesRepository.findBy(
  { where: { id: 123 } },
  trx,
);

// Find one where id = 123

For queries composed of more than one condition:

const example = await this.examplesRepository.findBy(
  { where: { id: 123, name: "example" } },
  trx,
);

// Find one where id = 123 AND name = "example"

For queries composed of one condition or another:

const example = await this.examplesRepository.findBy(
  {
    where: [
      { id: 123 },
      { name: "example" },
    ],
  },
  trx,
);

/** Find one where id = 123 OR name = "example"
 * You also can use a mapper to make your work easier and cleaner
 * There will be an introduction about them right under the standard queries introduction
 */

In addition, it can be passed as array of string keys of relations that you want to load and the fields you want to select:

const select = { name: true }

const example = await this.examplesRepository.findBy(
  {
    where: { id: 123 },
    relations: ["relation-1", "relation-2"], // or { "relation-1": true, "relation-2": true }
    select,
  },
  trx,
);

// Find one where id = 123 and load related relation-1 and relation-2 entities