Generate ObjectionJS models from database tables
npm install db2objectionGenerate ObjectionJS (or plain object) models from database tables.
_(Note: This is an ESM package from v0.1.0)_
Install cli globally with npm or your preferred package manager.
``shell`
$ npm install -g db2objection
db2objection currently supports the following databases:
- MySQL
- PostgreSQL
- SQLite
Create the db2objection config js file. This should be the first step to using db2objection in your project. Thedb2objection
config file is where you would configure the database connection parameters that will use to connect to
your database.
`shell`
Options:
--reset-config Reset the config file if it already exists.
Generate ObjectionJS model classes.
`shell`
Options:
-c | --case
--pojo Specify whether plain Typescript model classes will be generated, and not classes extending Objection.js Model class.
--db, --database
--dir
--scope
This returns "ok" if db2objection is able to connect to the database successfully.
The db2objection config file is a js module with the following contents:
`javascript
require('dotenv').config({
path: '.env'
});
module.exports = {
/**
* Knex configurations.
*/
knex: {
client: 'mysql2',
connection: {
database: process.env.DB_NAME,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
}
},
modelsOutputDir: '__db2obj/generated/', // Relative path where the objection models would be saved. If path does not exist, the default path will be used.
ignoreTables: [], // Tables to be ignored. e.g. migration tables and other tables used by frameworks.
case: 'camel' // 'camel' | 'snake' | 'ignore'
};
``