Skip to content
ArteMerlow edited this page May 28, 2025 · 3 revisions

ModularORM Documentation

Installation

First, install the library by running the following command:

$ npm install modular-orm

Then check the list of libraries

$ npm list

It should contain the following libraries: modular-orm, reflect-metadata, mysql2, cli-table3

Now create tsconfig.json (if it is not already created) and add the following values to it:

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  }
}

Time to run the library! In the main file of your application, on startup, call the ModularORM#start method

// some.main.ts
(async () => {
   // ...
    await ModularORM.getInstance().start({
        host: 'host',
        user: 'user name',
        password: 'mysql password',
        database: 'database (schema) name',
        port: 3306, // port
        // ...
    })
})()

After that, the library will work! You can also customize it for yourself. Here is a list of all available parameters that you can specify in ModularORM#start

logs: boolean

Whether to enable logging from the library.

entities: boolean

List of entities to be registered in the ORM.

validationErrors: boolean

Outputs a log to the console about invalid validation, removing invalid DTOs from the results array

maxMemoryUsageMB: number

Maximum memory allowed for the cache in MB.

If not provided, the default value will be used.

cacheSizeEstimationType: 'memoryUsage' | 'approximate'

The type of cache size estimation to use.

  • memoryUsage: Uses Node.js process memory usage for accurate cache size estimation.
  • approximate: Uses approximate estimation based on JSON.stringify size of cached items.

Default is approximate.

useCache: boolean

Will ORM use cache?

migrations: 'auto' | 'file'

Type of migrations

Either migrations will be automatically applied on startup, or written to a file first

rollbackTransactionsErrors: boolean

Should transactions be rolled back automatically in case of exceptions?

connectionType: 'connection' | 'pool'

Type of connection. Default - pool

returnsNullWhenErrors: boolean

When errors occur, methods will return default values.

checkTablesExists: boolean

Before creating tables, it will check if they exist in the database. If false is specified, CREATE TABLE IF NOT EXISTS will be used.

Clone this wiki locally