-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_rows.js
More file actions
24 lines (19 loc) · 658 Bytes
/
Copy pathcount_rows.js
File metadata and controls
24 lines (19 loc) · 658 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
import { Sequelize, DataTypes } from "sequelize";
const sequelize = new Sequelize("mysql://root:secret@localhost:3307/practice");
const Todo = sequelize.define("Todo", {
title: { type: DataTypes.STRING, allowNull: false },
completed: { type: DataTypes.BOOLEAN, defaultValue: false }
});
async function run() {
try {
await sequelize.sync();
// Count all rows matching specific criteria
const completedCount = await Todo.count({ where: { completed: true } });
console.log(`Total completed tasks: ${completedCount}`);
} catch (error) {
console.error("Error:", error);
} finally {
await sequelize.close();
}
}
run();