如何在 Sequelize Typescript 中使用 mySql 函数
How to use mySql function in Sequelize Typescript
我想在日期列上使用 Year 函数,因为我想比较年份
在原始格式中我们可以这样写查询
Select * from Table where YEAR(date) = 2020
我们如何在 sequelize-typescript
中转换此查询
class VenueSeason {
...
@AllowNull(false)
@Column(DataTypes.STRING(255))
name?: string;
@AllowNull(false)
@Column(DataTypes.DATE)
startDate?: Date;
@AllowNull(false)
@Column(DataTypes.DATE)
endDate?: Date;
}
要在 Sequelize Typescript 中使用 mysql 函数,您只需这样做:
where: {
// anyOtherColumn: //value,
[Op.and]: where(fn('YEAR', col('startDate')), _year),
}
从顶部的 sequelize 导入它的要求:
import { Op, fn, col, where } from "sequelize";
我从这个问题中得到了关于 Sequelize (Javacript) 的提示
Sequelize WHERE sequelize.fn(...) AND something='something' ordering issue
我想在日期列上使用 Year 函数,因为我想比较年份
在原始格式中我们可以这样写查询
Select * from Table where YEAR(date) = 2020
我们如何在 sequelize-typescript
中转换此查询class VenueSeason {
...
@AllowNull(false)
@Column(DataTypes.STRING(255))
name?: string;
@AllowNull(false)
@Column(DataTypes.DATE)
startDate?: Date;
@AllowNull(false)
@Column(DataTypes.DATE)
endDate?: Date;
}
要在 Sequelize Typescript 中使用 mysql 函数,您只需这样做:
where: {
// anyOtherColumn: //value,
[Op.and]: where(fn('YEAR', col('startDate')), _year),
}
从顶部的 sequelize 导入它的要求:
import { Op, fn, col, where } from "sequelize";
我从这个问题中得到了关于 Sequelize (Javacript) 的提示 Sequelize WHERE sequelize.fn(...) AND something='something' ordering issue