-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue description
Selecting BLOB/Buffer columns fails in TypeORM 0.3.26 with TypeError: val.toString is not a function (regression from 0.3.25)
Expected Behavior
- Queries that select BLOB/Buffer columns (e.g., mediumblob) should return Node.js Buffer instances, just as in 0.3.25.
- Binary data should be retrievable via getOne(), getRawOne(), or repository.findOne({ select: ['image'] }) without throwing errors.
Actual Behavior
- Any attempt to select a BLOB column results in TypeError: val.toString is not a function originating from sqlstring.
- The query never executes; no results are returned.
Steps to reproduce
Create a simple entity with a blob column:
@Entity()
export class Person {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column('mediumblob', { select: false, nullable: true })
image: Buffer;
}Run a query that selects the blob field:
const person = await repository
.createQueryBuilder('person')
.addSelect('person.image')
.where('person.id = :id', { id })
.getOne();Observe the error:
TypeError: val.toString is not a function
My Environment
| Dependency | Version |
|---|---|
| Operating System | macOS Sequoia 15.6.1 |
| Node.js version | 20.19.4 |
| Typescript version | 5.9.2 |
| TypeORM version | 0.3.26 |
| Driver | mysql2 3.14.3 |
Additional Context
After upgrading to TypeORM 0.3.26, queries involving BLOB/Buffer columns fail with:
TypeError: val.toString is not a function
at Object.escape (.../node_modules/sqlstring/lib/SqlString.js:52:33)
at Object.format (.../node_modules/sqlstring/lib/SqlString.js:100:19)
at PoolConnection.format (.../node_modules/mysql2/lib/base/connection.js:521:22)
at PoolConnection.query (.../node_modules/mysql2/lib/base/connection.js:566:25)
...
This did not happen with TypeORM 0.3.25. The error appears to be related to the change in 0.3.26 where stringifyObjects: true is now passed to the MySQL driver by default.
PR 11574 seems to introduce the issue. I am not sure if this behavior is intended this way, because it seems like it is a breaking change.
To fix it I had to change my connection settings as stated in the PR:
it can be disabled by passing stringifyObjects: false in the extra connection options if needed.
This seems to work for me.
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?
No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.