mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
added array option to column options to be able to create array types in postgres
This commit is contained in:
parent
d321d2eb47
commit
d0b5b34817
@ -34,4 +34,11 @@ export interface ColumnCommonOptions {
|
||||
*/
|
||||
comment?: string;
|
||||
|
||||
/**
|
||||
* Indicates if this column is an array.
|
||||
* Can be simply set to true or array length can be specified.
|
||||
* Supported only by postgres.
|
||||
*/
|
||||
array?: boolean|string;
|
||||
|
||||
}
|
||||
@ -71,4 +71,11 @@ export interface ColumnOptions {
|
||||
*/
|
||||
enum?: any[];
|
||||
|
||||
/**
|
||||
* Indicates if this column is an array.
|
||||
* Can be simply set to true or array length can be specified.
|
||||
* Supported only by postgres.
|
||||
*/
|
||||
array?: boolean|string;
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import {MysqlQueryRunner} from "./MysqlQueryRunner";
|
||||
import {ObjectLiteral} from "../../common/ObjectLiteral";
|
||||
import {ColumnMetadata} from "../../metadata/ColumnMetadata";
|
||||
import {DriverOptionNotSetError} from "../error/DriverOptionNotSetError";
|
||||
import {DataUtils} from "../../util/DataUtils";
|
||||
import {DateUtils} from "../../util/DateUtils";
|
||||
import {PlatformTools} from "../../platform/PlatformTools";
|
||||
import {Connection} from "../../connection/Connection";
|
||||
import {RdbmsSchemaBuilder} from "../../schema-builder/RdbmsSchemaBuilder";
|
||||
@ -77,7 +77,8 @@ export class MysqlDriver implements Driver {
|
||||
"mediumtext",
|
||||
"longblob",
|
||||
"longtext",
|
||||
"enum"
|
||||
"enum",
|
||||
"json"
|
||||
];
|
||||
|
||||
/**
|
||||
@ -215,19 +216,19 @@ export class MysqlDriver implements Driver {
|
||||
return value === true ? 1 : 0;
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedDateToTimeString(value);
|
||||
return DateUtils.mixedDateToTimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.mixedDateToUtcDatetimeString(value);
|
||||
return DateUtils.mixedDateToUtcDatetimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.stringify(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.simpleArrayToString(value);
|
||||
return DateUtils.simpleArrayToString(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -241,19 +242,19 @@ export class MysqlDriver implements Driver {
|
||||
return value ? true : false;
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.normalizeHydratedDate(value);
|
||||
return DateUtils.normalizeHydratedDate(value);
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedTimeToString(value);
|
||||
return DateUtils.mixedTimeToString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.parse(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.stringToSimpleArray(value);
|
||||
return DateUtils.stringToSimpleArray(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@ -5,7 +5,7 @@ import {OracleQueryRunner} from "./OracleQueryRunner";
|
||||
import {ObjectLiteral} from "../../common/ObjectLiteral";
|
||||
import {ColumnMetadata} from "../../metadata/ColumnMetadata";
|
||||
import {DriverOptionNotSetError} from "../error/DriverOptionNotSetError";
|
||||
import {DataUtils} from "../../util/DataUtils";
|
||||
import {DateUtils} from "../../util/DateUtils";
|
||||
import {PlatformTools} from "../../platform/PlatformTools";
|
||||
import {Connection} from "../../connection/Connection";
|
||||
import {RdbmsSchemaBuilder} from "../../schema-builder/RdbmsSchemaBuilder";
|
||||
@ -235,19 +235,19 @@ export class OracleDriver implements Driver {
|
||||
return value === true ? 1 : 0;
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedDateToTimeString(value);
|
||||
return DateUtils.mixedDateToTimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.mixedDateToUtcDatetimeString(value);
|
||||
return DateUtils.mixedDateToUtcDatetimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.stringify(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.simpleArrayToString(value);
|
||||
return DateUtils.simpleArrayToString(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -261,19 +261,19 @@ export class OracleDriver implements Driver {
|
||||
return value ? true : false;
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.normalizeHydratedDate(value);
|
||||
return DateUtils.normalizeHydratedDate(value);
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedTimeToString(value);
|
||||
return DateUtils.mixedTimeToString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.parse(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.stringToSimpleArray(value);
|
||||
return DateUtils.stringToSimpleArray(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@ -6,7 +6,7 @@ import {DriverUtils} from "../DriverUtils";
|
||||
import {ColumnMetadata} from "../../metadata/ColumnMetadata";
|
||||
import {PostgresQueryRunner} from "./PostgresQueryRunner";
|
||||
import {DriverOptionNotSetError} from "../error/DriverOptionNotSetError";
|
||||
import {DataUtils} from "../../util/DataUtils";
|
||||
import {DateUtils} from "../../util/DateUtils";
|
||||
import {PlatformTools} from "../../platform/PlatformTools";
|
||||
import {Connection} from "../../connection/Connection";
|
||||
import {RdbmsSchemaBuilder} from "../../schema-builder/RdbmsSchemaBuilder";
|
||||
@ -211,21 +211,21 @@ export class PostgresDriver implements Driver {
|
||||
return value === true ? 1 : 0;
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedDateToTimeString(value);
|
||||
return DateUtils.mixedDateToTimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "timestamp"
|
||||
|| columnMetadata.type === "timestamp with time zone"
|
||||
|| columnMetadata.type === "timestamp without time zone") {
|
||||
return DataUtils.mixedDateToUtcDatetimeString(value);
|
||||
return DateUtils.mixedDateToUtcDatetimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json" || columnMetadata.type === "jsonb") {
|
||||
return JSON.stringify(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.simpleArrayToString(value);
|
||||
return DateUtils.simpleArrayToString(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -241,16 +241,16 @@ export class PostgresDriver implements Driver {
|
||||
} else if (columnMetadata.type === "timestamp"
|
||||
|| columnMetadata.type === "timestamp with time zone"
|
||||
|| columnMetadata.type === "timestamp without time zone") {
|
||||
return DataUtils.normalizeHydratedDate(value);
|
||||
return DateUtils.normalizeHydratedDate(value);
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedTimeToString(value);
|
||||
return DateUtils.mixedTimeToString(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.stringToSimpleArray(value);
|
||||
return DateUtils.stringToSimpleArray(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -348,6 +348,11 @@ export class PostgresDriver implements Driver {
|
||||
} else if (column.scale) {
|
||||
type += "(" + column.scale + ")";
|
||||
}
|
||||
|
||||
if (column.array) {
|
||||
type += " ARRAY" + (typeof column.array === "string" ? column.array : "");
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import {DriverPackageNotInstalledError} from "../error/DriverPackageNotInstalled
|
||||
import {ColumnMetadata} from "../../metadata/ColumnMetadata";
|
||||
import {SqliteQueryRunner} from "./SqliteQueryRunner";
|
||||
import {DriverOptionNotSetError} from "../error/DriverOptionNotSetError";
|
||||
import {DataUtils} from "../../util/DataUtils";
|
||||
import {DateUtils} from "../../util/DateUtils";
|
||||
import {PlatformTools} from "../../platform/PlatformTools";
|
||||
import {Connection} from "../../connection/Connection";
|
||||
import {RdbmsSchemaBuilder} from "../../schema-builder/RdbmsSchemaBuilder";
|
||||
@ -169,19 +169,19 @@ export class SqliteDriver implements Driver {
|
||||
return value === true ? 1 : 0;
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedDateToTimeString(value);
|
||||
return DateUtils.mixedDateToTimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.mixedDateToUtcDatetimeString(value);
|
||||
return DateUtils.mixedDateToUtcDatetimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.stringify(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.simpleArrayToString(value);
|
||||
return DateUtils.simpleArrayToString(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -195,19 +195,19 @@ export class SqliteDriver implements Driver {
|
||||
return value ? true : false;
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.normalizeHydratedDate(value);
|
||||
return DateUtils.normalizeHydratedDate(value);
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedTimeToString(value);
|
||||
return DateUtils.mixedTimeToString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.parse(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.stringToSimpleArray(value);
|
||||
return DateUtils.stringToSimpleArray(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@ -6,7 +6,7 @@ import {SqlServerQueryRunner} from "./SqlServerQueryRunner";
|
||||
import {ObjectLiteral} from "../../common/ObjectLiteral";
|
||||
import {ColumnMetadata} from "../../metadata/ColumnMetadata";
|
||||
import {DriverOptionNotSetError} from "../error/DriverOptionNotSetError";
|
||||
import {DataUtils} from "../../util/DataUtils";
|
||||
import {DateUtils} from "../../util/DateUtils";
|
||||
import {PlatformTools} from "../../platform/PlatformTools";
|
||||
import {Connection} from "../../connection/Connection";
|
||||
import {RdbmsSchemaBuilder} from "../../schema-builder/RdbmsSchemaBuilder";
|
||||
@ -240,19 +240,19 @@ export class SqlServerDriver implements Driver {
|
||||
return value === true ? 1 : 0;
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedDateToTimeString(value);
|
||||
return DateUtils.mixedDateToTimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.mixedDateToUtcDatetimeString(value);
|
||||
return DateUtils.mixedDateToUtcDatetimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.stringify(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.simpleArrayToString(value);
|
||||
return DateUtils.simpleArrayToString(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -266,19 +266,19 @@ export class SqlServerDriver implements Driver {
|
||||
return value ? true : false;
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.normalizeHydratedDate(value);
|
||||
return DateUtils.normalizeHydratedDate(value);
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedTimeToString(value);
|
||||
return DateUtils.mixedTimeToString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.parse(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.stringToSimpleArray(value);
|
||||
return DateUtils.stringToSimpleArray(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@ -119,7 +119,7 @@ export type SimpleColumnType =
|
||||
|"tsquery" // postgres
|
||||
|"uuid" // postgres
|
||||
|"xml" // mssql, postgres
|
||||
|"json" // postgres
|
||||
|"json" // mysql, postgres
|
||||
|"jsonb" // postgres
|
||||
|"varbinary" // mssql
|
||||
|"cursor" // mssql
|
||||
|
||||
@ -3,7 +3,7 @@ import {DriverUtils} from "../DriverUtils";
|
||||
import {ObjectLiteral} from "../../common/ObjectLiteral";
|
||||
import {ColumnMetadata} from "../../metadata/ColumnMetadata";
|
||||
import {DriverOptionNotSetError} from "../error/DriverOptionNotSetError";
|
||||
import {DataUtils} from "../../util/DataUtils";
|
||||
import {DateUtils} from "../../util/DateUtils";
|
||||
import {WebsqlQueryRunner} from "./WebsqlQueryRunner";
|
||||
import {Connection} from "../../connection/Connection";
|
||||
import {RdbmsSchemaBuilder} from "../../schema-builder/RdbmsSchemaBuilder";
|
||||
@ -196,19 +196,19 @@ export class WebsqlDriver implements Driver {
|
||||
return value === true ? 1 : 0;
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedDateToTimeString(value);
|
||||
return DateUtils.mixedDateToTimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.mixedDateToUtcDatetimeString(value);
|
||||
return DateUtils.mixedDateToUtcDatetimeString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.stringify(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.simpleArrayToString(value);
|
||||
return DateUtils.simpleArrayToString(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -222,19 +222,19 @@ export class WebsqlDriver implements Driver {
|
||||
return value ? true : false;
|
||||
|
||||
} else if (columnMetadata.type === "datetime") {
|
||||
return DataUtils.normalizeHydratedDate(value);
|
||||
return DateUtils.normalizeHydratedDate(value);
|
||||
|
||||
} else if (columnMetadata.type === "date") {
|
||||
return DataUtils.mixedDateToDateString(value);
|
||||
return DateUtils.mixedDateToDateString(value);
|
||||
|
||||
} else if (columnMetadata.type === "time") {
|
||||
return DataUtils.mixedTimeToString(value);
|
||||
return DateUtils.mixedTimeToString(value);
|
||||
|
||||
} else if (columnMetadata.type === "json") {
|
||||
return JSON.parse(value);
|
||||
|
||||
} else if (columnMetadata.type === "simple-array") {
|
||||
return DataUtils.stringToSimpleArray(value);
|
||||
return DateUtils.stringToSimpleArray(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@ -98,6 +98,13 @@ export class ColumnMetadata {
|
||||
*/
|
||||
enum?: any[];
|
||||
|
||||
/**
|
||||
* Indicates if this column is an array.
|
||||
* Can be simply set to true or array length can be specified.
|
||||
* Supported only by postgres.
|
||||
*/
|
||||
array?: boolean|string;
|
||||
|
||||
/**
|
||||
* Gets full path to this column property (including column property name).
|
||||
* Full path is relevant when column is used in embeds (one or multiple nested).
|
||||
@ -209,6 +216,8 @@ export class ColumnMetadata {
|
||||
this.precision = options.args.options.precision;
|
||||
if (options.args.options.enum)
|
||||
this.enum = options.args.options.enum;
|
||||
if (options.args.options.array)
|
||||
this.array = options.args.options.array;
|
||||
if (options.args.mode) {
|
||||
this.isVirtual = options.args.mode === "virtual";
|
||||
this.isParentId = options.args.mode === "parentId";
|
||||
|
||||
@ -2,7 +2,7 @@ import {ObjectLiteral} from "../common/ObjectLiteral";
|
||||
import {EntityMetadata} from "../metadata/EntityMetadata";
|
||||
import {ColumnMetadata} from "../metadata/ColumnMetadata";
|
||||
import {RelationMetadata} from "../metadata/RelationMetadata";
|
||||
import {DataUtils} from "../util/DataUtils";
|
||||
import {DateUtils} from "../util/DateUtils";
|
||||
|
||||
/**
|
||||
* Holds information about insert operation into junction table.
|
||||
@ -326,14 +326,14 @@ export class Subject {
|
||||
// normalize special values to make proper comparision (todo: arent they already normalized at this point?!)
|
||||
if (entityValue !== null && entityValue !== undefined) {
|
||||
if (column.type === "date") {
|
||||
entityValue = DataUtils.mixedDateToDateString(entityValue);
|
||||
entityValue = DateUtils.mixedDateToDateString(entityValue);
|
||||
|
||||
} else if (column.type === "time") {
|
||||
entityValue = DataUtils.mixedDateToTimeString(entityValue);
|
||||
entityValue = DateUtils.mixedDateToTimeString(entityValue);
|
||||
|
||||
} else if (column.type === "datetime" || column.type === Date) {
|
||||
entityValue = DataUtils.mixedDateToUtcDatetimeString(entityValue);
|
||||
databaseValue = DataUtils.mixedDateToUtcDatetimeString(databaseValue);
|
||||
entityValue = DateUtils.mixedDateToUtcDatetimeString(entityValue);
|
||||
databaseValue = DateUtils.mixedDateToUtcDatetimeString(databaseValue);
|
||||
|
||||
} else if (column.type === "json" || column.type === "jsonb" || column.type === Object) {
|
||||
entityValue = JSON.stringify(entityValue);
|
||||
@ -341,8 +341,8 @@ export class Subject {
|
||||
databaseValue = JSON.stringify(databaseValue);
|
||||
|
||||
} else if (column.type === "sample-array") {
|
||||
entityValue = DataUtils.simpleArrayToString(entityValue);
|
||||
databaseValue = DataUtils.simpleArrayToString(databaseValue);
|
||||
entityValue = DateUtils.simpleArrayToString(entityValue);
|
||||
databaseValue = DateUtils.simpleArrayToString(databaseValue);
|
||||
}
|
||||
}
|
||||
// todo: this mechanism does not get in count embeddeds in embeddeds
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Provides utilities to transform hydrated and persisted data.
|
||||
*/
|
||||
export class DataUtils {
|
||||
export class DateUtils {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Static Methods
|
||||
Loading…
x
Reference in New Issue
Block a user