如何匹配日期&时间戳字段作为Typeorm查询构建器中的文本?
我正在从表中构建搜索文本的新查询带有
。typeorm
的Nest JS
我的查询:
var search_text = "04:45";
var query = this.Account.createQueryBuilder()
.where('created_at ilike :search', { search: `%${search_text}%` });
我的表格架:
@Entity('Account')
export class AccountEntity {
@PrimaryGeneratedColumn('uuid')
id: Number;
@Column({ collation: "default", nullable: true })
code: string;
@Column({ collation: "default" })
firstname: string;
@Column({ collation: "default" })
lastname: string;
@Column({ type: "timestamp", default: () => 'CURRENT_TIMESTAMP' })
created_at?: Date;
}
我尝试的是:我试图将字段投入文本以像操作员一样匹配,但不起作用。
var search_text = "04:45";
var query = this.Account.createQueryBuilder()
.where('(created_at)::text ilike :search', { search: `%${search_text}%` });
谁能指导我,我该如何实现? 我试图从最近两天开始修复它,但仍然没有得到任何解决方案。
I am building new query of searching text from table from postgresql
database & Nest JS
with Typeorm
.
My Query :
var search_text = "04:45";
var query = this.Account.createQueryBuilder()
.where('created_at ilike :search', { search: `%${search_text}%` });
My Table Schema :
@Entity('Account')
export class AccountEntity {
@PrimaryGeneratedColumn('uuid')
id: Number;
@Column({ collation: "default", nullable: true })
code: string;
@Column({ collation: "default" })
firstname: string;
@Column({ collation: "default" })
lastname: string;
@Column({ type: "timestamp", default: () => 'CURRENT_TIMESTAMP' })
created_at?: Date;
}
What I have tried : I tried to cast field into text to match like operator but does not working.
var search_text = "04:45";
var query = this.Account.createQueryBuilder()
.where('(created_at)::text ilike :search', { search: `%${search_text}%` });
Can anyone please guide me , How can I achieve this ?
I am trying to fix it from last two days but still not getting any solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论