小编Zun*_*iar的帖子

具有别名的计算列未映射到 TypeORM 实体

我正在尝试在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)

mysql calculated-columns typescript typeorm

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

calculated-columns ×1

mysql ×1

typeorm ×1

typescript ×1