UNPKG

sequelize-automate

Version:

Automatically generate bare sequelize models from your database.

23 lines (22 loc) 4.43 kB
[ { "file": "user.ts", "code": "import { Sequelize, DataTypes } from 'sequelize';\nexport default function (sequelize: 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.ts", "code": "import { Sequelize, DataTypes } from 'sequelize';\nexport default function (sequelize: 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" }, { "file": "user.d.ts", "code": "import { Model, BuildOptions } from 'sequelize';\nexport interface IUserAttributes {\n id: number,\n name: string,\n email: string,\n created_at: Date,\n updated_at: Date,\n}\nexport interface IUserModel extends IUserAttributes, Model {}\nexport type IUserModelStatic = typeof Model & {\n new (values?: object, options?: BuildOptions): IUserModel;\n};", "fileType": "definition" }, { "file": "user_post.d.ts", "code": "import { Model, BuildOptions } from 'sequelize';\nexport interface IUserPostAttributes {\n id: number,\n user_id: number,\n title: string,\n content?: string,\n created_at: Date,\n updated_at: Date,\n}\nexport interface IUserPostModel extends IUserPostAttributes, Model {}\nexport type IUserPostModelStatic = typeof Model & {\n new (values?: object, options?: BuildOptions): IUserPostModel;\n};", "fileType": "definition" } ]