UNPKG

sequelize-automate

Version:

Automatically generate bare sequelize models from your database.

13 lines (12 loc) 3.47 kB
[ { "file": "user.js", "code": "const {\n DataTypes\n} = require('sequelize');\n\nmodule.exports = sequelize => {\n const attributes = {\n id: {\n type: DataTypes.INTEGER(11).UNSIGNED,\n allowNull: false,\n defaultValue: null,\n primaryKey: true,\n autoIncrement: true,\n comment: \"primary ket\",\n field: \"id\"\n },\n name: {\n type: DataTypes.STRING(100),\n allowNull: false,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"user name\",\n field: \"name\",\n unique: \"uk_name\"\n },\n email: {\n type: DataTypes.STRING(255),\n allowNull: false,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"user email\",\n field: \"email\"\n },\n created_at: {\n type: DataTypes.DATE,\n allowNull: false,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"created datetime\",\n field: \"created_at\"\n },\n updated_at: {\n type: DataTypes.DATE,\n allowNull: false,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"updated datetime\",\n field: \"updated_at\"\n }\n };\n const options = {\n tableName: \"user\",\n comment: \"\",\n indexes: []\n };\n const UserModel = sequelize.define(\"user_model\", attributes, options);\n return UserModel;\n};", "fileType": "model" }, { "file": "user_post.js", "code": "const {\n DataTypes\n} = require('sequelize');\n\nmodule.exports = sequelize => {\n const attributes = {\n id: {\n type: DataTypes.INTEGER(11).UNSIGNED,\n allowNull: false,\n defaultValue: null,\n primaryKey: true,\n autoIncrement: true,\n comment: \"primary key\",\n field: \"id\"\n },\n user_id: {\n type: DataTypes.INTEGER(11).UNSIGNED,\n allowNull: false,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"user id\",\n field: \"user_id\",\n references: {\n key: \"id\",\n model: \"user_model\"\n }\n },\n title: {\n type: DataTypes.STRING(255),\n allowNull: false,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"post title\",\n field: \"title\"\n },\n content: {\n type: DataTypes.TEXT,\n allowNull: true,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"post content\",\n field: \"content\"\n },\n created_at: {\n type: DataTypes.DATE,\n allowNull: false,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"created datetime\",\n field: \"created_at\"\n },\n updated_at: {\n type: DataTypes.DATE,\n allowNull: false,\n defaultValue: null,\n primaryKey: false,\n autoIncrement: false,\n comment: \"updated datetime\",\n field: \"updated_at\"\n }\n };\n const options = {\n tableName: \"user_post\",\n comment: \"\",\n indexes: [{\n name: \"fk_user_id\",\n unique: false,\n type: \"BTREE\",\n fields: [\"user_id\"]\n }]\n };\n const UserPostModel = sequelize.define(\"user_post_model\", attributes, options);\n return UserPostModel;\n};", "fileType": "model" } ]