栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

TypeORM子查询

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

TypeORM子查询

我希望这个答案可以帮助其他人使用TypeORM子查询。

const subquery = await getManager()    .createQueryBuilder(table4, 't4')    .select('"t4".f')    .addSelect('"t4".g')    .addSelect('"t5".e')    .addSelect('"t6".h')    .innerJoin(table5, 't5', '"t4".g = "t5".g')    .innerJoin(table6, 't6', '"t6".g = "t4".g')    .where('"t4".k = 4 AND ("t6".i = 2 OR ("t6".i = 1 AND "t6".j = 1))');  model = await getManager()    .createQueryBuilder(table1, 't1')    .select('"t1".a')    .addSelect("TO_CHAr (MAX (jointable.f), 'MON YYYY')", 'f')    .addSelect('"t3".c')    .addSelect('"t3".d')    .addSelect('"t1".e')    .leftJoin('table2', 't2', '"t2".e = "t1".e')    .innerJoin(table3, 't3', '"t3".d = "t2".d')    .innerJoin('('+subquery.getQuery()+')', 'jointable', '"t1".e = jointable.e')    .where('jointable.h = :h AND (:d = 3 OR "t3".d = :d)',      { h: h, d: d })    .groupBy('"t1".a, "t3".c, "t3".d, "t1".e')    .orderBy('"t1".a', 'ASC')    .getRawMany();

'('+subquery.getQuery()+')'
用来获取子查询的选择查询等效于

(选择f,t4.g,t5.e,t6.h…。

......

....)可连接ON t1.e =可连接

根据我的理解:

  • Join
    实际上 等于
    inner join

  • .select``select
    在SQL中等于和。您也可以添加
    aliases
    (如SQL中一样)。

  • .addSelect
    类似于
    , in select

  • 使用选择查询构建器可以得到两种类型的结果:实体或原始结果。描述您是否要将数据作为实体(

    getOne
    getMany
    )或作为实体(
    getRawOne
    getRawMany
    )。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/426010.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号