gpt4 book ai didi

postgresql - 缺少表 "token"的 FROM 子句条目

转载 作者:行者123 更新时间:2023-12-01 01:39:40 25 4
gpt4 key购买 nike

我正在使用带有 TypeORM(Postgres 数据库)的 NestJs,我想定期从数据库中删除我过期的 token 。这是我的 token 实体:

@Entity('Token')
export class Token extends BaseEntity {
@PrimaryColumn()
public encoding: string;

@Column()
public expiresOn: Date;
}

我想从数据库中删除所有过期的 token 。所以 expiresOn返回比当前日期更旧的日期。

当我调用这个
    await this.tokensRepository
.createQueryBuilder('token')
.delete()
.from(Token) // I also tried it with 'token'
.where('token.expiresOn <= :currentDate', { currentDate: new Date() })
.execute();

我收到以下错误:
query: DELETE FROM "Token" WHERE token.expiresOn <= $1 -- PARAMETERS: ["2020-01-11T16:37:21.964Z"]
query failed: DELETE FROM "Token" WHERE token.expiresOn <= $1 -- PARAMETERS: ["2020-01-11T16:37:21.964Z"]
error: error: missing FROM-clause entry for table "token"
at Connection.parseE (/home/matthias/Projects/nest-api/node_modules/pg/lib/connection.js:604:13)
at Connection.parseMessage (/home/matthias/Projects/nest-api/node_modules/pg/lib/connection.js:403:19)
at Socket.<anonymous> (/home/matthias/Projects/nest-api/node_modules/pg/lib/connection.js:123:22)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
name: 'error',
length: 116,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '27',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '3240',
routine: 'errorMissingRTE'
}
(node:18572) UnhandledPromiseRejectionWarning: QueryFailedError: missing FROM-clause entry for table "token"
at new QueryFailedError (/home/matthias/Projects/nest-api/node_modules/typeorm/error/QueryFailedError.js:11:28)
at Query.callback (/home/matthias/Projects/nest-api/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:176:38)
at Query.handleError (/home/matthias/Projects/nest-api/node_modules/pg/lib/query.js:145:17)
at Connection.connectedErrorMessageHandler (/home/matthias/Projects/nest-api/node_modules/pg/lib/client.js:214:17)
at Connection.emit (events.js:210:5)
at Socket.<anonymous> (/home/matthias/Projects/nest-api/node_modules/pg/lib/connection.js:128:12)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)

如果您想查看存储库,它就在那里

https://github.com/matthiashermsen/nest-api/blob/master/src/authentications/expired-tokens-removal.service.ts#L60

如果你想尝试 NestJs API,这是我的 .env 文件配置
SERVER_PORT = 3000

DATABASE_TYPE = postgres
DATABASE_HOST = localhost
DATABASE_PORT = 5432
DATABASE_USERNAME = postgres
DATABASE_PASSWORD = postgres
DATABASE_NAME = api
DATABASE_LOGGING = true
DATABASE_SYNCHRONIZE = true

NODE_ENV = development

AUTHENTICATION_SALT_ROUNDS = 12
TOKEN_SECRET = secret
TOKEN_EXPIRATION_IN_SECONDS = 36000
EXPIRED_TOKEN_REMOVAL_IN_MILLISECONDS = 5000

有人知道如何解决这个问题吗?

最佳答案

如果在 SQL 中将标识符括在引号中,则必须完全按照存储的方式写入。姓名 "Token"不等于 token .您可能应该将实体声明更改为 @Entity('token') .

关于postgresql - 缺少表 "token"的 FROM 子句条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59728128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com