Skip to content

Missing MSSQL input type #11285

@sudhirt4

Description

@sudhirt4

Issue description

In MSSQL, when using the "find" method with where conditions on a "varchar" column, the query runner fails to specify the parameter type, causing performance issues.

Refer

Expected Behavior

Typeorm should handle the parameter input to node-mssql correctly

Actual Behavior

According to the node-mssql driver docs, the input type defaults to a JS data type. However, for "varchar," it appears to conflict with "nvarchar," leading to the wrong data type being used in queries.

As a result, runtime data conversion occurs, significantly impacting query performance (our application crashed under high load due to this issue).

For now, we're using a workaround by executing raw queries and manually handling SQL parameters. This resolved the performance issue, but it should be handled by the ORM itself.

Steps to reproduce

  1. Define a varchar column
@Index()
@Column({ type: 'varchar', nullable: true })
 memberId: string | null
  1. Query the entity with where condition on that column
this.somEntityRepo.find({ where: { memberId: "someValue" } })

On a large dataset, you can verify the resources used by this query.


Workaround which resolved the performance issue

 await this.connection.query(`SELECT * FROM "someEntity" WHERE "memberId" = ${'someValue'}`)

My Environment

Dependency Version
Node.js version 20.16.0
Typescript version 5.5.4
TypeORM version 0.3.20
mssql 10.0.4

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions