The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
higanbana

为什么国内的微服务框架都不用 gorm 作为微服务框架的 orm?

  •  
  •   higanbana · Dec 5, 2024 · 5950 views
    This topic created in 719 days ago, the information mentioned may be changed or developed.

    如题,同问,观察了一下,go-zero 用的是自己封装的 sqlx ,还可以理解是最简化,但是完全没好到哪儿去,复杂 sql 很麻烦,kratos 直接用了国外的 Ent ,其他的几个没接触过,想知道这样的考量是什么?

    21 replies  •  2024-12-31 21:28:36 +08:00
    Nexora
    Nexora
    Dec 5, 2024
    1
    我一直都用 gorm ,同事也用 gorm
    shakaraka
    shakaraka
    Dec 5, 2024
    2
    bun 比 gorm 好用很多
    gvison
    gvison
    Dec 5, 2024❤️1
    3
    这个要问原作者的自己的考量了。

    gorm 提供了大量的抽象层和自动化功能,内部使用了不少的反射操作,在处理复杂 SQL 或高并发场景时,性能不够好,在简单查询和标准 CRUD 操作上,grom 通常能够提供足够的性能了。

    这个微服务框架默认使用的是 gorm ,也可以使用自己熟悉的 orm 替代 gorm 。
    https://github.com/zhufuyi/sponge
    securityCoding
    securityCoding
    Dec 5, 2024
    4
    可读性吧 ,国内互联网大多是单表查询用不到那些高级玩意
    jenner1331
    jenner1331
    Dec 5, 2024❤️1
    5
    字节都用 gorm 吧 gorm 作者也在字节
    freemoon
    freemoon
    Dec 5, 2024
    6
    最近遇到的 gorm 硬伤:假设一个表有很多字段(数十个),在查询时,对于 A 字段,我要使用函数,例如地理数据:`astext(geometry) AS geometry`,其他字段不变,使用 gorm ,似乎没有 API 实现这个需求,只能手动 select(all_fields...)。
    liaohongxing
    liaohongxing
    Dec 5, 2024
    7
    框架作者喜好
    cdx
    cdx
    Dec 5, 2024❤️2
    8
    可能是把组员的 sql 水平尽量拉到同一水平线上。ent 是完全的 go 代码,增删改查基本不用去写 sql ,直接使用 ent 生成的 go 代码即可
    Baloneo
    Baloneo
    Dec 5, 2024
    9
    不好用
    laikicka
    laikicka
    Dec 5, 2024
    10
    golang 上的 orm 都不怎么好用..
    sngxx
    sngxx
    Dec 5, 2024
    11
    gorm xorm 都有用
    hankli
    hankli
    Dec 5, 2024
    12
    难道没有人用 https://github.com/go-jet/jet 吗? 非常好用!
    zoharSoul
    zoharSoul
    Dec 5, 2024
    13
    @gvison #3 这个好像没有整合依赖注入相关的啊
    yuzuhi
    yuzuhi
    Dec 6, 2024
    14
    没有人提 ent 吗?最近正打算试试看,用 gorm 总有一种就是在写原生 sql 的感觉
    gvison
    gvison
    Dec 6, 2024
    15
    @zoharSoul 不需要依赖注入也可以在 解耦、测试性、灵活性、可扩展性 满足要求的
    bv
    bv
    Dec 6, 2024
    16
    @yuzuhi 咋不试试 gorm/gen https://gorm.io/gen/query.html
    ninjashixuan
    ninjashixuan
    Dec 6, 2024
    17
    一般拆成微服务,大多服务不会写复杂的 sql ,毕竟微服务数据库都是拆分很细了,复杂的联表查询自然少,自然要个简单的 orm , 个人猜测。
    qloog
    qloog
    Dec 12, 2024
    18
    目前用的最多的还是 gorm, 也了解过 sqlc (基于 sql 生成代码)

    如楼上上上...所说, gorm 作者在字节,经过很多线上场景的考验,所以性能问题不用考虑(字节的体量你懂的),是经过大量优化的,同时 gorm 提供了 基于数据库表生成代码,还支持通过编写复杂 sql 生成代码,非常方便,也可以避免常见的 SQL 注入

    很多框架还是用 gorm 的,比如: https://github.com/go-eagle/eagle
    qloog
    qloog
    Dec 12, 2024
    19
    @qloog 补充 内部 gorm 和 开源版本基本一致,不同的是内部版本只是更多适配了他们自己的基建
    shellcodecow
    shellcodecow
    Dec 17, 2024
    20
    jinzhu 去字节啦? 之前还在 longbridge 的
    fxjson
    fxjson
    Dec 31, 2024
    21
    sqlx 这个库原生写,也不错,我自己用 gin 开发了一个开箱即用框架 https://github.com/fanqingxuan/go-gin ,使用的 gorm
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1371 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 17:04 · PVG 01:04 · LAX 09:04 · JFK 12:04
    ♥ Do have faith in what you're doing.