-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (60 loc) · 1.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const Sequelize = require('sequelize');
const sequelize = new Sequelize('casepass9001_v3.1.01', 'sa', 'wel@123', {
dialect: "mssql",
host: "192.168.1.191",
});
// checking is your databse is connected properly
sequelize.authenticate().then((data)=>{
console.log("Database Connected Sucessfully");
}).catch((error)=>{
console.log(error);
});
// creating a model
const User = sequelize.define('user', {
//here we given our table name as {user} but by default the sequelize takes it as plural as {users}
userId:{
type: Sequelize.DataTypes.INTEGER,
autoIncrement: true, //this needs to be first after that use primarykey
primaryKey: true
},
username:{
type: Sequelize.DataTypes.STRING,
allowNull: false
},
password:{
type: Sequelize.DataTypes.STRING
},
age:{
type: Sequelize.DataTypes.INTEGER,
defaultValue: 21
},
mobileNumber:{
type: Sequelize.DataTypes.INTEGER
},
city:{
type: Sequelize.DataTypes.STRING,
defaultValue: "Hyderabad"
},
employee:{
type: Sequelize.DataTypes.INTEGER,
defaultValue: 0
}
}, {
timestamps: false
});
// to insert a table into the database we are going to use sync() => this method runs by checking if table exists it will not create
User.sync().then(()=>{
//working with updated table
const data_ = User.create({
username: "lucky-dev07",
password: "@12345dev",
mobileNumber: 923450,
city: "Bangalore",
employee: 1
});
return data_;
}).then((data)=>{
console.log(data.toJSON());
}).catch((error)=>{
console.log("error");
});