code example for CSV Importer with Node
Co-authored-by: Arpendu Kumar Garai <Arpendu.KumarGarai@microfocus.com>
This commit is contained in:
committed by
GitHub
parent
3930e1cb03
commit
cd69fa5842
68
nodejs/node-csv-importer/server/models/employee.model.js
Normal file
68
nodejs/node-csv-importer/server/models/employee.model.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import Sequelize from 'sequelize';
|
||||
import { sequelize } from '../database/index.js';
|
||||
|
||||
const Employee = sequelize.define("employee", {
|
||||
id: {
|
||||
type: Sequelize.STRING,
|
||||
primaryKey: true
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
email: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
username: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
dob: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
company: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
address: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
location: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
salary: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
about: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
role: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
managedBy: {
|
||||
type: Sequelize.STRING,
|
||||
references: {
|
||||
model: 'employees',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
createdAt: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
updatedAt: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
avatar: {
|
||||
type: Sequelize.STRING
|
||||
}
|
||||
});
|
||||
|
||||
Employee.hasMany(Employee, {
|
||||
as: 'children',
|
||||
foreignKey: 'managedBy',
|
||||
sourceKey: 'id',
|
||||
useJunctionTable: false
|
||||
});
|
||||
Employee.belongsTo(Employee, {
|
||||
foreignKey: "managedBy",
|
||||
targetKey: "id",
|
||||
});
|
||||
|
||||
export default Employee;
|
||||
Reference in New Issue
Block a user