©️
Cross api
En-US
En-US
  • Introduction
  • Compatibility
  • Extensions
  • Usage
    • Tools
      • Config
      • ListProvider
      • Language
      • Help
    • Structure
      • MakeApi
      • MakeModule
      • MakeProvider
      • Revert
  • Structure
    • Root
    • Src
    • @Types
    • Assets
    • Config
    • Dtos
    • Jobs
    • Keys
    • Middlewares
    • Modules
    • Routes
    • Shared
    • Utils
  • Services
    • Transactions
    • Exists
    • FindBy
    • FindIn
    • FindLike
    • FindAll
    • Create
    • CreateMany
    • Update
    • UpdateMany
    • Delete
    • DeleteMany
    • SoftDelete
    • SoftDeleteMany
  • Mappers
    • CloneAttribute
    • UpdateAttribute
    • PatchAttribute
    • UpdateString
    • PatchString
    • InsertAttribute
  • Providers
    • Cache
    • Crypto
    • Hash
    • Lead
    • MailTemplate
    • Mail
    • Queue
    • Notification
    • Storage
Powered by GitBook
On this page

Was this helpful?

  1. Services

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

PreviousExistsNextFindIn

Was this helpful?