如何将 SQL 转换为 TypeORM 查询生成器?

How to translate an SQL to TypeORM query builder?

如何将下面的代码转换为 TypeORM 查询生成器?

SELECT * FROM "user"

  ORDER BY (CASE 

  WHEN ASCII(SUBSTRING(display_name,1)) BETWEEN 48 AND 57 THEN 3

  WHEN ASCII(SUBSTRING(display_name,1)) < 128 THEN 2 ELSE 1 END), display_name;

谢谢。

你可以直接在你项目的typeorm模块中运行sql查询

首先在控制器中导入

import {  getManager } from "typeorm";
  const entityManager = getManager();

 locationQuery = await entityManager.query(`SELECT * FROM "user"

  ORDER BY (CASE 

  WHEN ASCII(SUBSTRING(display_name,1)) BETWEEN 48 AND 57 THEN 3

  WHEN ASCII(SUBSTRING(display_name,1)) < 128 THEN 2 ELSE 1 END), display_name;`);