Gathering detailed insights and metrics for sequelize-auto-models
Gathering detailed insights and metrics for sequelize-auto-models
Gathering detailed insights and metrics for sequelize-auto-models
Gathering detailed insights and metrics for sequelize-auto-models
sequelize-auto
Automatically generate bare sequelize models from your database.
egg-sequelize-auto
Automatically generate bare sequelize models from your database, adjustment for egg
egg-sequelize-models-auto
Automatically generate bare sequelize models from your database, adjustment for egg
egg-mysql-sequelize-auto
Automatically generate mysql sequelize models for Egg.js framework from your database.
Automatically generate models for SequelizeJS via the command line.
npm install sequelize-auto-models
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
3 Commits
1 Watchers
1 Branches
2 Contributors
Updated on Jun 13, 2021
Latest Version
0.2.14
Package Id
sequelize-auto-models@0.2.14
Unpacked Size
76.64 kB
Size
19.04 kB
File Count
23
NPM Version
6.14.6
Node Version
10.22.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Automatically generate models for SequelizeJS via the command line.
npm install -g sequelize-auto-models
You will need to install the correct dialect binding globally before using sequelize-auto-models.
Example for MySQL/MariaDB
npm install -g mysql
Example for Postgres
npm install -g pg pg-hstore
Example for Sqlite3
npm install -g sqlite
Example for MSSQL
npm install -g mssql
[node] sequelize-auto-models -h <host> -d <database> -u <user> -x [password] -p [port] --dialect [dialect] -c [/path/to/config] -o [/path/to/models] -t [tableName] -C
Options:
-h, --host IP/Hostname for the database. [required]
-d, --database Database name. [required]
-u, --user Username for database.
-x, --pass Password for database.
-p, --port Port number for database.
-c, --config JSON file for Sequelize's constructor "options" flag object as defined here: https://sequelize.readthedocs.org/en/latest/api/sequelize/
-o, --output What directory to place the models.
-e, --dialect The dialect/engine that you're using: postgres, mysql, sqlite
-a, --additional Path to a json file containing model definitions (for all tables) which are to be defined within a model's configuration parameter. For more info: https://sequelize.readthedocs.org/en/latest/docs/models-definition/#configuration
-t, --tables Comma-separated names of tables to import
-T, --skip-tables Comma-separated names of tables to skip
-C, --camel Use camel case to name models and fields
-n, --no-write Prevent writing the models to disk.
-s, --schema Database schema from which to retrieve tables
-z, --typescript Output models as typescript with a definitions file.
sequelize-auto-models -o "./models" -d sequelize_auto_test -h localhost -u my_username -p 5432 -x my_password -e postgres
Produces a file/files such as ./models/Users.js which looks like:
const sequelize = require("../config/env.js");
const Sequelize = require("sequelize");
const Model = Sequelize.Model;
class Users extends Model {
Users.init({
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
username: {
type: DataTypes.STRING,
allowNull: true
},
touchedAt: {
type: DataTypes.DATE,
allowNull: true
},
aNumber: {
type: DataTypes.INTEGER(11),
allowNull: true
},
bNumber: {
type: DataTypes.INTEGER(11),
allowNull: true
},
validateTest: {
type: DataTypes.INTEGER(11),
allowNull: true
},
validateCustom: {
type: DataTypes.STRING,
allowNull: false
},
dateAllowNullTrue: {
type: DataTypes.DATE,
allowNull: true
},
defaultValueBoolean: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: '1'
},
createdAt: {
type: DataTypes.DATE,
allowNull: false
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false
}
}, {
sequelize,
modelName: 'Users',
freezeTableName: true,
timestamps: false
});
};
module.exports = Users;
Note: You must config 'sequelize' in ../config/env.js like:
const Sequelize = require("sequelize");
const sequelize = new Sequelize("database", "username", "password", {
host: "localhost",
dialect: "mysql"
});
module.exports = sequelize;
Which makes it easy for you to simply Sequelize.import it.
For the -c, --config
option the following JSON/configuration parameters are defined by Sequelize's options
flag within the constructor. For more info:
https://sequelize.readthedocs.org/en/latest/api/sequelize/
1var SequelizeAuto = require('sequelize-auto-models') 2var auto = new SequelizeAuto('database', 'user', 'pass'); 3 4auto.run(function (err) { 5 if (err) throw err; 6 7 console.log(auto.tables); // table list 8 console.log(auto.foreignKeys); // foreign key list 9}); 10 11With options: 12var auto = new SequelizeAuto('database', 'user', 'pass', { 13 host: 'localhost', 14 dialect: 'mysql'|'mariadb'|'sqlite'|'postgres'|'mssql', 15 directory: false, // prevents the program from writing to disk 16 port: 'port', 17 additional: { 18 timestamps: false 19 //... 20 }, 21 tables: ['table1', 'table2', 'table3'] 22 //... 23})
Add -z to cli options or typescript: true
to programmatic options. Model usage in a ts file:
1// All models, can put in or extend to a db object at server init 2import * as dbTables from './models/db.tables'; 3const tables = dbTables.getModels(sequelize); //:dbTables.ITable 4tables.Device.findAll 5// Single models 6import * as dbDef from './models/db.d'; 7const devices:dbDef.DeviceModel = sequelize.import('./models/Device'); 8devices.findAll
You must setup a database called sequelize_auto_test
first, edit the test/config.js
file accordingly, and then enter in any of the following:
# for all
npm run test
# mysql only
npm run test-mysql
# postgres only
npm run test-postgres
# postgres native only
npm run test-postgres-native
# sqlite only
npm run test-sqlite
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/1 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More