Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 2 months ago
JSON representation
automagically generate all ObjectionJS models from Mysql
- Host: GitHub
- URL: https://github.com/joneldiablo/objection-model-generator
- Owner: joneldiablo
- Created: 2019-06-28T23:28:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-09T16:14:21.000Z (9 months ago)
- Last Synced: 2024-04-14T06:11:53.352Z (9 months ago)
- Topics: automagically, automation, model, models, mysql, objection, objectionjs
- Language: JavaScript
- Size: 701 KB
- Stars: 12
- Watchers: 4
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
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();
```