Nexorm
  • Getting Started
  • Schema
    • What is Schema?
    • Decorator's
  • Column
    • What is Column?
    • Decorator's
  • Core
  • Method's
    • Finder Method's
      • $search
      • $searchOne
      • $searchFirst
      • $searchById
      • $searchByIds
      • $searchAndCount
      • $distinct
      • $everything
      • $count
      • $query
    • Updater Method's
      • $update
      • $updateMany
      • $upsert
      • $restore
    • Creation Method's
      • $build
      • $buildMany
    • Deletion Method's
      • $delete
      • $deleteMany
      • $softDelete
      • $softDeleteMany
      • $truncate
  • Operator's
    • Search Operator's
      • $eq
      • $ne
      • $gt
      • $gte
      • $lt
      • $lte
      • $between
      • $notBetween
      • $in
      • $notIn
      • $like
      • $notLike
      • $startsWith
      • $endsWith
      • $substring
      • $and
      • $or
      • $is
      • $not
      • $overlap
      • $contains
      • $contained
      • $any
      • $regexp
      • $notRegexp
      • $iLike
      • $notILike
      • $adjacent
    • Update Operator's
      • String Operator's
        • $append
        • $prepend
        • $replace
        • $trim
        • $substr
        • $capitalize
        • $reverse
        • $slice
        • $lowercase
        • $uppercase
        • $camelcase
        • $kebabcase
        • $snakecase
        • $titlecase
      • Number Operator's
        • $inc
        • $dec
        • $mul
        • $div
        • $min
        • $max
        • $sqrt
        • $floor
        • $random
        • $abs
        • $ceil
        • $pow
        • $toFixed
        • $toExponential
        • $toPrecision
        • $round
        • $trunc
        • $mod
      • Boolean Operator's
        • $toggle
      • Object Operator's
        • $omit
        • $merge
        • $mapKeys
        • $mapValues
        • $invert
      • Array Operator's
        • $push
        • $pop
        • $pull
        • $addToSet
        • $sliceArray
        • $concat
      • Global Operator's
        • $set
        • $unset
        • $clear
    • Rules Operator's
    • Options Operator's
  • Hook's
    • $beforeCreate
    • $afterCreate
    • $beforeFind
    • $afterFind
    • $beforeUpdate
    • $afterUpdate
    • $beforeDestroy
    • $afterDestroy
    • $beforeSave
    • $afterSave
    • $beforeBulkCreate
    • $afterBulkCreate
    • $beforeBulkUpdate
    • $afterBulkUpdate
    • $beforeBulkDestroy
    • $afterBulkDestroy
Powered by GitBook
On this page
  • UpdateMethodsOptions
  • RestoreMethodsOptions
  • CountMethodsOptions
  • SearchMethodsOptions
  • DeleteMethodsOptions
  1. Operator's

Options Operator's

UpdateMethodsOptions

This type defines options used when performing update operations.

1. $upsert:

• If set to true, it will perform an “upsert” (update if exists, insert if not).

• If not set, it will only update existing records and will fail if no record matches.

2. $multi:

• If set to true, it will allow updating multiple records that match the criteria.

• If not set, only a single record will be updated.

3. $cache:

• This option allows you to control caching behavior:

• If set to true, it enables caching.

• If set to a number, it sets the cache expiration time in seconds.

• If set to an object { $key: string, $ttl: number }, it allows you to define a specific cache key and the time-to-live (TTL) for the cache.

RestoreMethodsOptions

This type defines options for restoring records, typically after deletion or archiving.

1. $limit:

• Specifies the maximum number of records to restore.

• If not set, it will attempt to restore all matching records.

2. $logging:

• This option controls logging behavior:

• If set to true, logging will be enabled by default.

• If set to a function (sql: string, benchmark?: number) => void, it allows you to provide a custom logging function to log SQL queries with optional benchmarks for performance.

CountMethodsOptions

This type defines options for counting records in the database.

1. $logging:

• Controls logging as described above for the RestoreMethodsOptions.

2. $col:

• Specifies the column to be used for counting, allowing you to group the count by a specific field.

• If not set, it will count all records.

3. $attributes:

• Specifies the attributes (fields) to be considered when counting.

• The AttributesOption type would define the exact behavior (for instance, which columns to include or exclude).

4. $group:

• Allows you to group the results by a specific field, returning the count for each group.

• The field will be of type keyof SchemaProps (a key from the schema).

5. $distinct:

• If set to true, the count will be distinct (count only unique values for the column).

6. $paranoid:

• If set to true, only non-deleted records will be counted (if “paranoid” mode is enabled in the ORM).

SearchMethodsOptions

This type defines options for search queries, enabling filtering, sorting, and pagination.

1. $limit:

• Specifies the maximum number of records to return.

• If not set, all matching records will be returned.

2. $offset:

• Used for pagination; specifies how many records to skip before starting to return results.

• Helps in implementing “pagination” with limit.

3. $sort:

• Defines the sorting order for the query results.

• The SortOption type would define how the sorting works, such as sorting by a column in ascending or descending order.

4. $attributes:

• Specifies which attributes (columns) should be included or excluded from the result.

• Similar to $attributes in CountMethodsOptions.

5. $group:

• Used to group the results by a specific field, useful for aggregate functions (e.g., COUNT, SUM).

6. $having:

• Allows you to filter the results after they have been grouped (typically used with aggregate functions like COUNT or SUM).

7. $raw:

• If set to true, the query will return raw data (without transformations or model associations).

8. $paranoid:

• Controls whether to include only non-deleted records (works when paranoid mode is enabled).

9. $subQuery:

• If set to true, the query will be executed as a subquery, which may be useful for nested queries.

10. $logging:

• Controls logging behavior for the query, as described in RestoreMethodsOptions.

11. $useMaster:

• Specifies whether to use the master database for the query (useful in sharded or replicated database setups).

12. $lock:

• This option defines row-level locking for the query:

• If set to true, it will lock the selected rows during the query.

• If set to an object, it allows you to specify the lock level (e.g., key_share or update) and the table(s) to apply the lock to.

13. $skipLocked:

• If set to true, rows that are currently locked by other transactions will be skipped during the query.

14. $plain:

• If set to true, it will return plain results without the ORM model’s data transformation.

15. $cache:

• Controls caching behavior, similar to the $cache in UpdateMethodsOptions.

DeleteMethodsOptions

This type defines options for deleting records.

1. $limit:

• Specifies the maximum number of records to delete.

• If not set, it will attempt to delete all matching records.

2. $force:

• If set to true, the deletion will be forced, meaning it bypasses any “soft-delete” behavior and deletes the record permanently.

3. $truncate:

• If set to true, the delete operation will truncate the table, effectively deleting all records in the table.

4. $logging:

• Controls logging behavior, similar to the $logging option in RestoreMethodsOptions and SearchMethodsOptions.

PreviousRules Operator'sNextHook's

Last updated 2 months ago