发布说明 1.0
TypeORM 1.0 是一个主要版本,它移除了长期弃用的 API、现代化了平台要求,并带来了 0.3.x 周期中积累的数十项 bug 修复与新特性。
破坏性变更
详细的升级说明请参阅升级指南。
平台要求
- 要求 Node.js 20+ —— 不再支持 Node.js 16 和 18,最低 JavaScript 目标现在是 ES2023(#11382,作者 @alumni)
- 移除
Bufferpolyfill —— 在非 Node 平台上二进制数据现在使用Uint8Array;Node.js 的Buffer(它继承自Uint8Array)继续照常工作(#11935,作者 @pujux) - 替换 Glob 库 ——
glob已被替换为tinyglobby,rimraf已被移除,依赖更少(#11699,作者 @alumni) - 哈希改用原生
crypto——sha.js和uuid包已被替换为原生crypto模块和crypto.randomUUID()(#11864,作者 @G0maa;#11769,作者 @mag123c)
驱动变更
- MySQL / MariaDB:弃用
mysql包 —— 只支持mysql2;connectorPackage选项已移除(#11766,作者 @pkuczynski) - MySQL:
legacySpatialSupport现在默认为false—— 默认使用标准的ST_GeomFromText/ST_AsText函数(#12083,作者 @pkuczynski) - MySQL:移除
width和zerofill列选项 —— 它们在 MySQL 8.0.17 中被弃用,并在 MySQL 8.4 中被移除(#12084,作者 @pkuczynski) - MySQL:
QueryBuilder.useIndex()接受索引名而非原生 SQL ——useIndex()现在接受单个索引名或名称数组,并把它们作为标识符转义。此前该参数被当作原生的、逗号分隔的 SQL 片段插值,这允许标识符注入(#12344,作者 @eddieran) - SQLite:弃用
sqlite3,默认使用better-sqlite3—— 不再支持sqlite3包;flags和busyTimeout选项已移除(#11836,作者 @pkuczynski) - MongoDB:要求驱动 v7+ —— 不再支持 MongoDB Node.js 驱动 v5/v6;
stats()方法已移除;已弃用的连接选项已移除;内部类型不再导出(#12208,作者 @naorpeled;#12179,作者 @pkuczynski;#12120,作者 @pkuczynski;#12037,作者 @alumni) - MS SQL Server:移除
domain连接选项 —— 请改用 NTLM 类型的authentication(#12135,作者 @pkuczynski) - MS SQL Server:
options.isolation更名为options.isolationLevel—— 值格式从READ_COMMITTED改为READ COMMITTED以匹配IsolationLevel类型;新增SNAPSHOT隔离级别(#12231,作者 @Cprakhar) - SAP HANA:移除已弃用的连接别名 ——
hanaClientDriver、pool.max、pool.requestTimeout、pool.idleTimeout等已被移除,请改用它们现代的等价项(#12080,作者 @gioboa) - Expo:移除旧版驱动 —— 旧版 Expo SQLite 驱动已移除;请使用 Expo SDK v52+ 及其现代异步 API(#11860,作者 @G0maa)
- Redis:移除旧版客户端支持 —— 查询结果缓存只支持现代 Redis 客户端(v4+)(#12057,作者 @G0maa)
移除的 API
- 移除
Connection和ConnectionOptions—— 请改用DataSource和DataSourceOptions(#12022,作者 @alumni) .connection属性更名为.dataSource——Driver、QueryRunner、EntityManager、QueryBuilder、EntityMetadata以及所有*Event订阅者接口上的connection属性已更名为dataSource;提供了一个已弃用的 getter 作为过渡(#12244、#12245、#12246、#12249,作者 @pkuczynski)- 移除
ConnectionManager和全局便捷函数 ——createConnection、getConnection、getManager、getRepository、createQueryBuilder等全局函数已移除(#12098,作者 @michaelbromley) - 移除
getMongoRepository和getMongoManager全局函数 —— 请改用dataSource.getMongoRepository()和dataSource.mongoManager(#12099,作者 @pkuczynski) - 移除
DataSource.name—— 命名连接在 v0.3 中已弃用;ConnectionOptionsReader.all()更名为get()(#12136,作者 @pkuczynski) - 移除
TYPEORM_*环境变量支持 ——ConnectionOptionsEnvReader、ormconfig.env以及dotenv自动加载均已移除(#12134,作者 @pkuczynski) - 移除
findByIds—— 请改用带In运算符的findBy(#12114,作者 @pkuczynski) - 移除
findOneById—— 请改用findOneBy(#12198,作者 @pkuczynski) - 移除
Repository.exist()—— 请改用Repository.exists()(#12131,作者 @pkuczynski) - 移除
AbstractRepository、@EntityRepository和getCustomRepository—— 请改用Repository.extend()(#12096,作者 @pkuczynski) - 移除
@RelationCount装饰器 —— 请改用带子查询的@VirtualColumn(#12181,作者 @pkuczynski) - 移除 IoC 容器系统 ——
useContainer()、getFromContainer()及相关类型已移除(#12180,作者 @pkuczynski) - 移除
readonly列选项 —— 请改用update: false(#12132,作者 @pkuczynski) - 移除
ColumnNumericOptions上的unsigned—— 仅影响 decimal/float 类型;整数的unsigned保持不变(#12133,作者 @pkuczynski) - QueryBuilder:移除
onConflict()、已弃用的orUpdate()重载和setNativeParameters()—— 请改用orIgnore()/orUpdate()的数组签名以及setParameters()(#12090,作者 @pkuczynski) - QueryBuilder:移除
printSql()—— 它是多余的,因为所有已执行的查询都已经通过所配置的日志记录器记录;请改用getSql()或getQueryAndParameters()来查看 SQL(#12151,作者 @naorpeled;#12220,作者 @pkuczynski) - QueryBuilder:移除
WhereExpression类型别名 —— 请改用WhereExpressionBuilder(#12097,作者 @pkuczynski) - QueryBuilder:移除
replacePropertyNames()—— 它是一个空操作(#12178,作者 @pkuczynski) - 移除
join查找选项 —— LEFT JOIN 请使用relations,其他连接类型请使用 QueryBuilder(#12188,作者 @pkuczynski) - 移除基于字符串的
select—— 请使用对象语法select: { id: true }代替select: ["id"](#12214,作者 @pkuczynski) - 移除基于字符串的
relations—— 请使用对象语法relations: { profile: true }代替relations: ["profile"](#12215,作者 @pkuczynski) - 移除已弃用的锁模式 ——
pessimistic_partial_write和pessimistic_write_or_fail被带onLocked选项的pessimistic_write取代(#12093,作者 @pkuczynski) - 移除
QueryRunner.loadedTables和loadedViews—— 请改用getTables()和getViews()(#12183,作者 @pkuczynski) - 移除
MigrationExecutor.getAllMigrations()—— 请改用getPendingMigrations()、getExecutedMigrations()或dataSource.migrations(#12142,作者 @pkuczynski) - 移除
EntityMetadata.createPropertyPath()静态方法 —— 内部工具,没有公开替代品(#12141,作者 @pkuczynski) - 从驱动和 query builder 中移除内部的
nativeParameters管道(#12104,作者 @pkuczynski) - 从 Broadcaster 中移除内部的
broadcastLoadEventsForAll()(#12137,作者 @pkuczynski) - 移除内部的
DriverUtils.buildColumnAlias()—— 请改用buildAlias()(#12138,作者 @pkuczynski) - 移除
RdbmsSchemaBuilder.renameTables()—— 一个从未被调用过的空操作方法(#12284,作者 @naorpeled) - 移除
EntityMetadata.getValueMap()的options参数 ——skipNulls选项从未生效;请移除第三个参数(#12303,作者 @naorpeled) LegacyOracleNamingStrategy和NamingStrategyV03移到@typeorm/legacy-naming-strategies—— 这些类不再从typeorm核心包导出;如果你仍然需要它们,请安装独立的@typeorm/legacy-naming-strategies包并从那里导入(#12416,作者 @alumni)
行为变更
- 非空关系现在使用 INNER JOIN —— 标记为
nullable: false的ManyToOne和拥有方OneToOne关系现在使用INNER JOIN而不是LEFT JOIN,这可能会排除带有孤儿外键的行(#12064,作者 @pkuczynski) invalidWhereValuesBehavior默认为throw—— 在 where 条件中传入null或undefined现在会抛出错误,而不是静默忽略该属性;匹配 null 请使用IsNull()(#11710,作者 @naorpeled)invalidWhereValuesBehavior仅作用于高层 API —— QueryBuilder 的.where()、.andWhere()、.orWhere()不再受该设置影响(#11878,作者 @naorpeled)ConnectionOptionsReader和FileLogger的路径从process.cwd()解析 ——ConnectionOptionsReader不再使用app-root-path来定位ormconfig文件;改为搜索process.cwd()。要给构造函数传{ root: "/custom/path" }来覆盖。FileLogger.logPath同样从process.cwd()解析——当应用不是从其根文件夹启动时,请使用绝对路径(#12257,作者 @alumni)
新特性
Query Builder
INSERT INTO ... SELECT FROM ...——InsertQueryBuilder上新增valuesFromSelect()方法,用于数据迁移和转换查询(#11896,作者 @Cprakhar)- update/upsert 的
returning选项 —— repository 和 entity manager 的update()与upsert()方法现在在支持RETURNING子句的数据库上支持returning选项(#11782,作者 @naorpeled) - 所有 drop 方法新增
ifExists参数 ——dropColumn、dropIndex、dropPrimaryKey、dropForeignKey、dropUniqueConstraint、dropCheckConstraint、dropExclusionConstraint及其复数形式现在都接受ifExists标志(#12121,作者 @pkuczynski) QueryRunner的显式资源管理 —— 支持await using语法(TypeScript 5.2+)以自动清理(#11701,作者 @alumni)
事务
- 所有驱动都支持 DataSource 级默认隔离级别 ——
DataSourceOptions.isolationLevel现在被每个支持事务的驱动采纳,而不仅仅是 SQL Server。通过 DataSource 启动的事务(显式的,或 DML 隐式的)默认使用该级别(#12269,作者 @pkuczynski) - Aurora Postgres:事务隔离级别支持 —— Aurora Postgres 现在会在 DataSource 上以及显式
startTransaction()调用上采纳isolationLevel选项(#12334,作者 @pkuczynski) - Spanner:事务隔离级别支持 —— Google Spanner 现在会采纳
isolationLevel选项。Spanner 的supportedIsolationLevels仅限于REPEATABLE READ(目前处于预览阶段)和SERIALIZABLE(#12335,作者 @pkuczynski)
驱动
- PostgreSQL:枚举变更使用
ADD VALUE—— 添加新的枚举值时,TypeORM 现在会在可能的情况下使用更简单的ALTER TYPE ... ADD VALUE语法,而不是"重命名-创建-迁移-删除"四步方案(#10956,作者 @janzipek) - PostgreSQL:额外扩展 —— 新增
installExtensions选项,用于在连接建立期间安装额外的 PostgreSQL 扩展(#11888,作者 @Cprakhar) - PostgreSQL:部分索引支持 —— 添加对 PostgreSQL 部分索引的支持(#11318,作者 @freePixel)
- SAP HANA:SELECT 中的锁 —— SAP HANA 查询现在支持
FOR UPDATE及其他锁模式(#11996,作者 @alumni) - SAP HANA:表注释 ——
@Entity({ comment: "..." })现在在 SAP HANA 上可用(#11939,作者 @Cprakhar) - SAP HANA:连接池超时 —— 新增
maxWaitTimeoutIfPoolExhausted连接池选项(#11868,作者 @alumni) - SAP HANA:生成列 ——
@Column({ generatedType: "STORED", asExpression: "..." })现在在 SAP HANA 中受支持(#12393,作者 @Cprakhar) - SQLite:
jsonb列类型 —— SQLite 现在支持jsonb列类型(#11933,作者 @Cprakhar) - MongoDB:基于对象的
select投影 ——find*()方法现在除了已有的字符串数组形式外,还接受其他驱动所使用的同样的对象式select语法(select: { id: true, name: true })(#12237,作者 @pkuczynski) - React Native:加密密钥 —— 新增选项,用于为 React Native SQLite 数据库传入加密密钥(#11736,作者 @HtSpChakradharCholleti)
持久化与 Upsert
clear()中的级联截断 ——Repository.clear()和EntityManager.clear()现在接受{ cascade: true },会在 PostgreSQL、CockroachDB 和 Oracle 上发出TRUNCATE ... CASCADE(#11866,作者 @Cprakhar)increment/decrement的类型改进 —— conditions 参数现在使用正确的、感知实体的类型,而不是any(#11294,作者 @OSA413)
列类型与装饰器
其他
- 面向 v1 迁移的自动化 codemod —— 新的
@typeorm/codemod包可自动处理大部分破坏性变更:运行npx @typeorm/codemod v1 src/即可更新导入、API 重命名、查找选项语法等(#12233,作者 @pkuczynski) - 改进的 ormconfig 错误处理 —— 加载失败现在会记录警告,而不是静默失败(#11871,作者 @Cprakhar)
Bug 修复
查询生成
orderBy中的列别名被正确转义 —— 避免别名与保留字冲突时出现 SQL 错误(#12027,作者 @Cprakhar)addOrderBy能解析数据库列名 —— 现在使用数据库列名(例如created_at)代替属性名也能正确工作(#11904,作者 @smith-xyz)- 子查询列排序解析 —— 修复了按子查询列排序时出现 "Cannot get metadata for given alias" 错误的问题(#11343,作者 @trannhan0810)
- 保留
select的列顺序 ——getQuery()/getSql()现在按通过select()和addSelect()添加的顺序返回列(#11902,作者 @Cprakhar) - 修复
.update()的查询生成 —— 修正了使用 QueryBuilder.update()时生成错误 SQL 的问题(#11993,作者 @gioboa) - 带表别名的 upsert SQL 生成 —— 修复了带表继承和自定义模式的 upsert 查询中列引用错误的问题(#11915,作者 @Cprakhar)
- 带连接的 limit —— 修复了带连接使用
skip/take分页时结果错误的问题(#11987,作者 @gioboa) - 括号内的连接属性 —— 修复了条件中包含括号时的连接解析问题(#11218,作者 @balkrushna)
- 为聚合函数禁用全局
ORDER BY——repo.max()、repo.min()等不再生成带ORDER BY子句的非法 SQL(#11925,作者 @Cprakhar) - 分页子查询包含被连接实体的主键 —— 带
skip/take的leftJoin现在能正确加载关联实体(#11669,作者 @mag123c) - camelCase 别名缩短 ——
shorten方法现在能正确处理camelCase_aliases(#11283,作者 @OSA413) QueryBuilder.update()的实体类型 ——update(partialEntity)签名现在使用正确的、感知实体的类型,而不是松散的对象(#11296,作者 @OSA413)- 日志查询空白 —— 记录的查询字符串不再包含首尾空白(#12047,作者 @Cprakhar)
JsonContains接受数组值 ——JsonContains([...])不再抛出错误,并在 PostgreSQL 上生成预期的@>包含谓词(#12420,作者 @kyungseopk1m)- MSSQL 计算列的连接作用域 —— 当多张表共享列名时,计算列的结构自省现在限定在正确的表上(#12288,作者 @PreAgile)
关系与急加载
- 带非空外键的孤儿一对多子对象现在会被删除 —— 保存带级联的一对多关系并替换子对象时,带非空外键的孤儿行现在会被删除,而不是因约束冲突而失败;可空外键的行仍像以前一样被置空(#11982,作者 @naorpeled)
- 急加载关系现在遵循
relationLoadStrategy: "query"—— 设置"query"策略时,急加载关系会通过独立查询加载,而不是总是使用 JOIN(#11326,作者 @SharkSharp;#12256,作者 @pkuczynski) - 自引用关系别名冲突 —— 使用
relationLoadStrategy: "query"的自引用关系不再因别名冲突而生成错误 SQL(#11066,作者 @campmarc) - 急加载关系不再被连接两次 —— 在
relations中显式指定一个急加载关系不再导致重复的 JOIN(#11991,作者 @veeceey) - 带急加载关系的保存 —— 修复了实体带有急加载关系时的保存失败问题(#11975,作者 @gioboa)
select: false的列不再被读查询返回 —— 标记为select: false的列现在会正确地从find和 query-builder 结果中排除;使用addSelect选择性加入。注意select: false只控制读取时从数据库加载什么——repository.save()返回的内存中实体(以及你传入的引用)保持不变,因此你提供的任何值在持久化之后仍然可用(#11944,作者 @gioboa;#12501,作者 @tada5hi)- 配合
joinMapOne方法的子查询 —— 修复了使用 join map 方法时的错误行为(#11943,作者 @gioboa) - 嵌套嵌入实体中的关系 ID —— 修复了在嵌入实体内映射关系 ID 时出现
TypeError: Cannot set properties of undefined的问题(#11942,作者 @Cprakhar) RelationIdLoader别名处理 —— 使用DriverUtils.getAlias以防止标识符长度限制较短的数据库截断别名(#11228,作者 @te1)createPropertyPath中的*-to-many—— 移除了阻止某些关系配置的错误错误处理(#11119,作者 @ThbltLmr)- 带复合主键的
OneToMany上的级联删除 —— 当目标有复合主键时,cascade: ["remove"]现在能正确地把删除传播给子实体;此前CascadesSubjectBuilder从未把这些子对象标记为mustBeRemoved,导致外键约束冲突(#12286,作者 @pkuczynski) withDeleted传播到多对多恢复的关系 id 加载器 —— 恢复带多对多关系的软删除实体时不再尝试重新插入已存在的中间表行;当父查询设置了withDeleted时,RelationIdLoader现在会包含软删除的实体(#12287,作者 @pkuczynski)
持久化
- 带
update: false或generatedType的 upsert —— upsert 现在能正确处理那些不应被更新的列(#12030,作者 @gioboa) - 值转换器应用于
FindOperator——ApplyValueTransformers现在能正确转换In、Between等FindOperator实例内部的值(#11172,作者 @ZimGil) - 软删除不再更新已软删除的行 ——
softDelete和softRemove现在会跳过已经软删除的行(#10705,作者 @hassanmehdi98) - 实体合并尊重
null值 —— 合并进实体时不再静默丢弃值为null的属性(#11154,作者 @knoid) - Map/对象比较 —— 修复了 Map 和普通对象列值的变更检测错误(#10990,作者 @mgohin)
- 日期转换器变更检测 —— 修复了带日期值转换器时的误报脏检测(#11963,作者 @gioboa)
- 子 mpath 更新 —— 重新指定父节点时,树形实体的 mpath 现在会被正确更新,即使父节点是软删除的(#10844,作者 @JoseCToscano)
- 闭包中间表的模式/数据库传播 —— 模式和数据库设置现在会正确传播到闭包中间表(#12110,作者 @pkuczynski)
- 结构构建器中的虚拟属性处理 —— 结构构建器不再尝试为虚拟属性创建列(#11000,作者 @skyran1278)
- 无名
TableForeignKey的删除 —— 删除没有显式名称的外键不再失败(#10744,作者 @taichunmin) getPendingMigrations不再创建迁移表 —— 检查待执行迁移不再有副作用(#11672,作者 @pkuczynski)- 多对多
deferrable外键 ——@ManyToMany现在会在中间表的外键上采纳deferrable选项(#11924,作者 @smith-xyz) - 复合外键列顺序 —— 结构构建器会对复合外键中被引用的列排序,使其与被引用主键的索引顺序一致,避免 MySQL / MSSQL / SAP HANA 拒绝该约束(#12280,作者 @pkuczynski)
- 变更集中保留用户定义的共享连接列 —— 多个关系之间共享的显式
@JoinColumn条目不再在持久化过程中被丢弃(#12354,作者 @PreAgile)
驱动专属修复
- PostgreSQL:
timestamptz持久化/水合 ——timestamp with time zone列现在能正确持久化和读取(#11774,作者 @Minishlink) - PostgreSQL:几何类型重复保存 —— point/circle 值现在会在持久化时被规范化,避免重新保存已读取对象时出现非法输入错误(#11857,作者 @Cprakhar)
- PostgreSQL/CockroachDB:带引号表名的表 —— 修复了名称中含特殊字符的表的处理(#10993,作者 @iskalyakin)
- PostgreSQL:顺序执行查询 —— 现在查询会在同一连接上顺序执行,以避免
pg8.19.0 的弃用警告,包括其余的关系加载和持久化路径(#12105,作者 @pkuczynski;#12421,作者 @kyungseopk1m) - MySQL:PolarDB-X 2.0 版本检测 ——
getVersion()对 PolarDB-X 2.0 不再返回undefined(#11837,作者 @Missna) - MongoDB:
ObjectIdColumn属性名转换 ——findOneBy({ id: value })现在能在 MongoDB 查询中正确转换为_id(#12200,作者 @pkuczynski) - MongoDB:嵌套文档的嵌入数组 —— 正确处理嵌套文档结构中的嵌入数组(#10940,作者 @mciuchitu)
- SQLite:simple-enum 数组 —— 带
array: true的simple-enum列不再因 CHECK 约束错误而失败(#11865,作者 @Cprakhar) - SAP HANA:
Date参数转义 —— JSDate值现在作为查询参数传递,而不是被嵌入 SQL 字符串中(#11867,作者 @alumni) - CockroachDB:事务重试中的结构化查询结果 ——
useStructuredResult标志现在会在 CockroachDB 事务重试重放期间被保留(#11861,作者 @naorpeled) - Cordova:查询影响行数 —— 查询结果现在包含受影响行数(#10873,作者 @jacobg)
- PostgreSQL / CockroachDB:枚举值声明顺序 —— 枚举值现在按其声明顺序加载,因此在没有任何变化时生成的迁移不再反复变动(#12404,作者 @pkuczynski)
- Expo:自动加载
expo-sqlite—— Expo 驱动通过loadDependencies()加载expo-sqlite,不再需要显式传入该模块(#12363,作者 @pkuczynski)
其他
- CLI
init命令 ——package.json不存在时不再崩溃(#11947,作者 @gioboa);发布的包现在正确包含脚手架所需的devDependencies(#12281,作者 @pkuczynski);init 期间不再运行npm install,因此在离线或非 Node 项目环境中也能工作(#12386,作者 @alumni) - Deno
process导入 —— 修复了 Deno 上process依赖的错误导入(#11248,作者 @yohannpoli) - 为 MySQL/MSSQL 保留查询堆栈跟踪 —— 驱动错误现在会保留最初的调用位置,让查询失败更容易调试(#12056,作者 @Cprakhar)
安全修复
- SQL 注入防护 —— 所有驱动的结构自省和 DDL 方法现在都使用参数化查询和转义后的标识符,防止通过数据库/模式/表/列名进行 SQL 注入(#12207,作者 @pkuczynski;#12197,作者 @pkuczynski;#12185,作者 @pkuczynski)
- OrderBy 条件校验 —— QueryBuilder 的
orderBy和addOrderBy现在会在运行时校验条件值,防止通过排序表达式注入(#12217,作者 @pkuczynski) - 在 Update/SoftDelete query builder 上校验
.limit()—— 传给.limit()的非数字值现在会在调用时抛出错误,而不是被插值进 SQL(#12436,作者 @smith-xyz)
性能改进
- PostgreSQL / CockroachDB:
clearDatabase()中批量 DROP —— 把单独的 DROP 语句合并成单条批量查询,显著减少测试准备期间的往返次数(#12164、#12159,作者 @pkuczynski)
TypeORM 1.0 is a major release that removes long-deprecated APIs, modernizes platform requirements, and ships dozens of bug fixes and new features accumulated during the 0.3.x cycle.
Breaking changes
See the Upgrading Guide for detailed upgrade instructions.
Platform requirements
- Node.js 20+ required — support for Node.js 16 and 18 has been dropped, and the minimum JavaScript target is now ES2023 (#11382 by @alumni)
Bufferpolyfill removed —Uint8Arrayis now used for binary data on non-Node platforms; Node.jsBuffer(which extendsUint8Array) continues to work as before (#11935 by @pujux)- Glob library replaced —
globhas been replaced withtinyglobbyandrimrafhas been removed, resulting in fewer dependencies (#11699 by @alumni) - Hashing moved to native
crypto— thesha.jsanduuidpackages have been replaced with the nativecryptomodule andcrypto.randomUUID()(#11864 by @G0maa, #11769 by @mag123c)
Driver changes
- MySQL / MariaDB:
mysqlpackage dropped — onlymysql2is supported; theconnectorPackageoption has been removed (#11766 by @pkuczynski) - MySQL:
legacySpatialSupportnow defaults tofalse— standardST_GeomFromText/ST_AsTextfunctions are used by default (#12083 by @pkuczynski) - MySQL:
widthandzerofillcolumn options removed — these were deprecated in MySQL 8.0.17 and removed in MySQL 8.4 (#12084 by @pkuczynski) - MySQL:
QueryBuilder.useIndex()accepts index name(s), not raw SQL —useIndex()now takes either a single index name or an array of names and escapes them as identifiers. Previously the argument was interpolated as a raw, comma-separated SQL fragment, which allowed identifier injection (#12344 by @eddieran) - SQLite:
sqlite3dropped,better-sqlite3is the default — thesqlite3package is no longer supported;flagsandbusyTimeoutoptions have been removed (#11836 by @pkuczynski) - MongoDB: driver v7+ required — support for MongoDB Node.js driver v5/v6 has been dropped;
stats()method removed; deprecated connection options removed; internal types are no longer exported (#12208 by @naorpeled, #12179 by @pkuczynski, #12120 by @pkuczynski, #12037 by @alumni) - MS SQL Server:
domainconnection option removed — useauthenticationwith NTLM type instead (#12135 by @pkuczynski) - MS SQL Server:
options.isolationrenamed tooptions.isolationLevel— value format changed fromREAD_COMMITTEDtoREAD COMMITTEDto matchIsolationLeveltype;SNAPSHOTisolation level added (#12231 by @Cprakhar) - SAP HANA: deprecated connection aliases removed —
hanaClientDriver,pool.max,pool.requestTimeout,pool.idleTimeout, and others have been removed in favor of their modern equivalents (#12080 by @gioboa) - Expo: legacy driver removed — the legacy Expo SQLite driver has been removed; use Expo SDK v52+ with the modern async API (#11860 by @G0maa)
- Redis: legacy client support removed — only modern Redis client (v4+) is supported for query result caching (#12057 by @G0maa)
Removed APIs
ConnectionandConnectionOptionsremoved — useDataSourceandDataSourceOptionsinstead (#12022 by @alumni).connectionproperty renamed to.dataSource— theconnectionproperty onDriver,QueryRunner,EntityManager,QueryBuilder,EntityMetadata, and all*Eventsubscriber interfaces has been renamed todataSource; a deprecated getter is provided as a bridge (#12244, #12245, #12246, #12249 by @pkuczynski)ConnectionManagerand global convenience functions removed —createConnection,getConnection,getManager,getRepository,createQueryBuilder, and other globals have been removed (#12098 by @michaelbromley)getMongoRepositoryandgetMongoManagerglobals removed — usedataSource.getMongoRepository()anddataSource.mongoManagerinstead (#12099 by @pkuczynski)DataSource.nameremoved — named connections were deprecated in v0.3;ConnectionOptionsReader.all()renamed toget()(#12136 by @pkuczynski)TYPEORM_*environment variable support removed —ConnectionOptionsEnvReader,ormconfig.env, anddotenvauto-loading have been removed (#12134 by @pkuczynski)findByIdsremoved — usefindBywithInoperator instead (#12114 by @pkuczynski)findOneByIdremoved — usefindOneByinstead (#12198 by @pkuczynski)Repository.exist()removed — useRepository.exists()instead (#12131 by @pkuczynski)AbstractRepository,@EntityRepository, andgetCustomRepositoryremoved — useRepository.extend()instead (#12096 by @pkuczynski)@RelationCountdecorator removed — use@VirtualColumnwith a sub-query instead (#12181 by @pkuczynski)- IoC container system removed —
useContainer(),getFromContainer(), and related types have been removed (#12180 by @pkuczynski) readonlycolumn option removed — useupdate: falseinstead (#12132 by @pkuczynski)unsignedonColumnNumericOptionsremoved — only affected decimal/float types; integerunsignedis unchanged (#12133 by @pkuczynski)- QueryBuilder:
onConflict(), deprecatedorUpdate()overload, andsetNativeParameters()removed — useorIgnore()/orUpdate()array signature andsetParameters()instead (#12090 by @pkuczynski) - QueryBuilder:
printSql()removed — it was redundant since all executed queries are already logged through the configured logger; usegetSql()orgetQueryAndParameters()to inspect SQL instead (#12151 by @naorpeled, #12220 by @pkuczynski) - QueryBuilder:
WhereExpressiontype alias removed — useWhereExpressionBuilderinstead (#12097 by @pkuczynski) - QueryBuilder:
replacePropertyNames()removed — it was a no-op (#12178 by @pkuczynski) joinfind option removed — userelationsfor LEFT JOINs or QueryBuilder for other join types (#12188 by @pkuczynski)- String-based
selectremoved — use object syntaxselect: { id: true }instead ofselect: ["id"](#12214 by @pkuczynski) - String-based
relationsremoved — use object syntaxrelations: { profile: true }instead ofrelations: ["profile"](#12215 by @pkuczynski) - Deprecated lock modes removed —
pessimistic_partial_writeandpessimistic_write_or_failreplaced bypessimistic_writewithonLockedoption (#12093 by @pkuczynski) QueryRunner.loadedTablesandloadedViewsremoved — usegetTables()andgetViews()instead (#12183 by @pkuczynski)MigrationExecutor.getAllMigrations()removed — usegetPendingMigrations(),getExecutedMigrations(), ordataSource.migrationsinstead (#12142 by @pkuczynski)EntityMetadata.createPropertyPath()static method removed — internal utility with no public replacement (#12141 by @pkuczynski)- Internal
nativeParametersplumbing removed from drivers and query builders (#12104 by @pkuczynski) - Internal
broadcastLoadEventsForAll()removed from Broadcaster (#12137 by @pkuczynski) - Internal
DriverUtils.buildColumnAlias()removed — usebuildAlias()instead (#12138 by @pkuczynski) RdbmsSchemaBuilder.renameTables()removed — empty no-op method that was never called (#12284 by @naorpeled)EntityMetadata.getValueMap()optionsparameter removed — theskipNullsoption was never functional; remove the third argument (#12303 by @naorpeled)LegacyOracleNamingStrategyandNamingStrategyV03moved to@typeorm/legacy-naming-strategies— these classes are no longer exported fromtypeormcore; install the separate@typeorm/legacy-naming-strategiespackage and import them from there if you still need them (#12416 by @alumni)
Behavioral changes
- Non-nullable relations now use INNER JOIN —
ManyToOneand owningOneToOnerelations markednullable: falsenow useINNER JOINinstead ofLEFT JOIN, which may exclude rows with orphaned foreign keys (#12064 by @pkuczynski) invalidWhereValuesBehaviordefaults tothrow— passingnullorundefinedin where conditions now throws an error instead of silently ignoring the property; useIsNull()for null matching (#11710 by @naorpeled)invalidWhereValuesBehaviorscoped to high-level APIs only — QueryBuilder's.where(),.andWhere(),.orWhere()are no longer affected by this setting (#11878 by @naorpeled)ConnectionOptionsReaderandFileLoggerpaths resolved fromprocess.cwd()—ConnectionOptionsReaderno longer usesapp-root-pathto locateormconfigfiles; it searchesprocess.cwd()instead. Pass{ root: "/custom/path" }to the constructor to override.FileLogger.logPathis likewise resolved fromprocess.cwd()— use an absolute path when the app is not started from its root folder (#12257 by @alumni)
New features
Query Builder
INSERT INTO ... SELECT FROM ...— newvaluesFromSelect()method onInsertQueryBuilderfor data migration and transformation queries (#11896 by @Cprakhar)returningoption for update/upsert — repository and entity managerupdate()andupsert()methods now support areturningoption on databases that supportRETURNINGclauses (#11782 by @naorpeled)ifExistsparameter on all drop methods —dropColumn,dropIndex,dropPrimaryKey,dropForeignKey,dropUniqueConstraint,dropCheckConstraint,dropExclusionConstraint, and their plural variants now accept anifExistsflag (#12121 by @pkuczynski)- Explicit resource management for
QueryRunner— supportsawait usingsyntax (TypeScript 5.2+) for automatic cleanup (#11701 by @alumni)
Transactions
- DataSource-level default isolation level for all drivers —
DataSourceOptions.isolationLevelis now honored by every driver that supports transactions, not just SQL Server. Transactions started through the DataSource (explicitly or implicitly for DML) use this level by default (#12269 by @pkuczynski) - Aurora Postgres: transaction isolation level support — Aurora Postgres now honors the
isolationLeveloption on DataSource and on explicitstartTransaction()calls (#12334 by @pkuczynski) - Spanner: transaction isolation level support — Google Spanner now honors the
isolationLeveloption. Spanner'ssupportedIsolationLevelsis limited toREPEATABLE READ(currently in preview) andSERIALIZABLE(#12335 by @pkuczynski)
Drivers
- PostgreSQL:
ADD VALUEfor enum changes — when adding new enum values, TypeORM now uses the simplerALTER TYPE ... ADD VALUEsyntax instead of the 4-step rename-create-migrate-drop approach, when possible (#10956 by @janzipek) - PostgreSQL: additional extensions — new
installExtensionsoption to install additional PostgreSQL extensions during connection setup (#11888 by @Cprakhar) - PostgreSQL: partial index support — add support for PostgreSQL partial indexes (#11318 by @freePixel)
- SAP HANA: locking in SELECT —
FOR UPDATEand other lock modes are now supported in SAP HANA queries (#11996 by @alumni) - SAP HANA: table comments —
@Entity({ comment: "..." })now works with SAP HANA (#11939 by @Cprakhar) - SAP HANA: pool timeout — new
maxWaitTimeoutIfPoolExhaustedpool option (#11868 by @alumni) - SAP HANA: generated columns —
@Column({ generatedType: "STORED", asExpression: "..." })is now supported in SAP HANA (#12393 by @Cprakhar) - SQLite:
jsonbcolumn type — SQLite now supports thejsonbcolumn type (#11933 by @Cprakhar) - MongoDB: object-based
selectprojection —find*()methods now accept the same object-basedselectsyntax used by other drivers (select: { id: true, name: true }) in addition to the existing string-array form (#12237 by @pkuczynski) - React Native: encryption key — new option to pass an encryption key for React Native SQLite databases (#11736 by @HtSpChakradharCholleti)
Persistence & Upsert
- Cascade truncate in
clear()—Repository.clear()andEntityManager.clear()now accept{ cascade: true }to issueTRUNCATE ... CASCADEon PostgreSQL, CockroachDB, and Oracle (#11866 by @Cprakhar) - Better typing for
increment/decrement— conditions parameter now uses proper entity-aware types instead ofany(#11294 by @OSA413)
Column types & Decorators
- Deferrable support on
@Exclusion— mirrors the existing deferrable support on@Uniqueand@Index(#11802 by @oGAD31)
Other
- Automated codemod for v1 migration — the new
@typeorm/codemodpackage automates most breaking changes: runnpx @typeorm/codemod v1 src/to update imports, API renames, find option syntax, and more (#12233 by @pkuczynski) - Improved ormconfig error handling — loading failures now log warnings instead of silently failing (#11871 by @Cprakhar)
Bug fixes
Query generation
- Column alias properly escaped in
orderBy— prevents SQL errors when alias names conflict with reserved words (#12027 by @Cprakhar) addOrderByresolves database column names — using the database column name (e.g.,created_at) instead of the property name now works correctly (#11904 by @smith-xyz)- Order subquery column resolution — fixed "Cannot get metadata for given alias" error when ordering by subquery columns (#11343 by @trannhan0810)
selectcolumn ordering preserved —getQuery()/getSql()now returns columns in the order they were added viaselect()andaddSelect()(#11902 by @Cprakhar).update()query generation fixed — corrected incorrect SQL generation when using QueryBuilder.update()(#11993 by @gioboa)- Upsert SQL generation with table alias — fixed incorrect column references in upsert queries with table inheritance and custom schemas (#11915 by @Cprakhar)
- Limit with joins — fixed incorrect results when using
skip/takepagination with joins (#11987 by @gioboa) - Join attributes inside brackets — fixed join parsing when conditions contain brackets (#11218 by @balkrushna)
- Disable global
ORDER BYfor aggregate functions —repo.max(),repo.min(), etc. no longer produce invalid SQL with anORDER BYclause (#11925 by @Cprakhar) - Pagination subquery includes joined entity PKs —
leftJoinwithskip/takenow correctly loads related entities (#11669 by @mag123c) - Alias shortening with camelCase — the
shortenmethod now correctly handlescamelCase_aliases(#11283 by @OSA413) - Entity typing for
QueryBuilder.update()— theupdate(partialEntity)signature now uses a proper entity-aware type instead of a loose object (#11296 by @OSA413) - Log query whitespace — trailing and leading whitespace is no longer included in logged query strings (#12047 by @Cprakhar)
JsonContainsaccepts array values —JsonContains([...])no longer throws and produces the expected@>containment predicate on PostgreSQL (#12420 by @kyungseopk1m)- MSSQL computed columns join scope — schema introspection of computed columns is now scoped to the correct table when multiple tables share column names (#12288 by @PreAgile)
Relations & Eager loading
- Orphaned one-to-many children with non-nullable FK are now deleted — when saving a one-to-many relation with cascade and replacing children, orphaned rows with a non-nullable FK are now deleted instead of failing with a constraint violation; nullable FK rows are still nullified as before (#11982 by @naorpeled)
- Eager relations now respect
relationLoadStrategy: "query"— eager relations are loaded via separate queries when the"query"strategy is set, instead of always using JOINs (#11326 by @SharkSharp, #12256 by @pkuczynski) - Self-referencing relation alias collision — self-referencing relations with
relationLoadStrategy: "query"no longer produce incorrect SQL due to alias collision (#11066 by @campmarc) - Eager relations no longer joined twice — explicitly specifying an eager relation in
relationsno longer causes duplicate JOINs (#11991 by @veeceey) - Save with eagerly loaded relations — fixed save failures when an entity has eagerly loaded relations (#11975 by @gioboa)
- Columns with
select: falseno longer returned by read queries — columns marked withselect: falseare now correctly excluded fromfindand query-builder results; useaddSelectto opt-in. Note thatselect: falseonly controls what is loaded from the database on a read — the in-memory entity returned byrepository.save()(and the reference you passed in) is left untouched, so any value you supplied is still available on it after persistence (#11944 by @gioboa, #12501 by @tada5hi) - Subquery with
joinMapOnemethods — fixed incorrect behavior when using join map methods (#11943 by @gioboa) - Relation IDs in nested embedded entities — fixed
TypeError: Cannot set properties of undefinedwhen mapping relation IDs within embedded entities (#11942 by @Cprakhar) RelationIdLoaderalias handling — usesDriverUtils.getAliasto prevent alias trimming by databases with short identifier limits (#11228 by @te1)*-to-manyincreatePropertyPath— removed incorrect error handling that prevented certain relation configurations (#11119 by @ThbltLmr)- Cascade remove on
OneToManywith composite primary keys —cascade: ["remove"]now correctly propagates the delete to child entities when the target has a composite PK; previouslyCascadesSubjectBuildernever marked these children asmustBeRemoved, causing FK constraint violations (#12286 by @pkuczynski) withDeletedpropagated to relation-id loader for many-to-many recover — recovering a soft-removed entity with many-to-many relations no longer tries to re-insert existing junction rows;RelationIdLoadernow includes soft-deleted entities when the parent query haswithDeletedset (#12287 by @pkuczynski)
Persistence
- Upsert with
update: falseorgeneratedType— upsert now correctly handles columns that should not be updated (#12030 by @gioboa) - Value transformers applied to
FindOperators —ApplyValueTransformersnow correctly transforms values insideFindOperatorinstances likeIn,Between, etc. (#11172 by @ZimGil) - Soft deletion no longer updates already soft-deleted rows —
softDeleteandsoftRemovenow skip rows that are already soft-deleted (#10705 by @hassanmehdi98) - Entity merge respects
nullvalues — merging into an entity no longer silently dropsnullproperty values (#11154 by @knoid) - Map/object comparison — fixed incorrect change detection for Map and plain object column values (#10990 by @mgohin)
- Date transformer change detection — fixed false-positive dirty detection with date value transformers (#11963 by @gioboa)
- Child mpath update — tree entity mpath is now correctly updated when re-parenting, even with soft-deleted parents (#10844 by @JoseCToscano)
- Closure junction table schema/database propagation — schema and database settings are now correctly propagated to closure junction tables (#12110 by @pkuczynski)
- Virtual property handling in schema builder — schema builder no longer attempts to create columns for virtual properties (#11000 by @skyran1278)
- Nameless
TableForeignKeydrop — dropping a foreign key without an explicit name no longer fails (#10744 by @taichunmin) getPendingMigrationsno longer creates the migrations table — checking for pending migrations no longer has side effects (#11672 by @pkuczynski)- Many-to-many
deferrableforeign keys —@ManyToManynow honors thedeferrableoption on the junction table's foreign keys (#11924 by @smith-xyz) - Composite foreign key column order — schema builder sorts referenced columns in composite foreign keys to match the referenced primary key index order, preventing MySQL / MSSQL / SAP HANA from rejecting the constraint (#12280 by @pkuczynski)
- User-defined shared join columns preserved in change set — explicit
@JoinColumnentries shared between relations are no longer dropped during persistence (#12354 by @PreAgile)
Driver-specific fixes
- PostgreSQL:
timestamptzpersistence/hydration —timestamp with time zonecolumns now persist and hydrate correctly (#11774 by @Minishlink) - PostgreSQL: geometric type re-save — point/circle values are now normalized on persist to avoid invalid input errors when re-saving hydrated objects (#11857 by @Cprakhar)
- PostgreSQL/CockroachDB: tables with quoted names — fixed handling of tables with special characters in names (#10993 by @iskalyakin)
- PostgreSQL: sequential query execution — queries are now executed sequentially on the same connection to avoid
pg8.19.0 deprecation warnings, including remaining relation-load and persistence paths (#12105 by @pkuczynski, #12421 by @kyungseopk1m) - MySQL: PolarDB-X 2.0 version detection —
getVersion()no longer returnsundefinedfor PolarDB-X 2.0 (#11837 by @Missna) - MongoDB:
ObjectIdColumnproperty name translation —findOneBy({ id: value })now correctly translates to_idin MongoDB queries (#12200 by @pkuczynski) - MongoDB: embedded arrays of nested documents — correctly processes embedded arrays within nested document structures (#10940 by @mciuchitu)
- SQLite: simple-enum arrays —
simple-enumcolumns witharray: trueno longer fail with CHECK constraint errors (#11865 by @Cprakhar) - SAP HANA:
Dateparameter escaping — JSDatevalues are now passed as query parameters instead of being embedded in SQL strings (#11867 by @alumni) - CockroachDB: structured query results in txn retry — the
useStructuredResultflag is now preserved during CockroachDB transaction retry replay (#11861 by @naorpeled) - Cordova: query rows affected — query results now include the count of affected rows (#10873 by @jacobg)
- PostgreSQL / CockroachDB: enum value declaration order — enum values are now loaded in their declared order, so generated migrations no longer churn when nothing has changed (#12404 by @pkuczynski)
- Expo: auto-load
expo-sqlite— the Expo driver loadsexpo-sqlitethroughloadDependencies(), removing the need to pass the module explicitly (#12363 by @pkuczynski)
Other
- CLI
initcommand — no longer crashes whenpackage.jsondoes not exist (#11947 by @gioboa); published package now correctly includesdevDependenciesneeded for scaffolding (#12281 by @pkuczynski); no longer runsnpm installduring init, so it works in offline or non-Node project setups (#12386 by @alumni) - Deno
processimport — fixed incorrect import for theprocessdependency on Deno (#11248 by @yohannpoli) - Query stack traces preserved for MySQL/MSSQL — driver errors now retain the originating call site, making query failures easier to debug (#12056 by @Cprakhar)
Security fixes
- SQL injection prevention — parameterized queries and escaped identifiers are now used across all drivers for schema introspection and DDL methods, preventing SQL injection via database/schema/table/column names (#12207 by @pkuczynski, #12197 by @pkuczynski, #12185 by @pkuczynski)
- OrderBy condition validation — QueryBuilder
orderByandaddOrderBynow validate condition values at runtime, preventing injection via order expressions (#12217 by @pkuczynski) .limit()validated on Update/SoftDelete query builders — non-numeric values passed to.limit()now throw at call time instead of being interpolated into SQL (#12436 by @smith-xyz)
Performance improvements
- PostgreSQL / CockroachDB: batched DROP in
clearDatabase()— consolidates individual DROP statements into single batched queries, significantly reducing round-trips during test setup (#12164, #12159 by @pkuczynski)