Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joneldiablo/objection-model-generator

automagically generate all ObjectionJS models from Mysql
https://github.com/joneldiablo/objection-model-generator

automagically automation model models mysql objection objectionjs

Last synced: about 2 months ago
JSON representation

automagically generate all ObjectionJS models from Mysql

Awesome Lists containing this project

README

        

# OMG

Objection Model Generator is a tool to _automagically_ generate all ObjectionJS models from Mysql data base, using the information_schema table to let us know tables, columns and BelongsToOneRelations.

```js

require('dotenv').config();
const fs = require('fs');
const Omg = require('objection-model-generator');

// OPTIONAL: add pluralize customization
const pluralize = require('pluralize');
pluralize.addSingularRule('mouse', 'mice');
pluralize.addSingularRule('Mouse', 'Mice');
//----

const main = async () => {
let omg = new Omg({
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASS
}, process.env.DB_NAME, '../knex'); // relative path to the knex instance, the generated file goings to require that file
let ms = await omg.createModels();
let path = 'src/api/models/generated.js'; // path to where goings to be created the output
fs.writeFileSync(path, ms);
console.log('-> file writed:', path);
process.exit();
}

main();
```