V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
mikurasa

想问问 gorm 的封装库有没有搞头

  •  
  •   mikurasa ·
    Germiniku · Sep 8, 2023 · 1830 views
    This topic created in 967 days ago, the information mentioned may be changed or developed.
    gin 框架 controller 层总会定义个结构体去接收请求参数,把结构体透传到 dao 层,dao 层自己根据 tag 去过滤,免去写一堆垃圾 if
    type QueryFruits struct {
    Fruit string `json:"fruit" filter:"column:fruit;operator:like"`
    }
    d.Model(&Fruit{}).Scopes(func (db *gorm.DB) *gorm.DB){
    scope := xxxx()
    return db.Where(scope)
    }
    11 replies    2023-09-15 17:48:16 +08:00
    PiersSoCool
        1
    PiersSoCool  
       Sep 8, 2023
    没有 gpt 会帮你写好
    vitoliu
        2
    vitoliu  
       Sep 9, 2023
    go-mapper 不就完事儿了
    bianxiaoxian
        3
    bianxiaoxian  
       Sep 9, 2023
    我自己项目就封装了一下,gorm 封装的像 MyBatisPlus 那样,根据泛型,组合,用起来挺爽的
    wheeler
        4
    wheeler  
       Sep 9, 2023 via iPhone
    这样只适合简单的逻辑吧。explicit is better than implicit 。
    learningman
        5
    learningman  
       Sep 9, 2023 via Android
    快进到被注入
    Nazz
        6
    Nazz  
       Sep 9, 2023 via Android
    这个满足你需求吗

    https://github.com/lxzan/fi
    mikurasa
        7
    mikurasa  
    OP
       Sep 10, 2023
    @Nazz 酷 我的想法也是和这个差不多
    flyv2x
        8
    flyv2x  
       Sep 12, 2023
    ent 框架很好用
    mikurasa
        9
    mikurasa  
    OP
       Sep 12, 2023
    Nazz
        10
    Nazz  
       Sep 12, 2023
    @mikurasa 做完之后发现我更喜欢非反射的姿势
    ace12
        11
    ace12  
       Sep 15, 2023 via Android
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2634 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 03:42 · PVG 11:42 · LAX 20:42 · JFK 23:42
    ♥ Do have faith in what you're doing.