Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/guides/8-migration-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Note: code that reads `dataSource.name` will now receive `undefined` instead of

### `.connection` property in various classes is now `.dataSource`

The `connection` property in the `Driver`, `QueryRunner`, `EntityManager`, `QueryBuilder` and `*Event` classes was renamed to `dataSource`. For `EntityManager`, this change was announced in 0.3, but it was not actually implemented. To ease the transition, a deprecated getter was added that returns the same value as `dataSource`.
The `connection` property in the `Driver`, `QueryRunner`, `EntityManager`, `QueryBuilder`, `EntityMetadata` and `*Event` classes was renamed to `dataSource`. For `EntityManager`, this change was announced in 0.3, but it was not actually implemented. To ease the transition, a deprecated getter was added that returns the same value as `dataSource`.

### Miscellaneous

Expand Down
5 changes: 1 addition & 4 deletions src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ClosureJunctionEntityMetadataBuilder {
// create entity metadata itself
const entityMetadata = new EntityMetadata({
parentClosureEntityMetadata: parentClosureEntityMetadata,
connection: this.dataSource,
dataSource: this.dataSource,
args: {
target: "",
name:
Expand All @@ -47,7 +47,6 @@ export class ClosureJunctionEntityMetadataBuilder {
parentClosureEntityMetadata.primaryColumns.forEach((primaryColumn) => {
entityMetadata.ownColumns.push(
new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
closureType: "ancestor",
referencedColumn: primaryColumn,
Expand Down Expand Up @@ -77,7 +76,6 @@ export class ClosureJunctionEntityMetadataBuilder {
)
entityMetadata.ownColumns.push(
new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
closureType: "descendant",
referencedColumn: primaryColumn,
Expand Down Expand Up @@ -130,7 +128,6 @@ export class ClosureJunctionEntityMetadataBuilder {
if (parentClosureEntityMetadata.treeLevelColumn) {
entityMetadata.ownColumns.push(
new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
args: {
target: "",
Expand Down
14 changes: 4 additions & 10 deletions src/metadata-builder/EntityMetadataBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export class EntityMetadataBuilder {
}

return new EntityMetadata({
connection: this.dataSource,
dataSource: this.dataSource,
args: tableArgs,
inheritanceTree: inheritanceTree,
tableTree: tableTree,
Expand Down Expand Up @@ -566,7 +566,6 @@ export class EntityMetadataBuilder {
}

const column = new ColumnMetadata({
connection: this.dataSource,
entityMetadata,
args,
})
Expand Down Expand Up @@ -594,8 +593,7 @@ export class EntityMetadataBuilder {
)
if (!discriminatorColumn) {
discriminatorColumn = new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
entityMetadata,
args: {
target: entityMetadata.target,
mode: "virtual",
Expand Down Expand Up @@ -655,8 +653,7 @@ export class EntityMetadataBuilder {
if (entityMetadata.treeType === "materialized-path") {
entityMetadata.ownColumns.push(
new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
entityMetadata,
materializedPath: true,
args: {
target: entityMetadata.target,
Expand All @@ -675,7 +672,6 @@ export class EntityMetadataBuilder {
const { left, right } = namingStrategy.nestedSetColumnNames
entityMetadata.ownColumns.push(
new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
nestedSetLeft: true,
args: {
Expand All @@ -693,8 +689,7 @@ export class EntityMetadataBuilder {
)
entityMetadata.ownColumns.push(
new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
entityMetadata,
nestedSetRight: true,
args: {
target: entityMetadata.target,
Expand Down Expand Up @@ -857,7 +852,6 @@ export class EntityMetadataBuilder {
.filterColumns(targets)
.map((args) => {
return new ColumnMetadata({
connection: this.dataSource,
entityMetadata,
embeddedMetadata,
args,
Expand Down
6 changes: 2 additions & 4 deletions src/metadata-builder/JunctionEntityMetadataBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class JunctionEntityMetadataBuilder {
)

const entityMetadata = new EntityMetadata({
connection: this.dataSource,
dataSource: this.dataSource,
args: {
target: "",
name: joinTableName,
Expand Down Expand Up @@ -88,7 +88,6 @@ export class JunctionEntityMetadataBuilder {
)

return new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
referencedColumn: referencedColumn,
args: {
Expand Down Expand Up @@ -153,8 +152,7 @@ export class JunctionEntityMetadataBuilder {
)

return new ColumnMetadata({
connection: this.dataSource,
entityMetadata: entityMetadata,
entityMetadata,
referencedColumn: inverseReferencedColumn,
args: {
target: "",
Expand Down
1 change: 0 additions & 1 deletion src/metadata-builder/RelationJoinColumnBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ export class RelationJoinColumnBuilder {
)
if (!relationalColumn) {
relationalColumn = new ColumnMetadata({
connection: this.dataSource,
entityMetadata: relation.entityMetadata,
embeddedMetadata: relation.embeddedMetadata,
args: {
Expand Down
47 changes: 18 additions & 29 deletions src/metadata/ColumnMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ export class ColumnMetadata {
// ---------------------------------------------------------------------

constructor(options: {
connection: DataSource
entityMetadata: EntityMetadata
embeddedMetadata?: EmbeddedMetadata
referencedColumn?: ColumnMetadata
Expand All @@ -356,7 +355,9 @@ export class ColumnMetadata {
materializedPath?: boolean
}) {
this.entityMetadata = options.entityMetadata
this.embeddedMetadata = options.embeddedMetadata!
const driver = this.entityMetadata.dataSource.driver

this.embeddedMetadata = options.embeddedMetadata
this.referencedColumn = options.referencedColumn
if (options.args.target) this.target = options.args.target
if (options.args.propertyName)
Expand Down Expand Up @@ -475,58 +476,46 @@ export class ColumnMetadata {
this.srid = options.args.options.srid
if ((options.args.options as VirtualColumnOptions).query)
this.query = (options.args.options as VirtualColumnOptions).query
if (this.isTreeLevel)
this.type = options.connection.driver.mappedDataTypes.treeLevel
if (this.isTreeLevel) this.type = driver.mappedDataTypes.treeLevel
if (this.isCreateDate) {
if (!this.type)
this.type = options.connection.driver.mappedDataTypes.createDate
if (!this.type) this.type = driver.mappedDataTypes.createDate
if (!this.default)
this.default = () =>
options.connection.driver.mappedDataTypes.createDateDefault
this.default = () => driver.mappedDataTypes.createDateDefault
// skip precision if it was explicitly set to "null" in column options. Otherwise use default precision if it exist.
if (
this.precision === undefined &&
options.args.options.precision === undefined &&
options.connection.driver.mappedDataTypes.createDatePrecision
driver.mappedDataTypes.createDatePrecision
)
this.precision =
options.connection.driver.mappedDataTypes.createDatePrecision
this.precision = driver.mappedDataTypes.createDatePrecision
}
if (this.isUpdateDate) {
if (!this.type)
this.type = options.connection.driver.mappedDataTypes.updateDate
if (!this.type) this.type = driver.mappedDataTypes.updateDate
if (!this.default)
this.default = () =>
options.connection.driver.mappedDataTypes.updateDateDefault
this.default = () => driver.mappedDataTypes.updateDateDefault
if (!this.onUpdate)
this.onUpdate =
options.connection.driver.mappedDataTypes.updateDateDefault
this.onUpdate = driver.mappedDataTypes.updateDateDefault
// skip precision if it was explicitly set to "null" in column options. Otherwise use default precision if it exist.
if (
this.precision === undefined &&
options.args.options.precision === undefined &&
options.connection.driver.mappedDataTypes.updateDatePrecision
driver.mappedDataTypes.updateDatePrecision
)
this.precision =
options.connection.driver.mappedDataTypes.updateDatePrecision
this.precision = driver.mappedDataTypes.updateDatePrecision
}
if (this.isDeleteDate) {
if (!this.type)
this.type = options.connection.driver.mappedDataTypes.deleteDate
if (!this.type) this.type = driver.mappedDataTypes.deleteDate
if (!this.isNullable)
this.isNullable =
options.connection.driver.mappedDataTypes.deleteDateNullable
this.isNullable = driver.mappedDataTypes.deleteDateNullable
// skip precision if it was explicitly set to "null" in column options. Otherwise use default precision if it exist.
if (
this.precision === undefined &&
options.args.options.precision === undefined &&
options.connection.driver.mappedDataTypes.deleteDatePrecision
driver.mappedDataTypes.deleteDatePrecision
)
this.precision =
options.connection.driver.mappedDataTypes.deleteDatePrecision
this.precision = driver.mappedDataTypes.deleteDatePrecision
}
if (this.isVersion)
this.type = options.connection.driver.mappedDataTypes.version
if (this.isVersion) this.type = driver.mappedDataTypes.version
if (options.closureType) this.closureType = options.closureType
if (options.nestedSetLeft) this.isNestedSetLeft = options.nestedSetLeft
if (options.nestedSetRight)
Expand Down
40 changes: 24 additions & 16 deletions src/metadata/EntityMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ export class EntityMetadata {
// -------------------------------------------------------------------------

/**
* Connection where this entity metadata is created.
* DataSource where this entity metadata is created.
*/
connection: DataSource
dataSource: DataSource

/**
* DataSource where this entity metadata is created.
* @deprecated since 1.0.0. Use {@link dataSource} instance instead.
*/
get connection(): DataSource {
return this.dataSource
}

/**
* Metadata arguments used to build this entity metadata.
Expand Down Expand Up @@ -521,14 +529,14 @@ export class EntityMetadata {
// ---------------------------------------------------------------------

constructor(options: {
connection: DataSource
dataSource: DataSource
inheritanceTree?: Function[]
inheritancePattern?: "STI" /*|"CTI"*/
tableTree?: TreeMetadataArgs
parentClosureEntityMetadata?: EntityMetadata
args: TableMetadataArgs
}) {
this.connection = options.connection
this.dataSource = options.dataSource
this.inheritanceTree = options.inheritanceTree || []
this.inheritancePattern = options.inheritancePattern
this.treeType = options.tableTree ? options.tableTree.type : undefined
Expand Down Expand Up @@ -574,12 +582,12 @@ export class EntityMetadata {
}

// add "typename" property
if (this.connection.options.typename) {
ret[this.connection.options.typename] = this.targetName
if (this.dataSource.options.typename) {
ret[this.dataSource.options.typename] = this.targetName
}

this.lazyRelations.forEach((relation) =>
this.connection.relationLoader.enableLazyLoad(
this.dataSource.relationLoader.enableLazyLoad(
relation,
ret,
queryRunner,
Expand Down Expand Up @@ -968,10 +976,10 @@ export class EntityMetadata {
// ---------------------------------------------------------------------

build() {
const namingStrategy = this.connection.namingStrategy
const entityPrefix = this.connection.options.entityPrefix
const namingStrategy = this.dataSource.namingStrategy
const entityPrefix = this.dataSource.options.entityPrefix
const entitySkipConstructor =
this.connection.options.entitySkipConstructor
this.dataSource.options.entitySkipConstructor

this.engine = this.tableMetadataArgs.engine
this.database =
Expand All @@ -986,8 +994,8 @@ export class EntityMetadata {
this.parentEntityMetadata
) {
this.schema = this.parentEntityMetadata.schema
} else if (this.connection.options?.hasOwnProperty("schema")) {
this.schema = (this.connection.options as any).schema
} else if (this.dataSource.options?.hasOwnProperty("schema")) {
this.schema = (this.dataSource.options as any).schema
}
this.givenTableName =
this.tableMetadataArgs.type === "entity-child" &&
Expand Down Expand Up @@ -1019,10 +1027,10 @@ export class EntityMetadata {

if (
this.tableMetadataArgs.type === "junction" &&
this.connection.driver.maxAliasLength &&
this.connection.driver.maxAliasLength > 0 &&
this.dataSource.driver.maxAliasLength &&
this.dataSource.driver.maxAliasLength > 0 &&
this.tableNameWithoutPrefix.length >
this.connection.driver.maxAliasLength
this.dataSource.driver.maxAliasLength
) {
// note: we are not using DriverUtils.buildAlias here because we would like to avoid
// hashed table names. However, current algorithm also isn't perfect, but we cannot
Expand All @@ -1044,7 +1052,7 @@ export class EntityMetadata {
this.expression = this.tableMetadataArgs.expression
this.withoutRowid =
this.tableMetadataArgs.withoutRowid === true ? true : false
this.tablePath = this.connection.driver.buildTableName(
this.tablePath = this.dataSource.driver.buildTableName(
this.tableName,
this.schema,
this.database,
Expand Down
11 changes: 4 additions & 7 deletions src/metadata/IndexMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,10 @@ export class IndexMetadata {
}) {
// check if index type is supported
if (
options.args &&
options.args.type &&
((options.entityMetadata.connection.driver.supportedIndexTypes &&
!options.entityMetadata.connection.driver.supportedIndexTypes.find(
(idx) => idx === options.args?.type,
)) ||
!options.entityMetadata.connection.driver.supportedIndexTypes)
options.args?.type &&
!options.entityMetadata.dataSource.driver.supportedIndexTypes?.includes(
options.args.type,
)
) {
throw new TypeORMError(`Unsupported index type`)
}
Expand Down
12 changes: 0 additions & 12 deletions src/query-builder/JoinAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,6 @@ export class JoinAttribute {
}

return undefined

/*if (typeof this.entityOrProperty === "string") { // entityOrProperty is a custom table

// first try to find entity with such name, this is needed when entity does not have a target class,
// and its target is a string name (scenario when plain old javascript is used or entity schema is loaded from files)
const metadata = this.connection.entityMetadatas.find(metadata => metadata.name === this.entityOrProperty);
if (metadata)
return metadata;

// check if we have entity with such table name, and use its metadata if found
return this.connection.entityMetadatas.find(metadata => metadata.tableName === this.entityOrProperty);
}*/
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/schema-builder/RdbmsSchemaBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class RdbmsSchemaBuilder implements SchemaBuilder {
async build(): Promise<void> {
this.queryRunner = this.dataSource.createQueryRunner()

// this.connection.driver.database || this.currentDatabase;
this.currentDatabase = this.dataSource.driver.database
this.currentSchema = this.dataSource.driver.schema

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe("relations > eager relations > basic", () => {
// Build the query to inspect the generated SQL
const sql = dataSource.manager
.getRepository(Editor)
.metadata.connection.createQueryBuilder(Editor, "Editor")
.metadata.dataSource.createQueryBuilder(Editor, "Editor")
.setFindOptions({
where: { userId: 1 },
relations: {
Expand Down
Loading
Loading