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
  • @Schema
  • For Example
  1. Schema

Decorator's

@Schema

The @Schema program processes the schema and makes it ready for saving to the table, it is mandatory* to use it when creating a model.

@Timestamps

The @Timestamps decorator automatically adds createdAt and updatedAt columns to the model. These columns store the creation and last update timestamps, with the updatedAt column being automatically updated on every change. Using @Timestamps is optional and can be included as needed to simplify timestamp management in your models.

@Paranoid

The @Paranoid decorator enables soft deletion for the model by adding a deletedAt column. Instead of permanently removing a record, it sets a timestamp in the deletedAt column when the record is deleted. This allows the data to be retained and queried if needed. Using @Paranoid is optional and can be implemented when soft delete functionality is required.

@Force

The @Force option in sync is used to drop and recreate the table in the database. When @Force is set to true, it completely removes the existing table, including all its data, and creates a new table based on the current model definition. This is useful for development purposes to quickly apply model changes, but it should be used with caution in production environments as it results in data loss.

@Debug

The @Debug decorator logs all operations performed on the schema where it is used. It provides detailed information about actions such as creation, updates, deletions, and queries, making it easier to debug and monitor database interactions. Using @Debug is optional and can be enabled when you need better insight into schema-level operations.

@Provider(providerName:string)

The @Provider decorator specifies which model the schema will be associated with, particularly in scenarios involving multiple connections or databases. It should be placed above the class structure and below other schema decorators. By default, the @Provider decorator uses 'nexorm' as the default connection. This makes it easier to manage and organize schemas across various database setups when working with multiple data sources.

For Example

import { 
  Schema, 
  Timestamps, 
  Paranoid,
  Force,
  Debug,
  Provider
} from 'nexorm/decorators';


@Schema
@Timestamps
@Paranoid
@Force
@Debug
@Provider('nexorm')
class anySchemaInterface {
/*
......
.....
*/
};
PreviousWhat is Schema?NextColumn

Last updated 3 months ago