typeorm 0.3.18-dev.022d2b5 → 0.3.18-dev.122c897
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/driver/sap/SapDriver.d.ts +8 -0
- package/browser/driver/sap/SapDriver.js +14 -3
- package/browser/driver/sap/SapDriver.js.map +1 -1
- package/browser/driver/sap/SapQueryRunner.d.ts +5 -14
- package/browser/driver/sap/SapQueryRunner.js +53 -55
- package/browser/driver/sap/SapQueryRunner.js.map +1 -1
- package/browser/entity-manager/MongoEntityManager.d.ts +5 -1
- package/browser/entity-manager/MongoEntityManager.js +7 -0
- package/browser/entity-manager/MongoEntityManager.js.map +1 -1
- package/browser/entity-schema/EntitySchemaOptions.d.ts +4 -0
- package/browser/entity-schema/EntitySchemaOptions.js.map +1 -1
- package/browser/entity-schema/EntitySchemaTransformer.js +7 -0
- package/browser/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/browser/find-options/FindOptionsWhere.d.ts +1 -1
- package/browser/find-options/FindOptionsWhere.js.map +1 -1
- package/browser/metadata-builder/EntityMetadataBuilder.js +13 -0
- package/browser/metadata-builder/EntityMetadataBuilder.js.map +1 -1
- package/browser/persistence/subject-builder/ManyToManySubjectBuilder.js +6 -2
- package/browser/persistence/subject-builder/ManyToManySubjectBuilder.js.map +1 -1
- package/browser/platform/PlatformTools.js +2 -0
- package/browser/platform/PlatformTools.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.js +2 -0
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/repository/MongoRepository.d.ts +5 -1
- package/browser/repository/MongoRepository.js +6 -0
- package/browser/repository/MongoRepository.js.map +1 -1
- package/commands/MigrationGenerateCommand.js +3 -1
- package/commands/MigrationGenerateCommand.js.map +1 -1
- package/driver/sap/SapDriver.d.ts +8 -0
- package/driver/sap/SapDriver.js +15 -4
- package/driver/sap/SapDriver.js.map +1 -1
- package/driver/sap/SapQueryRunner.d.ts +5 -14
- package/driver/sap/SapQueryRunner.js +53 -55
- package/driver/sap/SapQueryRunner.js.map +1 -1
- package/entity-manager/MongoEntityManager.d.ts +5 -1
- package/entity-manager/MongoEntityManager.js +7 -0
- package/entity-manager/MongoEntityManager.js.map +1 -1
- package/entity-schema/EntitySchemaOptions.d.ts +4 -0
- package/entity-schema/EntitySchemaOptions.js.map +1 -1
- package/entity-schema/EntitySchemaTransformer.js +7 -0
- package/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/find-options/FindOptionsWhere.d.ts +1 -1
- package/find-options/FindOptionsWhere.js.map +1 -1
- package/metadata-builder/EntityMetadataBuilder.js +13 -0
- package/metadata-builder/EntityMetadataBuilder.js.map +1 -1
- package/package.json +1 -1
- package/persistence/subject-builder/ManyToManySubjectBuilder.js +6 -2
- package/persistence/subject-builder/ManyToManySubjectBuilder.js.map +1 -1
- package/platform/PlatformTools.js +2 -0
- package/platform/PlatformTools.js.map +1 -1
- package/query-builder/SelectQueryBuilder.js +2 -0
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/repository/MongoRepository.d.ts +5 -1
- package/repository/MongoRepository.js +6 -0
- package/repository/MongoRepository.js.map +1 -1
- package/typeorm-model-shim.js +61 -53
|
@@ -197,7 +197,19 @@ class SapQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
197
197
|
* Returns raw data stream.
|
|
198
198
|
*/
|
|
199
199
|
async stream(query, parameters, onEnd, onError) {
|
|
200
|
-
|
|
200
|
+
if (this.isReleased)
|
|
201
|
+
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
202
|
+
const databaseConnection = await this.connect();
|
|
203
|
+
this.driver.connection.logger.logQuery(query, parameters, this);
|
|
204
|
+
const prepareAsync = (0, util_1.promisify)(databaseConnection.prepare).bind(databaseConnection);
|
|
205
|
+
const statement = await prepareAsync(query);
|
|
206
|
+
const resultSet = statement.executeQuery(parameters);
|
|
207
|
+
const stream = this.driver.streamClient.createObjectStream(resultSet);
|
|
208
|
+
if (onEnd)
|
|
209
|
+
stream.on("end", onEnd);
|
|
210
|
+
if (onError)
|
|
211
|
+
stream.on("error", onError);
|
|
212
|
+
return stream;
|
|
201
213
|
}
|
|
202
214
|
/**
|
|
203
215
|
* Returns all available database names including system databases.
|
|
@@ -265,7 +277,7 @@ class SapQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
265
277
|
if (!parsedTableName.schema) {
|
|
266
278
|
parsedTableName.schema = await this.getCurrentSchema();
|
|
267
279
|
}
|
|
268
|
-
const sql = `SELECT * FROM "SYS"."TABLE_COLUMNS" WHERE "SCHEMA_NAME" = ${parsedTableName.schema} AND "TABLE_NAME" = ${parsedTableName.tableName} AND "COLUMN_NAME" = '${columnName}'`;
|
|
280
|
+
const sql = `SELECT * FROM "SYS"."TABLE_COLUMNS" WHERE "SCHEMA_NAME" = '${parsedTableName.schema}' AND "TABLE_NAME" = '${parsedTableName.tableName}' AND "COLUMN_NAME" = '${columnName}'`;
|
|
269
281
|
const result = await this.query(sql);
|
|
270
282
|
return result.length ? true : false;
|
|
271
283
|
}
|
|
@@ -747,9 +759,15 @@ class SapQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
747
759
|
clonedTable.columns[clonedTable.columns.indexOf(oldTableColumn)].name = newColumn.name;
|
|
748
760
|
oldColumn.name = newColumn.name;
|
|
749
761
|
}
|
|
750
|
-
if (this.isColumnChanged(oldColumn, newColumn)) {
|
|
751
|
-
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER (${this.buildCreateColumnSql(newColumn
|
|
752
|
-
|
|
762
|
+
if (this.isColumnChanged(oldColumn, newColumn, true)) {
|
|
763
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER (${this.buildCreateColumnSql(newColumn, !(oldColumn.default === null ||
|
|
764
|
+
oldColumn.default === undefined), !oldColumn.isNullable)})`));
|
|
765
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER (${this.buildCreateColumnSql(oldColumn, !(newColumn.default === null ||
|
|
766
|
+
newColumn.default === undefined), !newColumn.isNullable)})`));
|
|
767
|
+
}
|
|
768
|
+
else if (oldColumn.comment !== newColumn.comment) {
|
|
769
|
+
upQueries.push(new Query_1.Query(`COMMENT ON COLUMN ${this.escapePath(table)}."${oldColumn.name}" IS ${this.escapeComment(newColumn.comment)}`));
|
|
770
|
+
downQueries.push(new Query_1.Query(`COMMENT ON COLUMN ${this.escapePath(table)}."${newColumn.name}" IS ${this.escapeComment(oldColumn.comment)}`));
|
|
753
771
|
}
|
|
754
772
|
if (newColumn.isPrimary !== oldColumn.isPrimary) {
|
|
755
773
|
const primaryColumns = clonedTable.primaryColumns;
|
|
@@ -821,24 +839,6 @@ class SapQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
821
839
|
downQueries.push(this.createIndexSql(table, uniqueIndex));
|
|
822
840
|
}
|
|
823
841
|
}
|
|
824
|
-
if (newColumn.default !== oldColumn.default) {
|
|
825
|
-
if (newColumn.default !== null &&
|
|
826
|
-
newColumn.default !== undefined) {
|
|
827
|
-
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${newColumn.name}" ${this.connection.driver.createFullType(newColumn)} DEFAULT ${newColumn.default})`));
|
|
828
|
-
if (oldColumn.default !== null &&
|
|
829
|
-
oldColumn.default !== undefined) {
|
|
830
|
-
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${oldColumn.name}" ${this.connection.driver.createFullType(oldColumn)} DEFAULT ${oldColumn.default})`));
|
|
831
|
-
}
|
|
832
|
-
else {
|
|
833
|
-
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${oldColumn.name}" ${this.connection.driver.createFullType(oldColumn)} DEFAULT NULL)`));
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
else if (oldColumn.default !== null &&
|
|
837
|
-
oldColumn.default !== undefined) {
|
|
838
|
-
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${newColumn.name}" ${this.connection.driver.createFullType(newColumn)} DEFAULT NULL)`));
|
|
839
|
-
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(table)} ALTER ("${oldColumn.name}" ${this.connection.driver.createFullType(oldColumn)} DEFAULT ${oldColumn.default})`));
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
842
|
await this.executeQueries(upQueries, downQueries);
|
|
843
843
|
this.replaceCachedTable(table, clonedTable);
|
|
844
844
|
}
|
|
@@ -1623,7 +1623,9 @@ class SapQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
1623
1623
|
dbColumn["DEFAULT_VALUE"];
|
|
1624
1624
|
}
|
|
1625
1625
|
}
|
|
1626
|
-
|
|
1626
|
+
if (dbColumn["COMMENTS"]) {
|
|
1627
|
+
tableColumn.comment = dbColumn["COMMENTS"];
|
|
1628
|
+
}
|
|
1627
1629
|
if (dbColumn["character_set_name"])
|
|
1628
1630
|
tableColumn.charset =
|
|
1629
1631
|
dbColumn["character_set_name"];
|
|
@@ -1957,6 +1959,16 @@ class SapQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
1957
1959
|
: foreignKeyOrName;
|
|
1958
1960
|
return new Query_1.Query(`ALTER TABLE ${this.escapePath(tableOrName)} DROP CONSTRAINT "${foreignKeyName}"`);
|
|
1959
1961
|
}
|
|
1962
|
+
/**
|
|
1963
|
+
* Escapes a given comment so it's safe to include in a query.
|
|
1964
|
+
*/
|
|
1965
|
+
escapeComment(comment) {
|
|
1966
|
+
if (!comment) {
|
|
1967
|
+
return "NULL";
|
|
1968
|
+
}
|
|
1969
|
+
comment = comment.replace(/'/g, "''").replace(/\u0000/g, ""); // Null bytes aren't allowed in comments
|
|
1970
|
+
return `'${comment}'`;
|
|
1971
|
+
}
|
|
1960
1972
|
/**
|
|
1961
1973
|
* Escapes given table or view path.
|
|
1962
1974
|
*/
|
|
@@ -1967,49 +1979,35 @@ class SapQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
1967
1979
|
}
|
|
1968
1980
|
return `"${tableName}"`;
|
|
1969
1981
|
}
|
|
1970
|
-
/**
|
|
1971
|
-
* Concat database name and schema name to the foreign key name.
|
|
1972
|
-
* Needs because FK name is relevant to the schema and database.
|
|
1973
|
-
*/
|
|
1974
|
-
buildForeignKeyName(fkName, schemaName, dbName) {
|
|
1975
|
-
let joinedFkName = fkName;
|
|
1976
|
-
if (schemaName)
|
|
1977
|
-
joinedFkName = schemaName + "." + joinedFkName;
|
|
1978
|
-
if (dbName)
|
|
1979
|
-
joinedFkName = dbName + "." + joinedFkName;
|
|
1980
|
-
return joinedFkName;
|
|
1981
|
-
}
|
|
1982
|
-
/**
|
|
1983
|
-
* Removes parenthesis around default value.
|
|
1984
|
-
* Sql server returns default value with parenthesis around, e.g.
|
|
1985
|
-
* ('My text') - for string
|
|
1986
|
-
* ((1)) - for number
|
|
1987
|
-
* (newsequentialId()) - for function
|
|
1988
|
-
*/
|
|
1989
|
-
removeParenthesisFromDefault(defaultValue) {
|
|
1990
|
-
if (defaultValue.substr(0, 1) !== "(")
|
|
1991
|
-
return defaultValue;
|
|
1992
|
-
const normalizedDefault = defaultValue.substr(1, defaultValue.lastIndexOf(")") - 1);
|
|
1993
|
-
return this.removeParenthesisFromDefault(normalizedDefault);
|
|
1994
|
-
}
|
|
1995
1982
|
/**
|
|
1996
1983
|
* Builds a query for create column.
|
|
1997
1984
|
*/
|
|
1998
|
-
buildCreateColumnSql(column) {
|
|
1985
|
+
buildCreateColumnSql(column, explicitDefault, explicitNullable) {
|
|
1999
1986
|
let c = `"${column.name}" ` + this.connection.driver.createFullType(column);
|
|
2000
1987
|
if (column.charset)
|
|
2001
1988
|
c += " CHARACTER SET " + column.charset;
|
|
2002
1989
|
if (column.collation)
|
|
2003
1990
|
c += " COLLATE " + column.collation;
|
|
2004
|
-
if (column.default !== undefined && column.default !== null)
|
|
2005
|
-
// DEFAULT must be placed before NOT NULL
|
|
1991
|
+
if (column.default !== undefined && column.default !== null) {
|
|
2006
1992
|
c += " DEFAULT " + column.default;
|
|
2007
|
-
|
|
1993
|
+
}
|
|
1994
|
+
else if (explicitDefault) {
|
|
1995
|
+
c += " DEFAULT NULL";
|
|
1996
|
+
}
|
|
1997
|
+
if (!column.isGenerated) {
|
|
2008
1998
|
// NOT NULL is not supported with GENERATED
|
|
2009
|
-
|
|
1999
|
+
if (column.isNullable !== true)
|
|
2000
|
+
c += " NOT NULL";
|
|
2001
|
+
else if (explicitNullable)
|
|
2002
|
+
c += " NULL";
|
|
2003
|
+
}
|
|
2010
2004
|
if (column.isGenerated === true &&
|
|
2011
|
-
column.generationStrategy === "increment")
|
|
2005
|
+
column.generationStrategy === "increment") {
|
|
2012
2006
|
c += " GENERATED ALWAYS AS IDENTITY";
|
|
2007
|
+
}
|
|
2008
|
+
if (column.comment) {
|
|
2009
|
+
c += ` COMMENT ${this.escapeComment(column.comment)}`;
|
|
2010
|
+
}
|
|
2013
2011
|
return c;
|
|
2014
2012
|
}
|
|
2015
2013
|
}
|