doubiaokai4998
doubiaokai4998
2017-05-18 13:28

Golang是否有一个支持Postgresql多个架构的ORM库?

已采纳

I'm looking for an ORM library for Golang that supports working with multiple Postgresql schemas.

The idea is to support multi-tenancy using Postgres schemas. (i.e. upon each request, check which tenant should be queried and dynamically set the schema before querying)

Is anyone familiar with such a library?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • donglin5770 donglin5770 4年前

    Please note that I've only used the standard library so far and therefore my assumption that an ORM will behave in the same manner as the database/sql package might very well be wrong.


    I believe any ORM that exposes an interface analogous to the standard one that allows you to execute plain sql statements, like xorm and gorm for example do, should be able to facilitate switching between schemas by setting the search_path.

    db.Exec("SET search_path TO tenant_schema_123")
    

    This sets the schema for the db handle and any successive queries using that db handle are made to tenant_schema_123.

    点赞 评论 复制链接分享