-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (29 loc) · 989 Bytes
/
index.js
File metadata and controls
37 lines (29 loc) · 989 Bytes
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
const { Sequelize, DataTypes } = require('sequelize');
const sequelize = new Sequelize('mysql://root:190582@localhost:32769/customer')
init = async() => {
try {
await sequelize.authenticate();
const Customer = sequelize.define('Customer', {
Id: {
type: DataTypes.INTEGER,
primaryKey: true,
field: "CustomerId"
},
Name: {
type: DataTypes.STRING
}
});
await Customer.sync();
//await Customer.create({Id: 1, name: "Donald"});
const allCustomers = await Customer.findAll();
console.log("found " + allCustomers.length + " customer");
const [result, metadata] = await sequelize.query("SELECT COUNT(*) Antall FROM Customers");
console.log(result);
//await sequelize.sync();
await sequelize.close();
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
}
init();