I am migrating a web app from javascript to typescript. And I have noticed that the query results are a bit slower sometimes as compared to javascript. It is not consistent though.
I have two tables - User and Team. One user can have many teams. So it is hasMany and belongsTo association between them.
Team Model
import {Model, Table, Column, Default} from 'sequelize-typescript';
@Table
export class Team extends Model {
@Column name!: string;
@Default(true)
@Column isActive!: boolean;
}
User Model
import {Model, Table, Column, Default,DataType} from 'sequelize-typescript';
@Table
export class User extends Model {
@Column firstName!: string;
@Column lastName!: string;
@Column email!: string;
@Default(true)
@Column isActivated!: boolean;
@Column source!: string;
@Column(DataType.JSON)
profileData: string;
@Column(DataType.JSON)
settings: string;
@Column(DataType.JSON)
paymentDetails: string;
}
The association
Team.belongsTo(User, { foreignKey: "fk_ownerId", as: 'Owner' });
User.hasMany(Team, { foreignKey: "fk_ownerId", as: 'OwnedTeams' });
Here are my results
30k records
typescript
user ins query: 2.955s
user query: 2.134s
javascript
user ins query: 3.785s
user query: 1.947s
50k records
typescript
team ins query: 4.621s
team query: 2.601s
javascript
team ins query: 4.352s
team query: 2.340s
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"sourceMap": true,
"strictNullChecks": false,
"noUnusedLocals": true,
"pretty": true,
"skipLibCheck": true,
"lib": [
"es2015"
]
}
}
I am running tsc --build to generate the build.
Is there anything that I have been doing wrong ?