doucao8982 2019-06-19 21:18
浏览 156
已采纳

使用ORM模型代替正确的数据库建模

I've recently inherited a project where the database was modeled interestingly (i.e. lack of some index and foreign key definitions). The project uses GORM and from what I can tell, those Models have tags which define everything correctly.

I can't think of a reason why using the ORM for database "modeling" wouldn't work. The closest I can come is performance, but at the scale this would need to run, the point seems moot. Are there any downsides to this running things this way?

  • 写回答

1条回答 默认 最新

  • doudiejian5827 2019-06-19 22:21
    关注

    The only downsides I'm aware of from doing the same thing at my company are:

    1. Interoperability - you need to use golang to get everything up and running, so if you have projects that would like to use another language on a new database it gets a bit weird.
    2. Complex SQL stuff - occasionally you'll want to use a complex feature that might be awkward to write tags for (ex: compound indexes require tags on all the fields to use the same index name, but that's weird to mentally parse and you don't get to decide the order)
    3. Migration - if you use the built in AutoMigrate you can get tables, columns, and indices created, but you can't add in default data or write a data transition, nor will it drop columns, nor does it keep a history of changes. If all the developers use the same dev database this isn't too much of an issue, but if you start having separate dbs you'll probably start keeping migration sql files around too, which you'll have to manage separately from Gorm.

    I don't regret using it initially as it was much easier to declare the model and the sql in one place to start, but as we grew and started to use more advanced sql features and more databases, we had to switch to doing actually schema definitions and migrations.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵