Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Query<M, T>

Collects conditions to query

Type parameters

Hierarchy

  • Query

Implements

Index

Constructors

Properties

_adapter: AdapterBase
_conditions: Record<string, any>[]
_connection: Connection<AdapterBase>
_current_if: boolean
_find_single_id: boolean = false
_id: any
_ifs: boolean[]
_includes: { column: string; select?: string }[]
_model: typeof BaseModel
_name: string
_options: QueryOptions
_preserve_order_ids?: any[]
_used: boolean = false

Methods

  • _addCondition(condition: any): void
  • _doArchiveAndIntegrity(options: any): Promise<void>
  • _doIntegrityActions(integrities: any, ids: any): Promise<void>
  • _exec(find_options: AdapterFindOptions, options?: { skip_log?: boolean }): Promise<any>
  • Parameters

    • find_options: AdapterFindOptions
    • Optional options: { skip_log?: boolean }
      • Optional skip_log?: boolean

    Returns Promise<any>

  • _execAndInclude(options?: { skip_log?: boolean }): Promise<any>
  • _getAdapterFindOptions(): AdapterFindOptions
  • _setUsed(): void
  • _validateAndBuildSaveData(errors: any, data: any, updates: any, path: any, object: any): void
  • cache(options: undefined | { key: string; refresh?: boolean; ttl: number }): Query<M, T>
  • Cache result.

    If cache of key exists, actual query does not performed. If cache does not exist, query result will be saved in cache.

    Redis is used to cache.

    Parameters

    • options: undefined | { key: string; refresh?: boolean; ttl: number }

    Returns Query<M, T>

  • count(): Promise<number>
  • delete(options?: any): Promise<number>
  • exec(options?: { skip_log?: boolean }): Promise<any>
  • Executes the query

    see

    AdapterBase::findById

    see

    AdapterBase::find

    Parameters

    • Optional options: { skip_log?: boolean }
      • Optional skip_log?: boolean

    Returns Promise<any>

  • explain(): Promise<any>
  • group<U>(group_by: null | string | string[], fields?: object): QuerySingle<M, U>
  • group<U>(group_by: null | string | string[], fields?: object): QueryArray<M, U>
  • if(condition: boolean): Query<M, T>
  • include(column: string, select?: string): Query<M, T>
  • index_hint(hint: string): Query<M, T>
  • join(model_class: typeof BaseModel, options?: { alias?: string; base_column?: string; join_column?: string }): Query<M, T>
  • (inner) join

    Parameters

    • model_class: typeof BaseModel
    • Optional options: { alias?: string; base_column?: string; join_column?: string }
      • Optional alias?: string
      • Optional base_column?: string
      • Optional join_column?: string

    Returns Query<M, T>

  • lean(lean?: boolean): Query<M, T>
  • left_outer_join(model_class: typeof BaseModel, options?: { alias?: string; base_column?: string; join_column?: string }): Query<M, T>
  • limit(limit: number): Query<M, T>
  • near(target: object): Query<M, T>
  • Returns only one record (or null if does not exists).

    This is different from limit(1). limit(1) returns array of length 1 while this returns an instance.

    Returns Query<M, T>

  • order(orders?: string): Query<M, T>
  • select<K>(columns?: string | string[]): QuerySingle<M, Pick<M, K>>
  • select<K>(columns?: string | string[]): QueryArray<M, Pick<M, K>>
  • skip(skip: number): Query<M, T>
  • stream(): Readable
  • then<TResult1, TResult2>(onfulfilled?: null | ((value: T) => TResult1 | PromiseLike<TResult1>) | ((value: T[]) => TResult1 | PromiseLike<TResult1>), onrejected?: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)): PromiseLike<TResult1 | TResult2>
  • Executes the query as a promise (.then == .exec().then)

    Type parameters

    • TResult1 = T

    • TResult2 = never

    Parameters

    • Optional onfulfilled: null | ((value: T) => TResult1 | PromiseLike<TResult1>) | ((value: T[]) => TResult1 | PromiseLike<TResult1>)
    • Optional onrejected: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)

    Returns PromiseLike<TResult1 | TResult2>

  • update(updates: any): Promise<number>
  • upsert(updates: any, options?: { ignore_on_update: string[] }): Promise<void>
  • Executes the query as an insert or update operation

    see

    AdapterBase::upsert

    Parameters

    • updates: any
    • Optional options: { ignore_on_update: string[] }
      • ignore_on_update: string[]

    Returns Promise<void>

  • using(node: "master" | "read"): Query<M, T>
  • where(condition?: object): Query<M, T>

Generated using TypeDoc