-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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
Whether to enable logging from the library.
List of entities to be registered in the ORM.
Outputs a log to the console about invalid validation, removing invalid DTOs from the results array
Maximum memory allowed for the cache in MB.
If not provided, the default value will be used.
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.
Will ORM use cache?
Type of migrations
Either migrations will be automatically applied on startup, or written to a file first
Should transactions be rolled back automatically in case of exceptions?
Type of connection. Default - pool
When errors occur, methods will return default values.
Before creating tables, it will check if they exist in the database. If false is specified, CREATE TABLE IF NOT EXISTS will be used.