Getting Started
To use minorm you need to create instance of a manager. To do this we recommend to create a folder models
and put index.js
file to it with content like:
import { createManager } from '@minorm/core'
import { createAdapter } from '@minorm/adapter-mysql'
import config from '../config'
export const manager = createManager(createAdapter(config.db))
Config for a adapter should follow this format:
export default {
// Your other configs
db: {
host: process.env.MYSQL_HOST || 'localhost',
user: process.env.MYSQL_USER || 'user',
password: process.env.hasOwnProperty('MYSQL_PASS')
? process.env.MYSQL_PASS
: 'password',
database: process.env.MYSQL_DB || 'app_db',
},
}
If you want to read about other connection configuration parameters please read mysqljs/mysql doc.
Please note that minorm by default use connection pool, so there's additional config here
Init connection
In your startup screen you need to add code to bootstrap manager. This can looks like:
import { manager } from './models'
async function boot() {
manager.connect() // this method making instance of connection pool and put configuration to it
await manager.ready() // this method preparing manager for real use by loading metadata
// Other boot code
}