©️
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. Mappers

CloneAttribute

Receives as parameter a key array and a value, returns an array of objects with the same value, is useful for queries find WHERE + OR.

No mapper:

const param = "example";

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

// Find where id = "example" OR name = "example" OR description = "example"

Using mapper:

import { cloneAttribute } from "@utils/mappers";

const param = "example";

const example = await this.examplesRepository.findBy(
  {
    where: cloneAttribute<Example>(param, ['id', 'name', 'description']),
  },
  trx,
);

// Find where id = "example" OR name = "example" OR description = "example"

PreviousMappersNextUpdateAttribute

Last updated 5 months ago

Was this helpful?