是否可以使用 typeorm 在 postgresql 中创建一个数字数组?
Is it possible for an array of number in postgresql using typeorm?
我一直在尝试在我的用户实体中创建一个 orm 类型的数字数组,但是 orm 类型一直显示这个问题
代码
@Entity()
class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
username: string;
@Column()
password: string;
@Column()
points: number;
@Column()
time: number[];
};
终端的错误是:
(node:25398) UnhandledPromiseRejectionWarning: DataTypeNotSupportedError: Data type "Array" in "User.time" is not
supported by "postgres" database.
at new DataTypeNotSupportedError (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/error/DataTypeNotSupportedError.js:7:28)
at /home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:74:27
at Array.forEach ()
at EntityMetadataValidator.validate (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:71:36)
at /home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:42:74
at Array.forEach ()
at EntityMetadataValidator.validateMany (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:42:25)
at Connection.buildMetadatas (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/connection/Connection.js:498:33)
at Connection. (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/connection/Connection.js:128:30)
at step (/home/vinicius/www/Projects/Quizzer/backend/node_modules/tslib/tslib.js:141:27)
(node:25398) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async
function without a catch block, or by rejecting a promise which was
not handled with .catch(). To terminate the node process on unhandled
promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).
(rejection id: 1)
(node:25398) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are
not handled will terminate the Node.js process with a non-zero exit
code.
来自:
@Entity()
class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
username: string;
@Column()
password: string;
@Column()
points: number;
@Column("int", { array: true })
time: number[];
};
希望对您有所帮助:)
我一直在尝试在我的用户实体中创建一个 orm 类型的数字数组,但是 orm 类型一直显示这个问题
代码
@Entity()
class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
username: string;
@Column()
password: string;
@Column()
points: number;
@Column()
time: number[];
};
终端的错误是:
(node:25398) UnhandledPromiseRejectionWarning: DataTypeNotSupportedError: Data type "Array" in "User.time" is not supported by "postgres" database. at new DataTypeNotSupportedError (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/error/DataTypeNotSupportedError.js:7:28) at /home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:74:27 at Array.forEach () at EntityMetadataValidator.validate (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:71:36) at /home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:42:74 at Array.forEach () at EntityMetadataValidator.validateMany (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js:42:25) at Connection.buildMetadatas (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/connection/Connection.js:498:33) at Connection. (/home/vinicius/www/Projects/Quizzer/backend/node_modules/typeorm/connection/Connection.js:128:30) at step (/home/vinicius/www/Projects/Quizzer/backend/node_modules/tslib/tslib.js:141:27) (node:25398) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:25398) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
来自
@Entity()
class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
username: string;
@Column()
password: string;
@Column()
points: number;
@Column("int", { array: true })
time: number[];
};
希望对您有所帮助:)