我正在尝试在Express.js项目中使用TypeORM从MySQL数据库的表中获取数据。
我用来QueryBuilder获取数据。
我的实现:
const result = await this.repository.createQueryBuilder("post")
.skip((request.PageNo - 1) * request.PageSize)
.take(request.PageSize)
.select([
"post.Id",
"post.Title",
"SUBSTRING(post.Content, 1, 150) AS post_Content",
"post.ReadTime",
"post.CreatedDate"
])
.getRawAndEntities();
Run Code Online (Sandbox Code Playgroud)
结果:
{
raw: [
TextRow {
post_Id: '457457',
post_CreatedDate: 2021-03-17T18:00:00.000Z,
post_Title: 'This is a random title',
post_ReadTime: 3,
post_Content: "If you're looking for random paragraphs, you've come to the right place. When a random word or a random sentence isn't quite enough, the next logical "
} …Run Code Online (Sandbox Code Playgroud)